:root {
  --bg: #f5f6f3; --panel: #ffffff; --ink: #1d2320; --muted: #5d6862; --line: #dfe3dc;
  --brand: #2f5d3a; --brand-2: #467a52; --accent: #b0822a;
  --ok: #2e7d32; --warn: #b26a00; --err: #b3261e; --info: #1f5f8b;
  --radius: 6px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 20px 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #1f2e24; color: #d9e3dc; padding: 12px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { font-weight: 700; font-size: 16px; padding: 4px 16px 12px; color: #fff; letter-spacing: .3px; }
.side .logo span { color: #9fc5a8; font-weight: 400; }
.side nav a { display: block; color: #cfdad2; padding: 5px 16px; font-size: 13px; }
.side nav a:hover, .side nav a.on { background: #2c4133; color: #fff; text-decoration: none; }
.side nav .grp { text-transform: uppercase; font-size: 10.5px; letter-spacing: .8px; color: #86a08e; padding: 12px 16px 3px; }
.main { padding: 14px 22px 40px; min-width: 0; }
.topbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.topbar form { flex: 1; max-width: 420px; }
.topbar input[type=search] { width: 100%; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.menu-toggle { display: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl { background: var(--panel); }
.tbl th, .tbl td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); background: #f0f2ee; position: sticky; top: 0; }
.tbl tr:hover td { background: #fafbf8; }
.tbl td.n, .tbl th.n { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 600; background: #f6f7f4; }
.scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #e7ebe6; color: #33413a; white-space: nowrap; }
.b-ok, .b-OK, .b-COMPLETED, .b-CONFIRMED, .b-VALIDATED, .b-RECONCILED, .b-MATCHED, .b-OFFICIAL_RULES, .b-REVIEWED, .b-DONE, .b-OFFICIAL { background: #e0f0e1; color: var(--ok); }
.b-WARNING, .b-PENDING_CONFIRMATION, .b-PENDING_VALIDATION, .b-RULE_PENDING_VALIDATION, .b-SUGGESTED, .b-HIGH, .b-PLANNED, .b-PENDING_REVIEW, .b-IN_PROGRESS, .b-DECLARED, .b-RETRY, .b-DUE { background: #fcefd9; color: var(--warn); }
.b-ERROR, .b-OVERDUE, .b-CRITICAL, .b-OPEN, .b-FAILED, .b-RULE_SOURCE_REQUIRED, .b-DENIED, .b-VENCIDO { background: #fbe3e1; color: var(--err); }
.b-MEDIUM, .b-OPERATIONAL, .b-PAID, .b-INBOX, .b-RUNNING, .b-QUEUED { background: #e1ecf5; color: var(--info); }
.b-LOW, .b-IGNORED, .b-SUPERSEDED, .b-NOT_APPLICABLE, .b-DISABLED, .b-NOT_IMPLEMENTED, .b-NOT_AVAILABLE, .b-ESTIMATED { background: #eceeea; color: #6b726e; }
.b-AI_SUGGESTED { background: #efe4f7; color: #6a3d8a; }

.alert { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.alert.ok { background: #eef7ef; border-color: #b9dcbc; color: #1e5b22; }
.alert.err { background: #fdf0ef; border-color: #f0c3bf; color: #8a1d16; }
.alert.warn { background: #fff7e8; border-color: #f0d6a6; color: #7a4a00; }
.alert.info { background: #eef4fa; border-color: #c4d8ea; color: #184a6e; }

form.inline { display: inline; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
input, select, textarea { font: inherit; padding: 5px 7px; border: 1px solid #c9cfc6; border-radius: 4px; background: #fff; color: var(--ink); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #a9c9b1; border-color: var(--brand-2); }
textarea { width: 100%; min-height: 60px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid input:not([type=checkbox]), .form-grid select { width: 100%; }
.actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-block; background: var(--brand); color: #fff; border: 0; border-radius: 4px; padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn.sec { background: #e7ebe6; color: var(--ink); }
.btn.sec:hover { background: #d9dfd8; }
.btn.danger { background: var(--err); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.right { text-align: right; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 8px 0 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border: 1px solid transparent; border-bottom: 0; border-radius: 4px 4px 0 0; color: var(--muted); }
.tabs a.on { background: var(--panel); border-color: var(--line); color: var(--ink); margin-bottom: -1px; }
dl.kv { display: grid; grid-template-columns: 180px 1fr; gap: 3px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; }
dl.kv dd { margin: 0; }
.bar { height: 8px; background: #e7ebe6; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }
#map { height: 520px; border-radius: var(--radius); border: 1px solid var(--line); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal .d { background: var(--panel); border: 1px solid var(--line); min-height: 86px; padding: 3px 5px; font-size: 11.5px; }
.cal .d.out { background: #f1f2ef; color: #9aa19c; }
.cal .d.today { outline: 2px solid var(--accent); }
.cal .ev { display: block; margin-top: 2px; padding: 1px 4px; border-radius: 3px; background: #e1ecf5; color: #184a6e; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal .ev.OVERDUE, .cal .ev.CRITICAL { background: #fbe3e1; color: var(--err); }
.cal .ev.COMPLETED { background: #e0f0e1; color: var(--ok); }
.cal .hd { font-size: 11px; color: var(--muted); text-align: center; text-transform: uppercase; }
.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 14px; }
.timeline .it { position: relative; margin-bottom: 8px; }
.timeline .it::before { content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.login { max-width: 360px; margin: 10vh auto; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
pre.json { background: #f6f7f4; padding: 8px; border-radius: 4px; overflow: auto; font-size: 12px; max-height: 360px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 1000; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-toggle { display: inline-block; }
  .main { padding: 10px 12px 40px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .tbl th, .tbl td { padding: 6px; }
  .btn { padding: 9px 14px; }
  input, select, textarea { padding: 8px; font-size: 16px; }
  #map { height: 60vh; }
}
@media print { .side, .topbar, .actions, form { display: none !important; } .layout { display: block; } }
