/* CDRA CRM — layout: sticky top bar, one scrolling column of cards, drill-down drawer on the right. */
:root {
  --teal: #479CB1;
  --teal-dark: #2F7F93;
  --teal-soft: #E7F3F6;
  --accent: #7FBACA;
  --ink: #23292B;
  --ink-2: #4E585C;
  --muted: #76848A;
  --line: #E0E6E8;
  --bg: #F4F7F8;
  --panel: #FFFFFF;
  --bar-muted: #C9D4D8;
  --ok: #2F7D4F;
  --warn: #A76A12;
  --bad: #B83A2E;
  --font-display: "Roboto Condensed", "Arial Narrow", sans-serif;
  --font-body: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 50, .06), 0 2px 8px rgba(20, 40, 50, .04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font-body); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; margin: 0; text-wrap: balance; color: var(--ink); }
.num { font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1320px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-left)); display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; }
.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; }
.brand b { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--teal); letter-spacing: .02em; }
.brand span { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-family: var(--font-display); font-size: 15px; }
.tabs button:hover { background: var(--teal-soft); }
.tabs button[aria-selected="true"] { color: var(--teal-dark); background: var(--teal-soft); font-weight: 600; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; background: var(--bg); }
.seg button { border: 0; background: none; border-radius: 999px; padding: 5px 12px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--teal); color: #fff; }
select, input[type="search"], input[type="text"], input[type="password"] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--panel); min-width: 0; }
.btn { border: 1px solid var(--teal); background: var(--teal); color: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-family: var(--font-display); font-size: 15px; }
.btn:hover { background: var(--teal-dark); border-color: var(--teal-dark); box-shadow: 0 0 12px rgba(0, 0, 0, .17); }
.btn.ghost { background: transparent; color: var(--teal-dark); }
.btn.ghost:hover { background: var(--teal-soft); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.link { border: 0; background: none; color: var(--teal-dark); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- page */
main { max-width: 1320px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-left)) 48px; display: flex; flex-direction: column; gap: 28px; }
.view { display: flex; flex-direction: column; gap: 28px; }
.lead h1 { font-size: 28px; }
.lead p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; max-width: 80ch; }
.lead p b { color: var(--ink); font-weight: 500; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section > h2 { font-size: 21px; }
.section > p { margin: 0; color: var(--ink-2); max-width: 80ch; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card h3 { font-size: 17px; }
.note { color: var(--muted); font-size: 12.5px; margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; width: 16px; vertical-align: 3px; }
.legend i.dash { height: 0; width: 16px; border-top: 2px dashed var(--ink-2); border-radius: 0; vertical-align: 3px; }
.chart { width: 100%; height: 300px; }
.chart.short { height: 250px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; text-align: left; cursor: pointer; min-width: 0; }
.tile:hover { border-color: var(--accent); }
.tile .l { font-size: 12.5px; color: var(--muted); }
.tile .v { font-family: var(--font-display); font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .s { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- clickable bar rows */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bgroup { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 2px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-radius: 6px; cursor: pointer; border: 0; background: none; text-align: left; }
.bgroup:hover { background: var(--teal-soft); color: var(--teal-dark); }
.brow { display: grid; grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 6px; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.brow:hover { background: var(--teal-soft); }
.brow .lbl { overflow-wrap: anywhere; }
.track { height: 14px; position: relative; }
.track .p, .track .a { position: absolute; inset: 0 auto 0 0; border-radius: 4px; min-width: 2px; }
.track .p { background: var(--bar-muted); }
.track .a { background: var(--teal); }
.brow .t { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-size: 12.5px; }
.brow .t b { color: var(--ink); font-weight: 500; }

/* ---------- tables */
.tablewrap { overflow: auto; max-width: 100%; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-weight: 500; color: var(--muted); padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--panel); z-index: 1; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--teal-dark); }
table.data th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
table.data th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }
table.data td { padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data .n { text-align: right; white-space: nowrap; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover td { background: var(--teal-soft); }
table.data tr.current td { background: #F1F6F7; font-weight: 500; }
table.data td.cell-click { cursor: pointer; color: var(--teal-dark); text-decoration: underline dotted; text-underline-offset: 3px; }
table.data td.wrap { min-width: 16rem; max-width: 32rem; white-space: normal; }
table.data tfoot td { font-weight: 500; border-top: 1px solid var(--line); border-bottom: 0; }
.chip { display: inline-block; border: 1px solid currentColor; border-radius: 999px; padding: 0 8px; font-size: 12px; white-space: nowrap; }
.chip.m { color: var(--muted); }

/* ---------- drill-down drawer */
.drawer-back { position: fixed; inset: 0; background: rgba(20, 35, 40, .28); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(1100px, 100%); background: var(--panel); z-index: 41; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); padding-bottom: env(safe-area-inset-bottom); }
.drawer-head { padding: 16px max(18px, env(safe-area-inset-right)) 12px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.drawer-title { display: flex; align-items: flex-start; gap: 12px; }
.drawer-title h2 { font-size: 21px; flex: 1; }
.drawer-sub { color: var(--muted); font-size: 13px; }
.drawer-tot { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); }
.drawer-tot b { color: var(--ink); font-weight: 500; }
.drawer-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.drawer-tools input[type="search"] { flex: 1 1 14rem; }
.drawer-body { flex: 1; overflow: auto; padding: 0 max(18px, env(safe-area-inset-right)) 18px 18px; }
.close { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.close:hover { color: var(--ink); }
.detail { background: var(--bg); border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 6px 18px; font-size: 13px; }
.detail dt { color: var(--muted); font-size: 12px; }
.detail dd { margin: 0 0 4px; overflow-wrap: anywhere; }

/* ---------- forms: explorer filters, import */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 10px; align-items: end; }
.filters label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.drop { border: 2px dashed var(--accent); border-radius: var(--radius); padding: 28px 16px; text-align: center; color: var(--ink-2); background: var(--teal-soft); cursor: pointer; }
.drop.over { border-color: var(--teal); background: #D8EDF2; }
.drop b { color: var(--teal-dark); }
.editor { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 10px; align-items: end; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.editor label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.editor .ancho { grid-column: 1 / -1; }
.editor.objetivos { grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); }
input[type="number"], input[type="date"], textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--panel); min-width: 0; font: inherit; color: inherit; }
textarea { resize: vertical; }
.result { border-left: 4px solid var(--teal); background: var(--teal-soft); padding: 10px 14px; border-radius: 6px; }
.result.error { border-color: var(--bad); background: #FBEDEB; color: var(--bad); }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: calc(100vw - 32px); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 26px; color: var(--teal); }
.login .error { color: var(--bad); min-height: 1.2em; margin: 0; }

@media (max-width: 640px) {
  .lead h1 { font-size: 23px; }
  .tile .v { font-size: 24px; }
  .chart { height: 260px; }
  .brow { grid-template-columns: minmax(6rem, 9rem) minmax(0, 1fr) auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide .18s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
