:root {
  --bg: #f4f5f7;
  --surface: #fcfcfb;
  --text: #15181d;
  --muted: #5d6673;
  --line: #e2e5ea;
  --soft: #eef0f3;
  --accent: #0f9d6b;
  --accent-text: #ffffff;
  --warn: #a35a00;
  --warn-bg: #fff4e5;
  --bad: #c0262d;
  --bad-bg: #fdeeee;
  --good: #0f7d55;
  --good-bg: #e7f7ef;
  --input: #ffffff;
  --radius: 12px;
  /* Categorías: paleta categórica validada (orden fijo) */
  --c-infra: #2a78d6;
  --c-personal: #eb6834;
  --c-herramientas: #1baf7a;
  --c-familia: #eda100;
  --c-salud: #e87ba4;
  --c-ia: #6250d6;
  --c-other: #9aa3ae;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #1a1a19;
    --text: #f0efec;
    --muted: #a5adb7;
    --line: #2a2f37;
    --soft: #23272d;
    --accent: #34d399;
    --accent-text: #08130e;
    --warn: #f5a524;
    --warn-bg: #2d2313;
    --bad: #f87171;
    --bad-bg: #2f1818;
    --good: #34d399;
    --good-bg: #12261d;
    --input: #13161a;
    --c-infra: #3987e5;
    --c-personal: #d95926;
    --c-herramientas: #199e70;
    --c-familia: #c98500;
    --c-salud: #d55181;
    --c-ia: #9085e9;
    --c-other: #6b7480;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.num { font-variant-numeric: tabular-nums; }

.top {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 20px 24px 8px; max-width: 1280px; margin: 0 auto;
}
.top p { margin: 4px 0 0; font-size: 13px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 1280px; margin: 0 auto; padding: 8px 24px 120px; display: grid; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  font: inherit; font-size: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 13px; padding: 5px 10px; }
.btn.icon { padding: 2px 8px; font-size: 14px; color: var(--muted); background: transparent; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--input); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 7px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi.bad .value { color: var(--bad); }
.kpi.good .value { color: var(--good); }

/* Alertas */
.alert { display: flex; gap: 10px; align-items: flex-start; border-left: 4px solid var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; }
.alert .icon { font-weight: 700; color: var(--bad); }
.alert strong { display: block; }
.alert span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.alert.warn { border-color: var(--warn); background: var(--warn-bg); }
.alert.warn .icon { color: var(--warn); }

/* Segmented control */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { font: inherit; font-size: 13px; padding: 5px 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.seg-btn.on { background: var(--soft); color: var(--text); font-weight: 600; }

/* Barras horizontales */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 190px) 1fr auto; gap: 10px; align-items: center; }
.hbar .name { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.hbar .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 14px; border-radius: 0 4px 4px 0; position: relative; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 3px; }
.hbar .amt { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar .extra { grid-column: 2 / 4; font-size: 12px; color: var(--muted); margin-top: -6px; }
.total-line { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; font-weight: 600; }
@media (max-width: 520px) { .hbar { grid-template-columns: 1fr auto; } .hbar .track { grid-column: 1 / 3; grid-row: 2; } .hbar .extra { grid-column: 1 / 3; margin-top: 0; } }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.cat-infra { --cat: var(--c-infra); }
.cat-personal { --cat: var(--c-personal); }
.cat-herramientas { --cat: var(--c-herramientas); }
.cat-familia { --cat: var(--c-familia); }
.cat-salud { --cat: var(--c-salud); }
.cat-ia { --cat: var(--c-ia); }
.cat-other { --cat: var(--c-other); }
.dot, .fill, .stripe { background: var(--cat, var(--c-other)); }

/* Calendario */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { font-size: 11px; color: var(--muted); text-align: center; text-transform: uppercase; letter-spacing: .04em; padding-bottom: 2px; }
.cal .day { border: 1px solid var(--line); border-radius: 8px; min-height: 52px; padding: 4px 5px; font-size: 12px; background: var(--surface); cursor: default; text-align: left; font: inherit; color: inherit; }
.cal .day.has { cursor: pointer; }
.cal .day.has:hover, .cal .day.sel { border-color: var(--muted); }
.cal .day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .day.out { background: transparent; border-style: dashed; opacity: .45; }
.cal .day .n { font-size: 12px; color: var(--muted); }
.cal .day .dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.cal .day .dots .dot { width: 9px; height: 9px; box-shadow: 0 0 0 2px var(--surface); }
.cal .day .sum { font-size: 11px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.cal-detail { margin-top: 10px; font-size: 14px; min-height: 1.4em; }
.cal-detail ul { list-style: none; padding: 0; margin: 0; }
.cal-detail li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.cal-detail li .amt { margin-left: auto; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Saldos */
.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.bal { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 12px 16px; position: relative; overflow: hidden; display: grid; gap: 6px; }
.bal .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.bal .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bal .name-in { font-weight: 600; border-color: transparent; background: transparent; padding: 2px 4px; margin-left: -4px; width: 100%; }
.bal .name-in:hover { border-color: var(--line); }
.bal .cat-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.bal .big { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.bal .big small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.gauge { position: relative; height: 10px; background: var(--soft); border-radius: 0 4px 4px 0; }
.gauge .fill { height: 100%; border-radius: 0 4px 4px 0; }
.gauge .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .7; }
.bal .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.bal .edit { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.bal .edit label { font-size: 11px; color: var(--muted); display: grid; gap: 2px; }
.bal .edit input, .bal .edit select { width: 100%; text-align: left; }
.bal .bal-note { font-size: 12px; color: var(--muted); }
.spark { width: 100%; height: 28px; display: block; }
.spark polyline { fill: none; stroke: var(--cat, var(--c-other)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.idle { background: var(--soft); color: var(--muted); }

/* Suscripciones */
.group { margin-bottom: 18px; }
.group:last-child { margin-bottom: 0; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 2px solid var(--cat, var(--line)); margin-bottom: 4px; }
.group-head h3 { font-size: 14px; margin: 0; }
.group-head .tot { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 5px; white-space: nowrap; }
.table td { padding: 4px 5px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tr.off td { opacity: .5; }
.table input, .table select { width: 100%; }
.table select { min-width: 82px; }
.table select.sel-cycle { min-width: 104px; }
.table select.sel-biz { min-width: 118px; }
.table select.sel-cat { min-width: 190px; }
.table input.num { text-align: right; }
.w-xs { width: 56px; min-width: 56px; }
.w-sm { width: 100px; min-width: 100px; }
.w-md { width: 140px; min-width: 140px; }
.w-name { min-width: 190px; }
.w-note { min-width: 200px; }
.verif { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* Notas */
.note-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.note-form #note-text { flex: 1; min-width: 200px; }
.notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) { .notes { grid-template-columns: 1fr; } }
.notes h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.note { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start; }
.note.done { opacity: .55; }
.note.done .text { text-decoration: line-through; }
.note .text { font-size: 14px; overflow-wrap: anywhere; }
.note .date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.note .reply { grid-column: 2 / 4; font-size: 13px; background: var(--soft); border-radius: 6px; padding: 6px 8px; }
.note.due { border-color: var(--warn); }
.empty-col { font-size: 13px; color: var(--muted); }

/* Servicios */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.tile .t-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile .t-head strong { font-size: 14px; }
.tile .t-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.tile.ok { border-left: 4px solid var(--good); }
.tile.bad { border-left: 4px solid var(--bad); }
.tile.idle { border-left: 4px solid var(--line); }
.tile details { font-size: 12px; color: var(--muted); }
.tile details ul { margin: 4px 0 0; padding-left: 16px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--muted); min-width: 110px; }

.settings { margin-top: 14px; }
.settings summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.field { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
.field textarea { display: block; width: 100%; margin-top: 4px; resize: vertical; }

.preview { white-space: pre-wrap; background: var(--soft); border-radius: 8px; padding: 12px; font: 13px/1.5 ui-monospace, Menlo, monospace; margin: 12px 0 8px; }

.savebar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px 10px 16px; box-shadow: 0 8px 30px rgba(0,0,0,.18); z-index: 10;
  max-width: calc(100% - 32px);
}
.toast { position: fixed; top: 16px; right: 16px; z-index: 20; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 14px; max-width: min(420px, calc(100% - 32px)); }
.toast.bad { background: var(--bad); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 340px; display: grid; gap: 10px; }
.login-card h1 { margin-bottom: 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input { padding: 9px 10px; }

@media (max-width: 600px) {
  .top { padding: 16px 16px 4px; }
  main { padding: 8px 16px 120px; }
  .card { padding: 14px; }
  .kpi .value { font-size: 21px; }
  .cal .day { min-height: 44px; padding: 3px; }
  .cal .day .sum { display: none; }
}
