/* GENERGY MRV - estilos. Tokens de color segun la paleta de referencia validada (claro y oscuro). */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --surface-hover: #efeee9;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --track: #cde2fb;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --surface-hover: #2a2a28;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --series-1: #3987e5;
    --series-2: #d95926;
    --accent: #3987e5;
    --track: #184f95;
    --good-text: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-hover: #2a2a28;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --series-1: #3987e5;
  --series-2: #d95926;
  --accent: #3987e5;
  --track: #184f95;
  --good-text: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* --- Barra superior ------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 5px 7px 4px; background: var(--surface); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; }
.brand-name { font-weight: 650; letter-spacing: 0.02em; }
.brand-env { font-size: 11px; color: var(--ink-2); border: 1px solid var(--border-strong); border-radius: 999px; padding: 0 8px; }
.tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  color: var(--ink-2); padding: 8px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap;
}
.tabs a:hover { background: var(--surface-hover); text-decoration: none; color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.theme-toggle {
  border: 1px solid var(--border-strong); background: transparent; color: var(--ink);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.theme-toggle:hover { background: var(--surface-hover); }
.user-label { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.user-label:empty { display: none; }
.logout {
  border: 1px solid var(--border-strong); background: transparent; color: var(--ink);
  height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px;
}
.logout:hover { background: var(--surface-hover); }
.logout[hidden] { display: none; }

/* --- Estructura ------------------------------------------------------------ */
.view { max-width: 1280px; margin: 0 auto; padding: 24px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .view { padding: 16px; } .topbar { padding: 0 16px; gap: 12px; } .brand-env { display: none; } }
@media (max-width: 560px) {
  .brand-name { display: none; }
  .user-label { display: none; }
  .hero-value { font-size: 40px; }
  .hero-value .unit { font-size: 18px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .filters > .field { flex: 1 1 140px; }
  .filters select { width: 100%; }
  .card { padding: 16px; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.section-title { margin: 28px 0 12px; }
.muted { color: var(--muted); }
.secondary { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.empty { color: var(--ink-2); padding: 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); }

/* --- Formularios ----------------------------------------------------------- */
label.field { display: grid; gap: 6px; font-weight: 500; font-size: 13px; }
select, input[type="month"], input[type="text"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
select:hover, input:hover { border-color: var(--muted); }
.btn {
  font: inherit; font-weight: 550; cursor: pointer; border-radius: 8px; padding: 8px 14px; min-height: 36px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 4px 10px; min-height: 28px; font-size: 13px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 0; min-height: 0; }
.btn.link:hover { text-decoration: underline; background: none; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 22px 16px;
  text-align: center; color: var(--ink-2); cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.over { background: var(--surface-2); border-color: var(--accent); }
.dropzone strong { color: var(--ink); }
.dropzone input { display: none; }
.file-list { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; text-align: left; }
.file-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ink); }

.columns-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chip {
  font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border);
}
.chip.required { color: var(--ink); font-weight: 600; }

/* --- Permisos por rol (data-role en <html>; la API controla igual) -------------- */
:root[data-role="lectura"] .needs-load { display: none !important; }
:root[data-role]:not([data-role="admin"]) .admin-only { display: none !important; }

/* --- Configuracion: subnavegacion, dialogos y formularios --------------------- */
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin: -4px 0 18px; border-bottom: 1px solid var(--border); }
.subnav a { color: var(--ink-2); padding: 6px 10px 8px; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
table.data tr.inactive td { color: var(--muted); }
table.data td .mono, table.data td.mono { white-space: nowrap; }
ul.changes { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }

dialog.modal {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); color: var(--ink);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}
dialog.modal::backdrop { background: rgba(11, 11, 11, 0.45); }
dialog.modal form { display: grid; gap: 16px; padding: 20px; }
.modal-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-field { display: grid; gap: 4px; align-content: start; min-width: 0; }
.form-field.wide { grid-column: 1 / -1; }
.form-field > label { font-weight: 500; font-size: 13px; }
.form-field .req { color: var(--critical); }
.form-field.check > label { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; cursor: pointer; }
.form-field.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.form-field input[type="text"], .form-field input[type="date"], .form-field select, .form-field textarea { width: 100%; }
input[type="date"] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 10px; min-height: 36px;
}
input[type="file"] { font: inherit; font-size: 13px; color: var(--ink-2); }
.notice { border-radius: var(--radius); border: 1px solid var(--border); padding: 10px 14px; margin-bottom: 16px; background: var(--surface-2); }
fieldset.form-field { border: 0; padding: 0; margin: 0; }
fieldset.form-field legend { font-weight: 500; font-size: 13px; padding: 0; margin-bottom: 4px; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; }
.checks label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13.5px; }
.checks input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.checks[aria-invalid="true"] { outline: 1px solid var(--critical); border-radius: 6px; }
@media (max-width: 560px) { .checks { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.field-msg { font-size: 12px; color: var(--muted); min-height: 0; }
.field-msg:empty { display: none; }
.field-msg.error { color: var(--critical); font-weight: 550; }
[aria-invalid="true"] { border-color: var(--critical) !important; }
.form-error { color: var(--critical); font-weight: 550; font-size: 13px; }
.form-error:empty { display: none; }
textarea {
  font: inherit; color: var(--ink); background: var(--surface); resize: vertical;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px;
}
input.upper { text-transform: uppercase; }
input:disabled, select:disabled { opacity: 0.6; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } dialog.modal form { padding: 16px; } }

/* --- Estados (icono de color + texto, nunca solo color) ---------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; white-space: nowrap; color: var(--ink); }
.badge .ico {
  width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 800; color: #fff; flex: none;
}
.badge.good .ico { background: var(--good); }
.badge.critical .ico { background: var(--critical); }
.badge.warning .ico { background: var(--warning); color: #0b0b0b; }
.badge.serious .ico { background: var(--serious); }
.badge.info .ico { background: var(--muted); }
.badge.neutral .ico { background: var(--axis); color: var(--ink); }

.result { border-radius: var(--radius); border: 1px solid var(--border); padding: 14px 16px; margin-top: 14px; background: var(--surface-2); }
.result h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.result ul { margin: 6px 0 0; padding-left: 18px; }
.progress { color: var(--ink-2); font-size: 13px; margin-top: 10px; min-height: 20px; }

/* --- Tablas ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--ink-2); background: var(--surface-2);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--surface-hover); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.superseded td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--axis); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* --- Dashboard ------------------------------------------------------------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 20px; }
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 28px; margin-bottom: 16px; }
.hero-label { color: var(--ink-2); font-weight: 500; }
.hero-value { font-size: 52px; line-height: 1.05; font-weight: 650; letter-spacing: -0.02em; }
.hero-value .unit { font-size: 22px; font-weight: 500; color: var(--ink-2); margin-left: 6px; letter-spacing: 0; }
.hero-sub { color: var(--ink-2); padding-bottom: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 24px; font-weight: 620; margin-top: 2px; }
.tile-value .unit { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.tile-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile-badges { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.refetching { opacity: 0.55; transition: opacity 0.15s; }

details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--ink-2); font-size: 13px; padding: 4px 0 10px; }
details.more summary:hover { color: var(--ink); }

.meter { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

/* --- Graficos ---------------------------------------------------------------- */
.chart-card { margin: 0; }
.chart-body { position: relative; }
.chart-body svg { display: block; width: 100%; overflow: visible; }
.chart-body svg text { fill: var(--muted); font: 11.5px var(--font); font-variant-numeric: tabular-nums; }
.chart-body svg text.label { fill: var(--ink-2); font-size: 12px; }
.chart-body svg text.label-strong { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart-body .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-body .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart-body .hit { fill: transparent; cursor: default; }
.chart-body .hit:focus-visible { outline: none; }
.chart-body .hit:focus-visible + .focus-ring, .chart-body .focus-ring.on { stroke: var(--accent); stroke-width: 2; fill: none; }
.chart-body .crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.chart-body .bar { transition: opacity 0.1s; }
.chart-body .bar.dim { opacity: 0.75; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 12.5px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .key-line { width: 14px; height: 2px; border-radius: 2px; }
.legend .key-dot { width: 8px; height: 8px; border-radius: 50%; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 140px; max-width: 260px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12); padding: 8px 10px; font-size: 12.5px; display: none;
}
.tooltip .tt-title { color: var(--ink-2); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row .tt-name { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .tt-row strong { font-variant-numeric: tabular-nums; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 2px; }
.tooltip .tt-note { color: var(--ink-2); margin-top: 4px; border-top: 1px solid var(--border); padding-top: 4px; }
.chart-table { display: none; }
.chart-card.show-table .chart-table { display: block; }
.chart-card.show-table .chart-body, .chart-card.show-table .legend { display: none; }

@media (forced-colors: active) {
  .badge .ico { forced-color-adjust: none; border: 1px solid CanvasText; }
}
