/* =============================================================
   SecureEngine - estilos
   ============================================================= */
:root {
    --bg: #f3f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #0891b2;
    --topbar: #0b1f3a;
    --sidebar: #0f2747;
    --sidebar-text: #cbd5e1;
    --danger: #dc2626;
    --red: #dc2626; --orange: #ea580c; --yellow: #ca8a04; --green: #16a34a; --blue: #2563eb; --teal: #0d9488; --purple: #7c3aed; --gray: #64748b;
    --radius: 10px;
    --topbar-h: 62px;
    --sidebar-w: 236px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: Consolas, "Cascadia Mono", Menlo, monospace; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: .92em; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }

/* ---------- barra superior (siempre visible) ---------- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0 1rem; background: var(--topbar); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.topbar-left { display: flex; align-items: center; gap: .5rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-name { font-size: 1.25rem; letter-spacing: .3px; font-weight: 300; }
.brand-name strong { font-weight: 700; color: #22d3ee; }
.nav-toggle { display: none; background: transparent; border: 0; color: #fff; cursor: pointer; padding: 6px; }
.topbar-right { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.session-timer { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; color: #93c5fd; font-variant-numeric: tabular-nums; }
.session-timer.warn { color: #fbbf24; }
.user-chip { display: flex; align-items: center; gap: .6rem; color: #fff; padding: 4px 10px 4px 4px; border-radius: 30px; min-width: 0; }
.user-chip:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { font-size: .74rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 380px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #22d3ee, #2563eb); color: #fff; font-weight: 700; font-size: .85rem; flex: none;
}
.avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }
.logout-form { margin: 0; }
.btn-logout { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.25); }
.btn-logout:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

/* ---------- menú lateral ---------- */
.sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 40;
    background: var(--sidebar); color: var(--sidebar-text); overflow-y: auto; display: flex; flex-direction: column;
    padding: .8rem .6rem;
}
.sidebar nav { flex: 1; }
.nav-link { display: flex; align-items: center; gap: .65rem; padding: .58rem .75rem; border-radius: 8px; color: var(--sidebar-text); margin-bottom: 2px; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-section { text-transform: uppercase; font-size: .7rem; letter-spacing: 1px; color: #64748b; margin: 1rem .75rem .35rem; }
.sidebar-foot { font-size: .72rem; color: #64748b; padding: .75rem; text-align: center; }
.icon { flex: none; vertical-align: -3px; }

/* ---------- contenido ---------- */
.content { margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 1.25rem) 1.5rem 2rem; min-height: 100vh; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.45rem; }
.page-head p { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); font-weight: 600; }
.inline { display: inline; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card > h3:first-child { margin-bottom: .8rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
details.card > summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.grid { display: grid; gap: 1rem; margin-bottom: 0; }
.grid > .card, .grid > section, .grid > div > .card:last-child { margin-bottom: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1fr) 320px; }
.link-more { display: inline-block; margin-top: .6rem; font-size: .85rem; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; border-left: 4px solid var(--blue); }
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi-value { font-size: 1.8rem; font-weight: 700; margin: .15rem 0; }
.kpi-sub { font-size: .8rem; color: var(--muted); }
.kpi-red { border-left-color: var(--red); } .kpi-orange { border-left-color: var(--orange); } .kpi-teal { border-left-color: var(--teal); } .kpi-blue { border-left-color: var(--blue); }
.kpi-compliance { align-items: center; text-align: center; border-left-color: var(--accent); }
.kpi-compliance .donut { width: 110px; height: 110px; margin: .4rem 0; }

/* ---------- gráficas SVG ---------- */
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: .6rem; margin: .45rem 0; }
.bar-label { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row:has(.bar-label.wide) { grid-template-columns: minmax(150px, 46%) 1fr 34px; }
.bar-value { text-align: right; font-weight: 600; font-size: .85rem; }
.bar { width: 100%; height: 10px; display: block; }
.minw .bar { min-width: 90px; margin-bottom: 2px; }
.bar-bg { fill: #e2e8f0; }
.fill-critica { fill: var(--red); } .fill-alta { fill: var(--orange); } .fill-media { fill: var(--yellow); } .fill-baja { fill: var(--green); } .fill-informativa { fill: var(--blue); } .fill-accent { fill: var(--accent); }
.donut { width: 150px; height: 150px; display: block; margin: .5rem auto; }
.donut-bg { stroke: #e2e8f0; }
.donut-fg { stroke: var(--green); }
.donut-ok { stroke: var(--green); } .donut-warn { stroke: var(--yellow); } .donut-bad { stroke: var(--red); }
.donut-text { font-size: 8px; font-weight: 700; fill: var(--text); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-red { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge-orange { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.badge-yellow { background: #fef9c3; color: #854d0e; border-color: #fde68a; }
.badge-green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-blue { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge-teal { background: #ccfbf1; color: #115e59; border-color: #99f6e4; }
.badge-purple { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.badge-gray { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
.table, .md-table { width: 100%; border-collapse: collapse; }
.table th, .table td, .md-table th, .md-table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th, .md-table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--surface-2); }
.table tbody tr:hover { background: #f8fbff; }
.md-table { margin: .5rem 0; font-size: .9rem; }
.md-table th { text-transform: none; letter-spacing: 0; font-size: .85rem; }
.row-muted td { color: #94a3b8; }
.row-new { background: #ecfdf5; }
.matrix td, .matrix th { text-align: center; }
.cell-hot { font-weight: 700; }
.cell-critica { background: #fee2e2; } .cell-alta { background: #ffedd5; } .cell-media { background: #fef9c3; } .cell-baja { background: #dcfce7; } .cell-informativa { background: #dbeafe; }

/* ---------- botones ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .35rem; padding: .48rem .9rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2; white-space: nowrap;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-xs { padding: .2rem .4rem; font-size: .75rem; }
.btn-block { width: 100%; justify-content: center; margin-top: .6rem; }

/* ---------- formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: 1 / -1; }
.form-grid:not(.cols-4) .span-4 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .3rem; }
label { font-weight: 600; font-size: .85rem; color: #334155; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], select, textarea {
    width: 100%; padding: .5rem .65rem; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
textarea.mono { font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.readonly, input[readonly] { background: #f1f5f9; color: #475569; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin-top: 1rem; }
.fieldset legend { font-weight: 700; padding: 0 .4rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.field-error { color: var(--danger); font-size: .8rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; flex: 0 1 220px; }
.inline-label { display: inline-flex; gap: .4rem; align-items: center; font-weight: 500; }
.inline-label input { width: auto; }
.inline-assign select { min-width: 170px; padding: .3rem .4rem; font-size: .85rem; }
.inline-row { display: flex; justify-content: space-between; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--border); margin: 0; }
.upload-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.upload-form input[type=text] { flex: 1 1 200px; width: auto; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 2.4rem; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; cursor: pointer; font-size: 1rem; opacity: .6; }
.pw-rules { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .25rem; font-size: .84rem; }
.pw-rules li { color: var(--muted); padding-left: 1.4rem; position: relative; }
.pw-rules li::before { content: "○"; position: absolute; left: 0; color: #94a3b8; }
.pw-rules li.ok { color: #166534; }
.pw-rules li.ok::before { content: "✔"; color: var(--green); }
.pw-mismatch { border-color: var(--danger) !important; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; padding: 2rem 1rem; border: 2px dashed #93c5fd; border-radius: var(--radius); background: #f8fbff; cursor: pointer; text-align: center; color: #1e40af; margin-bottom: 1rem; }
.dropzone .icon { width: 32px; height: 32px; }
.dropzone.drag { background: #dbeafe; }
.dropzone input { max-width: 100%; }

/* ---------- alertas ---------- */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ---------- pestañas ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab { padding: .55rem .85rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- markdown ---------- */
.md { overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { margin: 1rem 0 .4rem; }
.md h1 { font-size: 1.25rem; } .md h2 { font-size: 1.12rem; } .md h3 { font-size: 1rem; } .md h4, .md h5, .md h6 { font-size: .95rem; }
.md pre { background: #0f172a; color: #e2e8f0; padding: .8rem; border-radius: 8px; overflow-x: auto; font-size: .82rem; }
.md pre code { background: transparent; color: inherit; padding: 0; }
.md blockquote { border-left: 4px solid #bfdbfe; margin: .5rem 0; padding: .2rem .9rem; color: #475569; background: #f8fbff; }
.md li.lvl1 { margin-left: 1.2rem; } .md li.lvl2 { margin-left: 2.4rem; } .md li.lvl3 { margin-left: 3.6rem; }
.md-section { border-bottom: 1px solid var(--border); padding-bottom: .8rem; margin-bottom: .8rem; }
.md-section:last-child { border-bottom: 0; margin-bottom: 0; }
.md-section-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }

/* ---------- listas ---------- */
.task-list, .rec-list, .file-list { list-style: none; padding: 0; margin: 0; }
.task-list li, .rec-list li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.task-list li:last-child, .rec-list li:last-child { border-bottom: 0; }
.task-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .3rem; font-size: .8rem; }
.rec-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.priority-list { padding-left: 1.3rem; margin: 0; }
.priority-list li { margin: .4rem 0; }
.check-list { padding-left: 1.2rem; } .check-list li { margin: .35rem 0; }
.file-list li { padding: .3rem 0; }
.props { display: grid; grid-template-columns: 110px 1fr; gap: .45rem .6rem; margin: 0; }
.props dt { color: var(--muted); font-size: .82rem; }
.props dd { margin: 0; overflow-wrap: anywhere; }
.profile-head { display: flex; gap: .9rem; align-items: center; margin-bottom: 1rem; }

/* ---------- galería ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin: .8rem 0; }
.thumb { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); color: var(--text); font-size: .78rem; }
.thumb img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumb span { padding: .3rem .45rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- modal de sesión ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-box { background: #fff; border-radius: 12px; padding: 1.4rem 1.5rem; max-width: 420px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

.modal-wide { max-width: 560px; display: flex; flex-direction: column; gap: .4rem; }
.modal-wide h3 { display: flex; align-items: center; gap: .4rem; }

/* ---------- configuración ---------- */
.switch { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; margin: .3rem 0 1rem; cursor: pointer; }
.switch.tiny { font-weight: 500; margin: .2rem 0 0; font-size: .78rem; }
.steps { padding-left: 1.2rem; margin: 0 0 .6rem; }
.steps li { margin: .35rem 0; }

/* ---------- base de conocimientos ---------- */
.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kb-grid > .card { margin-bottom: 0; }
.kb-group { grid-column: 1 / -1; margin: .6rem 0 -.2rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.kb-item { display: flex; flex-direction: column; gap: .35rem; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.kb-item:hover { text-decoration: none; border-color: #93c5fd; box-shadow: 0 4px 14px rgba(37, 99, 235, .12); }
.kb-item .badge { align-self: flex-start; }
.kb-code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .8rem; font-weight: 700; color: var(--primary); }
.kb-summary { font-size: 1rem; color: #334155; margin-top: 0; }
.kb-mitigation { border-left: 4px solid var(--green); }
.kb-mitigation h3 { display: flex; gap: .4rem; align-items: center; color: #166534; }
.kb-links { padding-left: 1.1rem; }
.kb-links li { margin: .25rem 0; }
.kb-ref { display: inline-flex; align-items: center; gap: .2rem; font-size: .78rem; margin-right: .4rem; }
.kb-ref .icon { width: 13px; height: 13px; }
.card-inline { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; border-left: 4px solid var(--primary); }

.section-title { display: flex; align-items: center; gap: .45rem; font-size: 1.1rem; margin: 1.4rem 0 .8rem; }
.inline-row input[type=text] { flex: 1 1 auto; width: auto; margin-right: .5rem; }
.inline-row select { width: auto; margin: 0 .5rem; }
.login-sep { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .8rem; margin: .8rem 0 .2rem; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-google { background: #fff; border-color: #dadce0; color: #3c4043; gap: .6rem; }
.btn-google:hover { background: #f8f9fa; border-color: #c6c9cc; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; background: radial-gradient(1200px 600px at 10% 10%, #12396b 0%, #0b1f3a 55%, #071427 100%); display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-wrap { display: grid; grid-template-columns: 1.1fr 1fr; max-width: 900px; width: 100%; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.login-hero { padding: 2.5rem; color: #cbd5e1; }
.login-hero h1 { color: #fff; font-size: 2rem; font-weight: 300; margin-top: .8rem; }
.login-hero h1 strong { color: #22d3ee; font-weight: 700; }
.login-hero ul { padding-left: 1.1rem; margin-top: 1.2rem; }
.login-hero li { margin: .4rem 0; }
.login-card { background: #fff; padding: 2.5rem 2.2rem; display: flex; flex-direction: column; gap: .45rem; }
.login-card h2 { margin-bottom: .8rem; }
.login-card input { margin-bottom: .6rem; }
.login-note { font-size: .76rem; color: var(--muted); text-align: center; margin-top: 1rem; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .grid-side { grid-template-columns: 1fr; }
    .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-3 { grid-column: span 2; }
    .user-meta small { max-width: 200px; }
}
@media (max-width: 860px) {
    .nav-toggle { display: inline-flex; }
    .sidebar { transform: translateX(-100%); transition: transform .2s; }
    body.nav-open .sidebar { transform: none; }
    .content { margin-left: 0; padding-left: 1rem; padding-right: 1rem; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .form-grid, .form-grid.cols-4 { grid-template-columns: 1fr; }
    .span-2, .span-3, .span-4 { grid-column: auto; }
    .user-meta, .session-timer span, .btn-logout span, .brand-name { display: none; }
    .login-wrap { grid-template-columns: 1fr; }
    .login-hero { display: none; }
}
@media print {
    .topbar, .sidebar, .page-actions, .filters, .tabs, .upload-form, .form-actions { display: none !important; }
    .content { margin: 0; padding: 0; }
    .tab-panel[hidden] { display: block !important; }
}

/* =============================================================
   Preferencias de interfaz: idioma y tema
   ============================================================= */
.ui-prefs { display: flex; align-items: center; gap: .45rem; flex: none; }
.lang-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; overflow: hidden; }
.lang-switch a { padding: .28rem .5rem; font-size: .72rem; font-weight: 700; color: #cbd5e1; letter-spacing: .3px; }
.lang-switch a:hover { text-decoration: none; background: rgba(255,255,255,.1); }
.lang-switch a.active { background: var(--primary); color: #fff; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: .3rem .42rem; cursor: pointer; }
.theme-toggle:hover { background: rgba(255,255,255,.1); }
[data-theme="dark"] .theme-toggle .icon-moon, [data-theme="light"] .theme-toggle .icon-sun, html:not([data-theme]) .theme-toggle .icon-sun { display: none; }
.login-prefs { position: fixed; top: 1rem; right: 1rem; z-index: 5; }

/* =============================================================
   Tema oscuro
   ============================================================= */
[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220;
    --surface: #111a2e;
    --surface-2: #0f1729;
    --border: #24324d;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --topbar: #060d1a;
    --sidebar: #0a1426;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.35);
}
[data-theme="dark"] a { color: #60a5fa; }
[data-theme="dark"] .user-chip, [data-theme="dark"] .brand, [data-theme="dark"] .lang-switch a { color: inherit; }
[data-theme="dark"] .nav-link { color: var(--sidebar-text); }
[data-theme="dark"] .nav-link.active, [data-theme="dark"] .lang-switch a.active, [data-theme="dark"] .user-chip, [data-theme="dark"] .brand { color: #fff; }
[data-theme="dark"] .lang-switch a:not(.active) { color: #cbd5e1; }
[data-theme="dark"] .btn { color: var(--text); }
[data-theme="dark"] .btn-primary { color: #fff; }
[data-theme="dark"] .btn-logout { color: #fff; }
[data-theme="dark"] code { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] label { color: #cbd5e1; }
[data-theme="dark"] input[type=text], [data-theme="dark"] input[type=email], [data-theme="dark"] input[type=password],
[data-theme="dark"] input[type=search], [data-theme="dark"] input[type=number], [data-theme="dark"] input[type=date],
[data-theme="dark"] select, [data-theme="dark"] textarea { background: #0f1729; border-color: #334155; color: var(--text); }
[data-theme="dark"] .readonly, [data-theme="dark"] input[readonly] { background: #1b2742; color: #94a3b8; }
[data-theme="dark"] .btn:hover { background: #1b2742; }
[data-theme="dark"] .btn-primary:hover { background: var(--primary-dark); }
[data-theme="dark"] .btn-danger { background: transparent; border-color: rgba(248,113,113,.45); color: #f87171; }
[data-theme="dark"] .btn-danger:hover { background: #dc2626; color: #fff; }
[data-theme="dark"] .btn-google { background: #131314; border-color: #8e918f; color: #e3e3e3; }
[data-theme="dark"] .table tbody tr:hover { background: #16213a; }
[data-theme="dark"] .row-muted td { color: #64748b; }
[data-theme="dark"] .row-new { background: #0d2a1e; }
[data-theme="dark"] .bar-bg { fill: #24324d; }
[data-theme="dark"] .donut-bg { stroke: #24324d; }
[data-theme="dark"] .badge-red { background: rgba(220,38,38,.18); color: #fca5a5; border-color: rgba(248,113,113,.35); }
[data-theme="dark"] .badge-orange { background: rgba(234,88,12,.18); color: #fdba74; border-color: rgba(251,146,60,.35); }
[data-theme="dark"] .badge-yellow { background: rgba(202,138,4,.18); color: #fde047; border-color: rgba(250,204,21,.3); }
[data-theme="dark"] .badge-green { background: rgba(22,163,74,.18); color: #86efac; border-color: rgba(74,222,128,.3); }
[data-theme="dark"] .badge-blue { background: rgba(37,99,235,.2); color: #93c5fd; border-color: rgba(96,165,250,.35); }
[data-theme="dark"] .badge-teal { background: rgba(13,148,136,.2); color: #5eead4; border-color: rgba(45,212,191,.3); }
[data-theme="dark"] .badge-purple { background: rgba(124,58,237,.22); color: #c4b5fd; border-color: rgba(167,139,250,.35); }
[data-theme="dark"] .badge-gray { background: rgba(100,116,139,.2); color: #cbd5e1; border-color: rgba(148,163,184,.3); }
[data-theme="dark"] .alert-success { background: #052e1a; border-color: #14532d; color: #86efac; }
[data-theme="dark"] .alert-danger { background: #3a0d0d; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: #33250a; border-color: #78350f; color: #fcd34d; }
[data-theme="dark"] .alert-info { background: #0b2447; border-color: #1e3a8a; color: #93c5fd; }
[data-theme="dark"] .alert a { color: inherit; text-decoration: underline; }
[data-theme="dark"] .cell-critica { background: rgba(220,38,38,.22); }
[data-theme="dark"] .cell-alta { background: rgba(234,88,12,.22); }
[data-theme="dark"] .cell-media { background: rgba(202,138,4,.22); }
[data-theme="dark"] .cell-baja { background: rgba(22,163,74,.22); }
[data-theme="dark"] .cell-informativa { background: rgba(37,99,235,.22); }
[data-theme="dark"] .md blockquote { background: #13203a; border-left-color: #1e3a8a; color: #cbd5e1; }
[data-theme="dark"] .md pre { background: #060d1a; border: 1px solid var(--border); }
[data-theme="dark"] .dropzone { background: #0f1d36; border-color: #1e40af; color: #93c5fd; }
[data-theme="dark"] .dropzone.drag { background: #13284d; }
[data-theme="dark"] .modal-box, [data-theme="dark"] .login-card { background: var(--surface); color: var(--text); }
[data-theme="dark"] .kb-summary { color: #cbd5e1; }
[data-theme="dark"] .kb-mitigation h3, [data-theme="dark"] .pw-rules li.ok { color: #86efac; }
[data-theme="dark"] .kb-item:hover { border-color: #3b82f6; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
[data-theme="dark"] .thumb, [data-theme="dark"] .kb-item { color: var(--text); }
[data-theme="dark"] .donut-text { fill: var(--text); }

/* =============================================================
   Responsivo adicional (tableta y teléfono)
   ============================================================= */
.inline-row { flex-wrap: wrap; gap: .4rem; }
@media (max-width: 860px) {
    .topbar { padding: 0 .6rem; gap: .5rem; }
    .topbar-right { gap: .45rem; }
    .page-head h1 { font-size: 1.2rem; }
    .page-actions { width: 100%; }
    .page-actions .btn, .page-actions form { flex: 1 1 auto; }
    .page-actions .btn { justify-content: center; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .kpi { padding: .7rem .8rem; }
    .kpi-value { font-size: 1.45rem; }
    .card { padding: .85rem .9rem; }
    .filters input[type=search], .filters select { flex: 1 1 100%; }
    .filters .btn { width: 100%; justify-content: center; }
    .card-inline { flex-direction: column; align-items: stretch; }
    .bar-row, .bar-row:has(.bar-label.wide) { grid-template-columns: minmax(90px, 40%) 1fr 32px; }
    .table, .md-table { font-size: .84rem; }
    .table th, .table td { padding: .45rem .45rem; }
    .props { grid-template-columns: 95px 1fr; }
    .login-prefs { top: .6rem; right: .6rem; }
    .modal-box { padding: 1rem; }
}
@media (max-width: 520px) {
    .kpis { grid-template-columns: 1fr; }
    .session-timer { display: none; }
    .brand img { width: 30px; height: 30px; }
    .lang-switch a { padding: .25rem .4rem; }
    .content { padding-left: .7rem; padding-right: .7rem; }
    .tabs { margin-left: -.7rem; margin-right: -.7rem; padding: 0 .7rem; }
    .tab { padding: .5rem .6rem; font-size: .85rem; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; justify-content: center; }
    .upload-form > * { flex: 1 1 100%; }
    .login-card { padding: 1.6rem 1.2rem; }
    .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* casillas de selección múltiple (activos de un hallazgo) */
.label { font-weight: 600; font-size: .85rem; color: #334155; }
[data-theme="dark"] .label { color: #cbd5e1; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .3rem .8rem; max-height: 220px; overflow-y: auto; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.check-item { display: flex; align-items: center; gap: .4rem; font-weight: 500; font-size: .86rem; cursor: pointer; }
.check-item input { width: auto; }
