:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e7ee;
  --brand: #1F3864; --brand-2: #2f5597; --accent: #d9e2f3; --danger: #c00000; --ok: #2e7d32;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 Arial, "Segoe UI", system-ui, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--brand-2); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 24px 0 10px; }
small { color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #fff; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 18px; }
.brand small { display: block; color: #c9d4ea; font-size: 11px; }
.brand.big small { color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--brand); font-weight: 700; display: grid; place-items: center; flex: none; }
.brand.big .logo { background: var(--brand); color: #fff; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: #e6ecf7; text-decoration: none; padding: 8px 10px; border-radius: 6px; }
nav a:hover { background: rgba(255,255,255,.08); }
nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; }
.me { margin-top: auto; padding: 10px 6px; border-top: 1px solid rgba(255,255,255,.15); display: flex; flex-direction: column; gap: 2px; }
.me small { color: #c9d4ea; }
.me .btn.link { color: #fff; padding: 4px 0; text-align: left; }
.main { padding: 22px 26px 60px; min-width: 0; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { border-left: 6px solid var(--c, var(--accent)); cursor: pointer; }
.kpi .n { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.three { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 700; background: #f8f9fb; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f8f9fb; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--panel); }
.table-wrap.tall { max-height: calc(100vh - 230px); }
tr.estado td:first-child { box-shadow: inset 6px 0 0 var(--c, transparent); }
tr.clickable { cursor: pointer; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--c, #eee); white-space: nowrap; }
.warn { color: var(--danger); font-weight: 700; }
.muted { color: var(--muted); }
.alert-list a { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.alert-list a:last-child { border: 0; }
.alert-list b { min-width: 28px; text-align: center; border-radius: 999px; padding: 0 8px; background: #eef1f6; }
.alert-list b.on { background: #ffc7ce; color: #9c0006; }
.bar { height: 8px; background: var(--brand-2); border-radius: 4px; min-width: 2px; }

/* forms */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 180px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; padding-bottom: 7px; }
input, select, textarea { font: inherit; color: var(--ink); border: 1px solid #cfd5df; border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db6e4; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: #555; }
textarea { min-height: 70px; resize: vertical; }
.form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form .span2 { grid-column: span 2; } .form .span4 { grid-column: 1 / -1; }
td input, td select { width: 100%; padding: 4px 6px; }
td input.n { text-align: right; }
.btn { font: inherit; border: 1px solid #cfd5df; background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f3f5f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px; color: var(--brand-2); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { margin: 0; }
.summary { grid-template-columns: repeat(5, minmax(0,1fr)); }
.summary .v { font-size: 18px; font-weight: 700; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #ffc7ce; color: #9c0006; white-space: nowrap; }
.hist { font-size: 13px; }
.hist li { padding: 6px 0; border-bottom: 1px solid var(--line); list-style: none; }
.hist ul { padding: 0; margin: 0; }
.hist .diff { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: pre-wrap; }
.error { color: var(--danger); min-height: 1em; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1F3864, #2f5597); }
.login-card { background: #fff; padding: 28px; border-radius: 12px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.login-card #loginLocal { display: flex; flex-direction: column; gap: 12px; }
.login-card .btn { justify-content: center; }

.toast { position: fixed; right: 18px; bottom: 18px; background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; max-width: 420px; z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .side .brand { padding: 0; } nav { flex-direction: row; flex-wrap: wrap; } .me { margin: 0; border: 0; flex-direction: row; align-items: center; gap: 8px; }
  .main { padding: 16px; }
  .form, .summary { grid-template-columns: 1fr 1fr; }
}

/* ajustes de detalle */
a.kpi { text-decoration: none; color: var(--ink); }
a.kpi:hover { border-color: #c5cfdf; }
td:first-child b { white-space: nowrap; }
td.mes { white-space: nowrap; }
select.st { min-width: 190px; }
.wide { grid-column: 1 / -1; }
.alert-list b { white-space: nowrap; align-self: center; }
table[data-l] td:first-child { width: 55%; }
table[data-l] td.actions, #tti td.actions { flex-wrap: nowrap; display: table-cell; white-space: nowrap; }
table[data-l] td.actions .btn + .btn { margin-left: 4px; }
.ajustes { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
table[data-l] input[data-k=valor] { min-width: 210px; }

.side .cli { color: #c9d4ea; margin: 0 6px 14px; }
.side .cli select { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.side .cli select option { color: #1d2433; }
