/* MonYThor v3 · hoja de estilos única, sin dependencias.
   Tokens de color en :root; tema oscuro automático (prefers-color-scheme) o forzado con data-theme. */

:root {
  --brand: #006083;
  --brand-strong: #004c69;
  --brand-soft: #e3f1f6;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e2e7ec;
  --text: #17212b;
  --muted: #5f6b77;
  --ok: #1d7a4a;      --ok-soft: #e2f4ea;
  --warn: #a15c00;    --warn-soft: #fdf0dc;
  --danger: #b42318;  --danger-soft: #fde8e6;
  --info: #175cd3;    --info-soft: #e6effd;
  --c1: #006083; --c2: #d9730d; --c3: #2f9e6e; --c4: #7a4fd0; --c5: #c23a6b; --c6: #6b7785;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --sidebar-w: 236px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #3fb0d9; --brand-strong: #6cc6e6; --brand-soft: #0f3341;
    --bg: #0f1419; --surface: #161d24; --surface-2: #1b232b; --border: #29333d;
    --text: #e6ebf0; --muted: #98a4b0;
    --ok: #4cc38a; --ok-soft: #12321f; --warn: #f0a74a; --warn-soft: #3a2a12;
    --danger: #f97066; --danger-soft: #3b1a17; --info: #7cb0ff; --info-soft: #14284a;
    --c1: #3fb0d9; --c2: #f0a74a; --c3: #4cc38a; --c4: #a78bfa; --c5: #f472b6; --c6: #98a4b0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #3fb0d9; --brand-strong: #6cc6e6; --brand-soft: #0f3341;
  --bg: #0f1419; --surface: #161d24; --surface-2: #1b232b; --border: #29333d;
  --text: #e6ebf0; --muted: #98a4b0;
  --ok: #4cc38a; --ok-soft: #12321f; --warn: #f0a74a; --warn-soft: #3a2a12;
  --danger: #f97066; --danger-soft: #3b1a17; --info: #7cb0ff; --info-soft: #14284a;
  --c1: #3fb0d9; --c2: #f0a74a; --c3: #4cc38a; --c4: #a78bfa; --c5: #f472b6; --c6: #98a4b0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* --- Base ------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .5rem; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 100; background: var(--surface); padding: .5rem 1rem; border-radius: 6px; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.mono { font-family: var(--mono); font-size: .9em; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; }
.push { margin-left: auto; }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
.inline { display: inline; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; margin: 0; }

/* --- Shell ------------------------------------------------------------------ */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; padding: 1rem .75rem;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; color: var(--text); padding: .25rem .5rem 1rem; }
.brand:hover { text-decoration: none; }
.nav-section { text-transform: uppercase; font-size: .7rem; letter-spacing: .06em; color: var(--muted); margin: 1rem .6rem .35rem; font-weight: 600; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: .65rem; padding: .5rem .6rem; border-radius: 8px; color: var(--text); font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); }
.sidebar .badge { margin-left: auto; background: var(--warn-soft); color: var(--warn); border-radius: 999px; font-size: .75rem; padding: 0 .5rem; font-weight: 600; }
.version { margin-top: auto; padding: 1rem .6rem 0; color: var(--muted); font-size: .75rem; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .6rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topsearch { flex: 1; max-width: 520px; display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0 .75rem; color: var(--muted); }
.topsearch input[type="search"] { border: 0; background: transparent; padding: .5rem 0; width: 100%; color: var(--text); font: inherit; box-shadow: none; }
.topsearch input[type="search"]:focus { outline: none; box-shadow: none; }
.topsearch:focus-within { border-color: var(--brand); }
.icon-btn { margin-left: auto; background: none; border: 1px solid transparent; color: var(--text); border-radius: 8px; padding: .4rem; cursor: pointer; line-height: 0; }
.icon-btn + .icon-btn, .topsearch + .icon-btn { margin-left: auto; }
.icon-btn:hover { background: var(--surface); border-color: var(--border); }
.theme-light { display: none; }
:root[data-theme="dark"] .theme-light { display: inline; }
:root[data-theme="dark"] .theme-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-light { display: inline; }
  :root:not([data-theme="light"]) .theme-dark { display: none; }
}

.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem .4rem; border-radius: 8px; font-weight: 500; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface); }
.usermenu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: .4rem; z-index: 30;
}
.usermenu-head { padding: .5rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.usermenu-panel a, .usermenu-panel button {
  display: flex; gap: .5rem; align-items: center; width: 100%; padding: .5rem .6rem; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}
.usermenu-panel a:hover, .usermenu-panel button:hover { background: var(--surface-2); text-decoration: none; }

.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar-initials { display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; }
.avatar-lg { width: 112px; height: 112px; font-size: 2.4rem; margin: .5rem auto 1rem; display: grid; }

.content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; max-width: 1500px; width: 100%; margin: 0 auto; }
.footer { padding: 1rem 1.5rem 1.5rem; color: var(--muted); font-size: .8rem; text-align: center; }
.backdrop { display: none; }

/* --- Componentes ------------------------------------------------------------ */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head p { margin: .25rem 0 0; }
.crumbs { margin: 0 0 .15rem !important; font-size: .85rem; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.card-head.padded { padding: 1rem 1.25rem 0; }
.link { display: inline-flex; align-items: center; gap: .25rem; font-size: .85rem; font-weight: 500; }
.link .icon { width: 14px; height: 14px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; }
.grid-1-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem; }
.kpi { display: flex; flex-direction: column; gap: .2rem; color: var(--text); }
a.kpi:hover { text-decoration: none; border-color: var(--brand); }
.kpi-label { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-weight: 500; font-size: .85rem; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .8rem; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .5rem .9rem; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
:root[data-theme="dark"] .btn-primary { color: #06212c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #06212c; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { border-color: var(--border); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }

.alert { border-radius: 8px; padding: .75rem 1rem; border: 1px solid transparent; }
.alert p:last-child { margin: 0; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.secret-value { display: inline-block; font-size: 1rem; padding: .35rem .6rem; cursor: copy; user-select: all; word-break: break-all; color: var(--text); }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); vertical-align: middle; }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: .2rem .7rem; background: var(--surface-2); }

/* --- Formularios -------------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: .9rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > span { font-weight: 500; font-size: .85rem; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="file"], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
input:disabled { opacity: .6; }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.check input, input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters .field { flex: 1 1 150px; }
.filters .field.grow { flex: 3 1 260px; }
.filters-actions { display: flex; gap: .5rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.inline-form input[type="text"] { flex: 1 1 140px; width: auto; }
.w-num { width: 80px !important; flex: none; }
.row-actions { display: flex; gap: .5rem; }
.table-filter { margin-bottom: .75rem; max-width: 320px; }

/* --- Tablas ------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table thead th a { color: inherit; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table.compact th, .table.compact td { padding: .4rem .5rem; }
.card:not(.flush) .table thead th { background: transparent; }
tr.is-muted td { opacity: .6; }
tr.editing td { background: var(--brand-soft); }

.spec { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.spec dt { color: var(--muted); }
.spec dd { margin: 0; overflow-wrap: anywhere; }

.diff { width: 100%; border-collapse: collapse; margin-top: .5rem; font-size: .9rem; }
.diff th, .diff td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.diff thead th { color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.diff tbody th { width: 22%; font-weight: 500; }
.diff-old { background: var(--danger-soft); color: var(--danger); width: 39%; }
.diff-new { background: var(--ok-soft); color: var(--ok); width: 39%; }

.change > header { display: flex; gap: .75rem; align-items: flex-start; }
.change details summary { cursor: pointer; color: var(--brand); font-weight: 500; margin-top: .5rem; font-size: .9rem; }
article.change + article.change { margin-top: 0; }
.tab-panel article.change { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.tab-panel article.change:last-child { border-bottom: 0; }
form#review-form { display: flex; flex-direction: column; gap: .75rem; }
.bulkbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .25rem .25rem; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feed li:last-child { border-bottom: 0; }
.feed li > div { flex: 1; min-width: 0; }
.feed time { white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: .45rem; background: var(--muted); }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-danger { background: var(--danger); } .dot-info { background: var(--brand); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; flex-wrap: wrap; }
.pager ul { list-style: none; display: flex; gap: .25rem; margin: 0; padding: 0; }
.pager a, .pager span:not(.muted) { display: inline-block; min-width: 32px; text-align: center; padding: .25rem .5rem; border-radius: 6px; border: 1px solid var(--border); color: var(--text); }
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager a:hover { background: var(--surface-2); text-decoration: none; }

.tabs { display: flex; flex-direction: column; gap: 0; }
.tab-list { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab-list button { background: none; border: 0; border-bottom: 2px solid transparent; padding: .6rem .9rem; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; display: inline-flex; gap: .4rem; align-items: center; }
.tab-list button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel h2 + .volumes, .tab-panel .volumes + h2 { margin-top: .25rem; }
.volumes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.volume-head { display: flex; gap: .4rem; align-items: baseline; margin-bottom: .3rem; }
meter { width: 100%; height: 10px; }

/* --- Gráficas SVG --------------------------------------------------------------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-lines { max-height: 340px; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .chart-label { fill: var(--text); }
.chart .chart-value { fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-bar { fill: var(--brand); }
.chart g:hover .chart-bar { fill: var(--brand-strong); }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--surface); stroke-width: 1.5; opacity: 0; transition: opacity .1s; }
.chart-lines:hover .chart-dot { opacity: 1; }
.chart-line.s1 { stroke: var(--c1); } .chart-dot.s1 { fill: var(--c1); }
.chart-line.s2 { stroke: var(--c2); } .chart-dot.s2 { fill: var(--c2); }
.chart-line.s3 { stroke: var(--c3); } .chart-dot.s3 { fill: var(--c3); }
.chart-line.s4 { stroke: var(--c4); } .chart-dot.s4 { fill: var(--c4); }
.chart-line.s5 { stroke: var(--c5); } .chart-dot.s5 { fill: var(--c5); }
.chart-line.s6 { stroke: var(--c6); } .chart-dot.s6 { fill: var(--c6); }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem 1rem; padding: 0; margin: .5rem 0 0; font-size: .85rem; }
.chart-legend li { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.s1 { background: var(--c1); } .swatch.s2 { background: var(--c2); } .swatch.s3 { background: var(--c3); }
.swatch.s4 { background: var(--c4); } .swatch.s5 { background: var(--c5); } .swatch.s6 { background: var(--c6); }

/* --- Login y errores ------------------------------------------------------------ */
.bare-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; gap: 1rem; }
.bare-main .alert { width: 100%; max-width: 380px; }
.login-card { width: 100%; max-width: 380px; padding: 2rem; }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { margin: .5rem 0 .1rem; }
.login-foot { font-size: .8rem; }
.error-page { max-width: 480px; margin: 3rem auto; text-align: center; padding: 2.5rem; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--brand); margin: 0; line-height: 1; }
.error-page h1 { margin: .5rem 0; }

/* --- Responsive ----------------------------------------------------------------- */
.only-mobile { display: none; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; margin-left: 0; }
  .hide-mobile { display: none; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: .5rem 1rem; }
  .topsearch + .icon-btn { margin-left: 0; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.6rem; }
  .spec { grid-template-columns: 1fr; gap: 0; }
  .spec dd { margin-bottom: .5rem; }
}
@media print {
  .sidebar, .topbar, .footer, .filters, .btn, .pager ul { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
}
