/* =====================================================================
   Sistema de Consulta y Gestion de Periodistas -- sistema visual.
   CSS propio, sin framework externo, sin CDN (seccion 16 del encargo
   ADMIN/UI). Organizado en capas: tokens -> reset -> primitivos
   (botones/inputs/tablas/badges/tarjetas) -> layout de aplicacion
   (sidebar/header) -> paginas especificas (login, grafo, dashboard).
   ===================================================================== */

/* --- 1. Tokens -------------------------------------------------------- */
:root {
    color-scheme: light;

    --brand-50:  #eef2fb;
    --brand-100: #dbe4f6;
    --brand-300: #7d97d6;
    --brand-500: #2b4f9e;
    --brand-600: #1f3f87;
    --brand-700: #17316b;
    --brand-900: #0e1f45;

    --ink-900: #14181f;
    --ink-700: #333c4a;
    --ink-500: #5b6472;
    --ink-300: #8b93a1;
    --ink-100: #e4e7ec;
    --ink-50:  #f4f5f7;

    --surface: #ffffff;
    --surface-muted: #f7f8fa;
    --border: var(--ink-100);
    --border-strong: #cfd4dc;

    --success-fg: #1c6b3f;
    --success-bg: #e5f5ea;
    --success-bd: #bfe6cd;
    --warn-fg: #8a5a00;
    --warn-bg: #fff3dc;
    --warn-bd: #f3ddaa;
    --error-fg: #9a2a24;
    --error-bg: #fbeae9;
    --error-bd: #f2c7c3;
    --info-fg: var(--brand-700);
    --info-bg: var(--brand-50);
    --info-bd: var(--brand-100);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 31, 0.06);
    --shadow-md: 0 6px 20px rgba(20, 24, 31, 0.08);
    --shadow-pop: 0 12px 32px rgba(14, 31, 69, 0.16);

    --sidebar-w: 250px;
    --header-h: 60px;

    --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- 2. Reset ----------------------------------------------------------*/
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    color: var(--ink-900);
    background: var(--surface-muted);
    margin: 0;
    line-height: 1.5;
    font-size: 15px;
}
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; color: var(--ink-900); }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75em; }
a { color: var(--brand-600); }
ul { margin: 0; }
:focus-visible {
    outline: 2.5px solid var(--brand-500);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --- 3. Primitivos: botones -------------------------------------------*/
button, a.btn, .btn {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    text-decoration: none;
    background: var(--brand-600);
    color: #fff;
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
    white-space: nowrap;
}
button:hover, a.btn:hover, .btn:hover { background: var(--brand-700); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:disabled:hover { background: var(--brand-600); }

.btn-secondary, button.btn-secondary {
    background: var(--surface);
    color: var(--brand-700);
    border-color: var(--border-strong);
}
.btn-secondary:hover, button.btn-secondary:hover { background: var(--brand-50); border-color: var(--brand-300); }

.btn-danger, button.btn-danger {
    background: var(--error-fg);
}
.btn-danger:hover, button.btn-danger:hover { background: #7f221d; }

.btn-ghost, button.btn-ghost {
    background: transparent;
    color: var(--brand-700);
    border-color: transparent;
    padding: 0.4rem 0.6rem;
}
.btn-ghost:hover, button.btn-ghost:hover { background: var(--brand-50); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* --- 4. Primitivos: formularios ----------------------------------------*/
form .field, form label.field-label, .form-row { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem 1.25rem; }
.form-grid.cols-1 { grid-template-columns: 1fr; }

label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-700); margin-bottom: 0.3rem; }
label .req { color: var(--error-fg); }
.help-text { font-weight: 400; font-size: 0.78rem; color: var(--ink-500); margin-top: 0.25rem; }

input[type="text"], input[type="password"], input[type="email"], input[type="date"],
input[type="number"], input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    font-family: inherit;
    font-size: 0.92rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-900);
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-500); }
select { appearance: auto; }
textarea { resize: vertical; min-height: 5rem; }

.field-error { color: var(--error-fg); font-size: 0.78rem; margin-top: 0.3rem; font-weight: 600; }
.field.has-error input, .field.has-error select { border-color: var(--error-fg); }

fieldset { border: 1px solid var(--border); border-radius: var(--radius-md); margin: 0 0 1.25rem; padding: 1.1rem 1.25rem 1.25rem; background: var(--surface); }
legend { font-weight: 700; padding: 0 0.5rem; color: var(--ink-900); font-size: 0.95rem; }

.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 180px; margin-bottom: 0; }
.row > .field { flex: 1 1 180px; }

.inline-form { display: inline-block; }
.field-full { flex: 1 1 100%; }
.form-actions-sm { margin-top: 0.75rem; }
.gap-sm { gap: 0.35rem; }
.btn-group-top { margin-top: 1rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.checkbox-label input[type="checkbox"] { width: auto; }

/* --- 5. Primitivos: tarjetas / stats ------------------------------------*/
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }
.card-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.75rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 1rem;
    margin: 0 0 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-value { font-size: 1.9rem; font-weight: 800; color: var(--brand-700); line-height: 1.1; }
.stat-card .stat-label { font-size: 0.82rem; color: var(--ink-500); margin-top: 0.35rem; font-weight: 600; }
.stat-card.stat-accent-warn .stat-value { color: var(--warn-fg); }
.stat-card.stat-accent-error .stat-value { color: var(--error-fg); }
.stat-card.stat-accent-ok .stat-value { color: var(--success-fg); }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.75rem 0 0.85rem; }
.section-title h2 { margin: 0; }

/* --- 6. Primitivos: tablas ----------------------------------------------*/
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 480px; }
th, td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-muted); color: var(--ink-500); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
tbody tr:hover { background: var(--brand-50); }
tbody tr:last-child td { border-bottom: none; }
td.col-actions { text-align: right; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--ink-500); font-style: normal; padding: 2rem 1rem; }
.empty-row .empty-icon { display: block; margin: 0 auto 0.5rem; color: var(--ink-300); }

/* --- 7. Badges (estados) -------------------------------------------------*/
.badge, .tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-role { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); text-transform: none; }

.tag-vigente, .tag-active, .tag-approved, .badge-ok { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-bd); }
.tag-vencida, .tag-inactive, .tag-denied, .tag-cancelled, .tag-cancelada, .badge-error { background: var(--error-bg); color: var(--error-fg); border-color: var(--error-bd); }
.tag-pending, .badge-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.tag-expired, .tag-vencido { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }

/* --- 8. Flash / feedback -------------------------------------------------*/
.flash {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 1.1rem;
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.88rem;
    border: 1px solid transparent;
}
.flash-error { background: var(--error-bg); color: var(--error-fg); border-color: var(--error-bd); }
.flash-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-bd); }
.flash-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-bd); }
.flash-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-bd); }
.flash.graph-flash-hidden { display: none; }
.error { color: var(--error-fg); font-weight: 600; }

/* --- 9. Layout de aplicacion autenticada (sidebar + header) --------------*/
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(180deg, var(--brand-900), var(--brand-700));
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.25rem 1.1rem;
    font-weight: 800;
    font-size: 0.92rem;
    line-height: 1.2;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-brand-mark { color: var(--brand-300); flex-shrink: 0; }
.sidebar-nav { padding: 0.75rem 0.6rem; flex: 1; }
.sidebar-nav ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-sep { height: 1px; background: rgba(255,255,255,0.12); margin: 0.6rem 0.4rem; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.82);
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
}
.sidebar-link:hover { background: rgba(255,255,255,0.09); color: #fff; }
.sidebar-link.is-active { background: rgba(255,255,255,0.16); color: #fff; }
.sidebar-icon { display: flex; flex-shrink: 0; }
.sidebar-logout-form { margin: 0; }
.sidebar-logout { color: rgba(255,255,255,0.7); }
.sidebar-backdrop { display: none; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.app-title { flex: 1; font-size: 1.05rem; margin: 0; }
.app-header-user { display: flex; align-items: center; }
.user-chip { display: flex; align-items: center; gap: 0.55rem; font-size: 0.85rem; }
.user-chip-name { font-weight: 700; color: var(--ink-900); }

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}
.hamburger span { display: block; width: 16px; height: 2px; background: var(--ink-700); margin: 0 auto; }
.hamburger:hover { background: var(--brand-50); }

.app-content { flex: 1; padding: 1.5rem; width: 100%; }
.app-content main { max-width: 1180px; margin: 0 auto; }
.app-content main.wide { max-width: 1180px; }
.app-content main.graph-page { max-width: 100%; }
.app-content main.login-page { max-width: 400px; }

nav.breadcrumb { margin-bottom: 1rem; font-size: 0.85rem; color: var(--ink-500); }
nav.breadcrumb a { color: var(--brand-600); text-decoration: none; font-weight: 600; }
nav.breadcrumb a:hover { text-decoration: underline; }

/* --- 10. Login (pantalla sin sesion) --------------------------------------*/
body:not(.app-body) {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--brand-900), var(--brand-600));
    padding: 1.5rem;
}
main.login-page {
    max-width: 400px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    padding: 2.25rem 2rem;
}
main.login-page h1 { text-align: center; font-size: 1.2rem; color: var(--brand-800, var(--brand-700)); margin-bottom: 1.5rem; }
main.login-page button { width: 100%; justify-content: center; padding: 0.7rem; margin-top: 0.25rem; }
body:not(.app-body) .flash, body:not(.app-body) p.error { max-width: 400px; margin: 0 auto 1rem; }

/* --- 11. Modales -----------------------------------------------------------*/
.modal-overlay {
    position: fixed; inset: 0; background: rgba(14,31,69,0.45);
    display: none; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}
.modal-overlay.is-open { display: flex; }
.modal {
    background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-pop);
    max-width: 420px; width: 100%; padding: 1.5rem;
}
.modal h2 { margin-bottom: 0.5rem; font-size: 1.05rem; }
.modal p { color: var(--ink-700); font-size: 0.9rem; }
.modal .btn-group { justify-content: flex-end; margin-top: 1.25rem; }

/* --- 12. Dashboards: listado "recientes" ----------------------------------*/
.mini-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.mini-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.mini-list li:last-child { border-bottom: none; }
.mini-list .mini-list-meta { color: var(--ink-500); font-size: 0.78rem; }
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 980px) { .dashboard-grid { grid-template-columns: 1fr; } }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* --- 13. Consulta natural ---------------------------------------------------*/
.query-box { display: flex; gap: 0.6rem; margin-bottom: 0.75rem; }
.query-box input[type="text"] { flex: 1; font-size: 1rem; padding: 0.75rem 1rem; }
.query-examples { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.query-examples button { background: var(--brand-50); color: var(--brand-700); border: 1px solid var(--brand-100); font-weight: 600; font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.query-examples button:hover { background: var(--brand-100); }

/* --- 14. Grafo (conserva la logica de Fase 8, solo mejora integracion) ----*/
.graph-toolbar { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; margin: 0 0 1rem; }
.graph-toolbar .field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; margin: 0; }
.graph-toolbar input[type="text"] { min-width: 220px; }
.graph-layout { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
.graph-canvas-outer { position: relative; }
.graph-canvas-wrap {
    width: 100%; height: 68vh; min-height: 420px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: #05070d; overflow: hidden; box-shadow: var(--shadow-sm);
}
.graph-canvas-wrap canvas { display: block; }
.graph-search-results {
    position: absolute; top: 0.6rem; left: 0.6rem; z-index: 5;
    background: rgba(255,255,255,0.98); border: 1px solid var(--border); border-radius: var(--radius-sm);
    max-width: 320px; max-height: 220px; overflow-y: auto; font-size: 0.85rem; display: none; box-shadow: var(--shadow-md);
}
.graph-search-results.visible { display: block; }
.graph-search-results button { display: block; width: 100%; text-align: left; background: none; color: var(--ink-900); padding: 0.45rem 0.7rem; border-radius: 0; font-weight: 500; }
.graph-search-results button:hover { background: var(--brand-50); }
.graph-search-empty { padding: 0.6rem 0.7rem; color: var(--ink-500); font-size: 0.85rem; }
.graph-panel { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.1rem; font-size: 0.88rem; min-height: 200px; background: var(--surface); box-shadow: var(--shadow-sm); }
.graph-panel dl { margin: 0.5rem 0; }
.graph-panel dt { font-weight: 700; margin-top: 0.6rem; color: var(--ink-700); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.graph-panel dd { margin: 0.15rem 0 0.4rem; }
.graph-panel ul { padding-left: 1.1rem; margin: 0.25rem 0; }
.graph-empty-hint { color: var(--ink-500); font-size: 0.85rem; }
.graph-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0 0 0.75rem; font-size: 0.78rem; color: var(--ink-500); }
.graph-legend-item { display: flex; align-items: center; gap: 0.4rem; }
.graph-legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
/* Colores identicos a colorForNode() en assets/js/graph.js -- la leyenda
   nunca debe divergir de lo que el grafo realmente dibuja. */
.graph-legend-dot-journalist-active { background: #2fa84f; }
.graph-legend-dot-journalist-inactive { background: #9e9e9e; }
.graph-legend-dot-media { background: #3f7fd6; }

/* --- 15. Responsive: sidebar colapsable ------------------------------------*/
@media (max-width: 880px) {
    .hamburger { display: flex; }
    .sidebar {
        position: fixed; left: 0; top: 0; height: 100vh;
        transform: translateX(-100%);
        transition: transform .18s ease;
        box-shadow: var(--shadow-pop);
    }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(14,31,69,0.4); z-index: 25;
    }
    .sidebar-backdrop.is-open { display: block; }
    .app-content { padding: 1rem; }
    .graph-layout { grid-template-columns: 1fr; }
    .graph-canvas-wrap { height: 52vh; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .app-header { padding: 0 1rem; }
    .app-title { font-size: 0.95rem; }
    .user-chip-name { display: none; }
}
@media (max-width: 620px) {
    .row { flex-direction: column; align-items: stretch; }
    .row > label, .row > .field { flex: 1 1 auto; }
    .form-grid { grid-template-columns: 1fr; }
    table { min-width: 100%; }
    th, td { padding: 0.55rem 0.6rem; font-size: 0.82rem; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
}
