:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dee2e6;
  --text: #1a2f4a;
  --text-muted: #6c757d;
  --rojo: #dc3545;
  --rojo-bg: #fff5f5;
  --rojo-border: #f5c6cb;
  --amarillo: #fd7e14;
  --amarillo-bg: #fff9f0;
  --amarillo-border: #fde8cc;
  --verde: #198754;
  --verde-bg: #f0fff4;
  --verde-border: #c3e6cb;
  --gray-bg: #f8f9fa;
  --gray-border: #dee2e6;
  --accent: #0d6efd;
  --header-h: 60px;
  --toolbar-h: 52px;
  --update-h: 28px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* ─── HEADER ─── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--text);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.logo { font-size: 1.1rem; font-weight: 700; letter-spacing: .5px; }
.logo span { color: #ffc107; }
.stats-bar { display: flex; gap: 14px; }
.stat { font-size: .9rem; padding: 3px 10px; border-radius: 20px; cursor: default; }
.stat.rojo { background: rgba(220,53,69,.2); }
.stat.amarillo { background: rgba(253,126,20,.2); }
.stat.verde { background: rgba(25,135,84,.2); }
.stat.gray { background: rgba(255,255,255,.1); }
.stat.informadas { background: rgba(13,110,253,.2); }
.header-right { display: flex; align-items: center; gap: 10px; }
.shift-info { font-size: .85rem; opacity: .8; white-space: nowrap; }

/* ─── BUTTONS ─── */
.btn {
  padding: 6px 14px; border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; font-size: .85rem; font-weight: 500; transition: all .15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #0b5ed7; }
.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #5a6268; }
.btn-outline { background: transparent; color: white; border-color: rgba(255,255,255,.4); }
.btn-outline:hover { background: rgba(255,255,255,.1); }
.btn-accent { background: #ffc107; color: var(--text); border-color: #ffc107; }
.btn-accent:hover { background: #e0a800; }
.btn-sm { padding: 3px 9px; font-size: .78rem; }
.btn-danger { background: var(--rojo); color: white; }
.btn-danger:hover { background: #bd2130; }
.btn-success { background: var(--verde); color: white; }
.btn-success:hover { background: #157347; }

/* ─── TOOLBAR ─── */
#toolbar {
  position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 99;
  height: var(--toolbar-h);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  flex-wrap: wrap;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-btn {
  padding: 4px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: white; cursor: pointer; font-size: .82rem; transition: all .15s;
}
.filter-btn:hover { border-color: #aaa; }
.filter-btn.active { background: var(--text); color: white; border-color: var(--text); }
.filter-btn.rojo.active { background: var(--rojo); border-color: var(--rojo); }
.filter-btn.amarillo.active { background: var(--amarillo); border-color: var(--amarillo); color: white; }
.filter-btn.verde.active { background: var(--verde); border-color: var(--verde); }
.filter-btn.gray.active { background: #6c757d; border-color: #6c757d; }
.toggle-label { display: flex; align-items: center; gap: 6px; font-size: .85rem; cursor: pointer; }
.hours-btn {
  padding: 2px 10px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  font-size: .78rem; transition: all .15s;
}
.hours-btn:hover { border-color: var(--text-muted); color: var(--text); }
.hours-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
#search-input {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: .85rem; width: 240px;
}

/* ─── UPDATE BAR ─── */
#last-update-bar {
  position: fixed; top: calc(var(--header-h) + var(--toolbar-h)); left: 0; right: 0; z-index: 98;
  height: var(--update-h);
  background: #e9ecef; border-bottom: 1px solid var(--border);
  font-size: .78rem; color: var(--text-muted);
  display: flex; align-items: center; padding: 0 20px; gap: 0;
}
#scraping-status { color: var(--accent); font-weight: 500; }

/* ─── MAIN ─── */
main {
  margin-top: calc(var(--header-h) + var(--toolbar-h) + var(--update-h));
  padding: 16px 20px 40px;
  min-height: calc(100vh - var(--header-h) - var(--toolbar-h) - var(--update-h));
}
#loading { text-align: center; padding: 60px; color: var(--text-muted); font-size: 1rem; }
#empty-state { text-align: center; padding: 80px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* ─── NEWS CARD ─── */
.news-card {
  background: var(--surface); border-radius: 8px; border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  margin-bottom: 10px; padding: 12px 16px;
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px; transition: box-shadow .15s;
}
.news-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.news-card.rojo    { background: var(--rojo-bg);    border-left-color: var(--rojo);    border-color: var(--rojo-border); }
.news-card.amarillo{ background: var(--amarillo-bg); border-left-color: var(--amarillo); border-color: var(--amarillo-border); }
.news-card.verde   { background: var(--verde-bg);   border-left-color: var(--verde);   border-color: var(--verde-border); }
.news-card.sin_match { background: var(--gray-bg); border-left-color: #adb5bd; }
.news-card.informed { opacity: .6; }
.news-card.informed .news-title { text-decoration: line-through; }

/* Inner layout: thumbnail + content */
.news-main { min-width: 0; display: flex; gap: 12px; align-items: flex-start; }

.news-thumb {
  flex-shrink: 0; width: 110px; height: 74px; border-radius: 6px;
  object-fit: cover; background: var(--bg);
  border: 1px solid var(--border);
  display: block;
}
.news-thumb-placeholder {
  flex-shrink: 0; width: 110px; height: 74px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; color: #adb5bd;
}
.news-body { min-width: 0; flex: 1; }

.news-title {
  font-size: .95rem; font-weight: 600; margin-bottom: 5px;
  cursor: pointer; color: var(--text); line-height: 1.35;
}
.news-title:hover { color: var(--accent); text-decoration: underline; }

.news-meta {
  font-size: .76rem; color: var(--text-muted);
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.portal-badge {
  background: var(--text); color: white; padding: 2px 8px;
  border-radius: 10px; font-size: .71rem; font-weight: 600;
}
.meta-date { white-space: nowrap; }
.meta-author { font-style: italic; color: #495057; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-divider { color: #ced4da; }

.kw-badge {
  padding: 2px 8px; border-radius: 10px; font-size: .7rem; color: white; font-weight: 500;
}
.kw-badge.rojo    { background: var(--rojo); }
.kw-badge.amarillo{ background: var(--amarillo); }
.kw-badge.verde   { background: var(--verde); }

.news-actions {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  min-width: 200px;
}
.semaforo {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.15); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: transform .1s;
}
.semaforo:hover { transform: scale(1.1); }
.semaforo.rojo { background: var(--rojo); }
.semaforo.amarillo { background: var(--amarillo); }
.semaforo.verde { background: var(--verde); }
.semaforo.sin_match { background: #adb5bd; }

.informed-row { display: flex; align-items: center; gap: 8px; }
.informed-check { width: 18px; height: 18px; cursor: pointer; }
.informed-label { font-size: .82rem; font-weight: 500; }

.btn-whatsapp {
  margin-left: 6px;
  padding: 3px 10px; border-radius: 6px;
  border: 1px solid #25d366;
  background: white; color: #128c7e;
  font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.btn-whatsapp:hover { background: #25d366; color: white; }
.btn-whatsapp.copiado { background: #25d366; color: white; border-color: #25d366; }

.notes-input {
  width: 100%; padding: 4px 8px; border: 1px solid var(--border);
  border-radius: 5px; font-size: .8rem; font-family: inherit;
  background: rgba(255,255,255,.7); resize: none;
}
.notes-input:focus { outline: none; border-color: var(--accent); }

.priority-select {
  font-size: .78rem; padding: 2px 6px; border: 1px solid var(--border);
  border-radius: 5px; cursor: pointer; background: white;
}

/* ─── MODALES ─── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5); align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: 10px; padding: 28px 32px;
  max-width: 520px; width: 90%; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal.modal-wide { max-width: 800px; }
.modal h2 { font-size: 1.3rem; margin-bottom: 16px; }
.modal h3 { font-size: 1rem; margin: 12px 0 8px; color: var(--text-muted); }
.modal label { font-size: .85rem; display: block; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.input-full { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: .9rem; }
.select-priority { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: .9rem; }

.kw-form { display: flex; gap: 8px; margin-bottom: 16px; align-items: flex-end; flex-wrap: wrap; }
.kw-form input { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .88rem; min-width: 140px; }

.keywords-table { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.kw-group-header {
  padding: 6px 12px; font-size: .78rem; font-weight: 700; letter-spacing: .5px;
  background: var(--bg); color: var(--text-muted); text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.kw-row, .portal-row {
  display: flex; align-items: center; padding: 8px 12px;
  border-bottom: 1px solid var(--border); gap: 10px;
  font-size: .85rem;
}
.kw-row:last-child, .portal-row:last-child { border-bottom: none; }
.kw-row:nth-child(even), .portal-row:nth-child(even) { background: var(--bg); }
.kw-word { flex: 1; font-weight: 500; }
.kw-prio { padding: 2px 10px; border-radius: 10px; font-size: .75rem; color: white; }
.kw-prio.rojo { background: var(--rojo); }
.kw-prio.amarillo { background: var(--amarillo); }
.kw-prio.verde { background: var(--verde); }

.portal-name { flex: 1; font-weight: 500; }
.portal-url { flex: 2; color: var(--text-muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-enabled { font-size: .75rem; }

/* Summary modal */
#summary-pre { white-space: pre-wrap; font-family: inherit; font-size: .88rem; line-height: 1.6; background: var(--bg); padding: 16px; border-radius: 6px; max-height: 50vh; overflow-y: auto; }

/* news detail modal */
.detail-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.detail-meta { font-size: .82rem; color: var(--text-muted); margin-bottom: 12px; }
.detail-summary { font-size: .9rem; line-height: 1.6; background: var(--bg); padding: 12px; border-radius: 6px; margin-bottom: 12px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #adb5bd; border-radius: 3px; }

/* ─── DARK MODE ─── */
.dark-mode {
  --bg: #0f1117;
  --surface: #1a1f2e;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-muted: #718096;
  --rojo-bg: #2d1515;
  --rojo-border: #5c2020;
  --amarillo-bg: #2d1f08;
  --amarillo-border: #5c3d10;
  --verde-bg: #0d2318;
  --verde-border: #144d26;
  --gray-bg: #1e2530;
  --gray-border: #2d3748;
  --accent: #63b3ed;
}
.dark-mode body            { background: var(--bg); color: var(--text); }
.dark-mode #toolbar        { background: var(--surface); border-color: var(--border); }
.dark-mode #last-update-bar{ background: #151922; border-color: var(--border); color: var(--text-muted); }
.dark-mode .filter-btn     { background: var(--surface); color: var(--text); border-color: var(--border); }
.dark-mode .filter-btn.active { color: white; }
.dark-mode .modal          { background: var(--surface); color: var(--text); }
.dark-mode .modal h3       { color: var(--text-muted); }
.dark-mode .input-full, .dark-mode .select-priority { background: var(--bg); color: var(--text); border-color: var(--border); }
.dark-mode .notes-input    { background: var(--bg); color: var(--text); border-color: var(--border); }
.dark-mode .priority-select{ background: var(--bg); color: var(--text); border-color: var(--border); }
.dark-mode .keywords-table { border-color: var(--border); }
.dark-mode .kw-group-header{ background: var(--bg); border-color: var(--border); }
.dark-mode .kw-row, .dark-mode .portal-row { border-color: var(--border); }
.dark-mode .kw-row:nth-child(even), .dark-mode .portal-row:nth-child(even) { background: rgba(255,255,255,.03); }
.dark-mode #summary-pre    { background: var(--bg); }
.dark-mode .news-card.sin_match { background: #1a1f2e; }

/* Note saved indicator */
.notes-input.saved { border-color: var(--verde) !important; transition: border-color .3s; }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  :root {
    --header-h: 108px;
    --toolbar-h: 96px;
    --update-h: 32px;
  }

  #header {
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
  }
  .header-left { width: 100%; }
  .header-center { width: 100%; }
  .header-right { width: 100%; justify-content: flex-end; gap: 6px; }
  .shift-info { display: none; }
  .stats-bar { gap: 6px; flex-wrap: wrap; }
  .stat { font-size: .75rem; padding: 2px 7px; }
  .btn { padding: 5px 10px; font-size: .8rem; }

  #toolbar {
    height: auto;
    min-height: var(--toolbar-h);
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 12px;
  }
  .filter-group { flex-wrap: wrap; gap: 4px; }
  #search-input { width: 100%; }

  .news-card { grid-template-columns: 1fr; }
  .news-thumb, .news-thumb-placeholder { width: 72px; height: 50px; }
  .news-actions { min-width: unset; width: 100%; align-items: flex-start; }

  .modal { padding: 18px 14px; width: 97vw; }
  .modal.modal-wide { max-width: 97vw; }
  .kw-form { flex-direction: column; }
  .kw-form input, .kw-form select { width: 100%; }
}

/* ─── LOGIN SCREEN ─── */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem;
  border-radius: 10px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
}

.login-box h2 {
  color: var(--text);
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 1.3rem;
}

.login-box input {
  display: block;
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}

.login-box input:focus { border-color: var(--accent); }

.error-msg {
  color: var(--rojo);
  margin-top: 0.5rem;
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* Dark mode login */
.dark-mode #login-screen { background: #0d1117; }
.dark-mode .login-box { background: #161b22; border-color: #30363d; }
.dark-mode .login-box input { background: #0d1117; color: #e6edf3; border-color: #30363d; }

/* ─── USER BADGE ─── */
.user-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ─── READ / UNREAD ─── */
.news-card.read {
  opacity: 0.55;
}
.news-card:not(.read) .news-thumb-wrapper::after {
  content: '👁';
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 14px;
  filter: drop-shadow(0 0 2px rgba(0,0,0,.5));
  pointer-events: none;
}
.news-thumb-wrapper {
  position: relative;
  flex-shrink: 0;
}
