:root {
  --bg: #f7f6f2; --panel: #ffffff; --fg: #1f1e1b; --muted: #6b6860; --line: #e4e1d8;
  --grid: #ecebe5; --axis: #c9c6bc; --ref: #9a978d;
  --ok: #2f7d4f; --warn: #a86a12; --bad: #b4372f;
  --c0: #2f6db5; --c1: #c2702b; --c2: #5b8a3c; --c3: #8a4fa3; --c4: #2a8c8c; --c5: #a8476b;
  --accent: #2f6db5; --radius: 10px; --notice: #fbf3e2;
  --serif: Georgia, "Times New Roman", serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --panel: #1f1f1c; --fg: #ecebe6; --muted: #a3a097; --line: #34332f;
    --grid: #2b2a27; --axis: #4a4943; --ref: #77756d;
    --ok: #6cc08b; --warn: #e0a24a; --bad: #ec7a6f;
    --c0: #6ea4e6; --c1: #e79a5a; --c2: #8fbf6c; --c3: #bb8ad0; --c4: #5cc2c2; --c5: #e07fa3; --accent: #6ea4e6; --notice: #2d2617;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); }
code { font-size: 12.5px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; display: flex; flex-direction: column; gap: 28px; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 32px; margin: 0; text-wrap: balance; }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
p { margin: 0; max-width: 78ch; }
.muted { color: var(--muted); font-size: 12.5px; }
.good { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
[hidden] { display: none !important; }

/* barra superior */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { max-width: 1200px; margin: 0 auto; padding: 8px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.brand { font-family: var(--serif); font-size: 18px; color: var(--fg); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.nav a.on { background: var(--bg); color: var(--fg); font-weight: 600; }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }

/* controles */
select, input[type=text], input[type=number], input[type=password], input[type=url], textarea, button {
  font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.head-text { display: flex; flex-direction: column; gap: 6px; flex: 1 1 320px; min-width: 0; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.sec { display: flex; flex-direction: column; gap: 10px; }
.sec > h2 { margin: 0; }
.notice { background: var(--notice); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; }

/* bloques de métricas con explicación */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile .k { color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: 6px; }
.tile .v { font-family: var(--serif); font-size: 28px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tile .i { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--muted); font-size: 10.5px; line-height: 14px; text-align: center; font-style: italic; font-family: var(--serif); }
.tile.has-info { cursor: help; }
.tile .info { display: none; position: absolute; left: -1px; right: -1px; top: calc(100% + 6px); z-index: 4; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0,0,0,.18); border-radius: 8px; padding: 9px 11px; font-size: 12.5px; line-height: 1.45; color: var(--fg); min-width: 220px; }
.tile.has-info:hover .info, .tile.has-info:focus .info, .tile.has-info:focus-within .info { display: block; }
.tile.has-info:hover, .tile.has-info:focus { border-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.bullets { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }

/* gráficos */
.chart { position: relative; min-height: 220px; }
.chart.small { min-height: 120px; }
.chart svg { display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11.5px; font-family: var(--sans); }
.chart .grid line { stroke: var(--grid); }
.chart .grid path, .chart .axis path { display: none; }
.chart .axis line { stroke: var(--axis); }
.chart .ref { stroke: var(--ref); stroke-dasharray: 4 3; }
.chart .ref.crit { stroke: var(--bad); }
.chart.photo { min-height: 300px; }
.tt { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.15); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 3; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* tablas */
.tblwrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.n, th.n { text-align: right; }
td.c { text-align: center; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
td.actions { display: flex; gap: 6px; }
td.actions button { padding: 4px 8px; font-size: 12px; }
.w-name { width: 130px; } .w-num { width: 110px; }

.recs { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.recs li { display: grid; grid-template-columns: 28px 1fr; gap: 8px; }
.recs .num { font-family: var(--serif); font-size: 20px; color: var(--muted); line-height: 1.2; }
.recs b { font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); }
details p { margin-top: 6px; }

/* administración */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 20px; text-align: center; color: var(--muted); cursor: pointer; display: block; }
.drop.over { border-color: var(--accent); color: var(--fg); }
.report { font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 12px 16px; align-items: start; }
.form label, .tagform label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form label.check, .tagform label.check { flex-direction: row; align-items: center; gap: 8px; }
.form .wide, .tagform .wide { grid-column: 1 / -1; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.empty { text-align: center; padding: 60px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; align-items: center; }

/* inicio de sesión */
.login { max-width: 360px; margin: 10vh auto 0; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

/* ficha de una operación */
.modal { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--fg); width: min(1000px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.modal-head h2 { margin: 0; }
.close { font-size: 20px; line-height: 1; padding: 4px 10px; }
.tagform { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px 16px; }
.tagform fieldset { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
.tagform legend { font-size: 13px; padding: 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; }
.chip:has(input:checked) { border-color: var(--accent); background: var(--bg); }
