:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --text: #1d1d1b;
  --muted: #6d6c66;
  --border: #e3e1da;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --pos: #23744f;
  --neg: #b4382f;
  --warn: #a8650b;
  --inc: #2a78d6;
  --exp: #eb6834;
  --gain: #2a78d6;
  --loss: #e34948;
  --zero: #d6d4cd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1e1f1c;
    --surface-2: #272824;
    --text: #ecebe6;
    --muted: #a09f97;
    --border: #33342f;
    --accent: #7cc2a8;
    --accent-text: #10201a;
    --pos: #6fcb9c;
    --neg: #f08a7e;
    --warn: #e8b162;
    --inc: #3987e5;
    --exp: #d95926;
    --gain: #3987e5;
    --loss: #e66767;
    --zero: #4a4a46;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; display: flex; align-items: baseline; gap: .5rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; padding: 1.25rem .75rem;
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; gap: 1rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); padding: 0 .6rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: var(--text); padding: .45rem .6rem; border-radius: 7px;
  display: flex; justify-content: space-between; align-items: center;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--surface-2); font-weight: 600; }
.logout { margin-top: auto; padding: 0 .6rem; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 420px; margin: 3rem auto; }
.card.empty { text-align: center; padding: 2.5rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.venture { color: var(--text); border-top: 4px solid var(--c, var(--accent)); }
.venture:hover { text-decoration: none; border-color: var(--c); }
.venture dl { display: grid; grid-template-columns: 1fr auto; gap: .25rem; margin: 0; }
.venture dt { color: var(--muted); }
.venture dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid2 > .card, .stack > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 1rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.more { margin-left: auto; font-weight: 400; font-size: .85rem; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi small { color: var(--muted); font-size: .8rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .82rem; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.tag { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.tag i { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; }
.pill { display: inline-block; font-size: .72rem; font-weight: 500; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill-ok { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.badge { background: var(--neg); color: #fff; font-size: .7rem; font-weight: 600; border-radius: 99px; padding: 0 .45rem; min-width: 1.2rem; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

/* Forms */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form label, .filters label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .9rem; }
input, select, textarea, .output {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: .5rem .65rem; width: 100%;
}
input[type="color"] { padding: .2rem; height: 2.4rem; }
.output { background: var(--surface-2); font-variant-numeric: tabular-nums; color: var(--text); font-size: 15px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; }
.filters input[type="search"] { min-width: 200px; flex: 1; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented label { flex-direction: row; }
.segmented input { position: absolute; opacity: 0; width: 1px; }
.segmented span { padding: .45rem 1rem; cursor: pointer; color: var(--text); font-size: .9rem; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: .3rem; font: inherit; font-size: .9rem; font-weight: 500;
  padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--neg); }
.btn-sm { font-size: .8rem; padding: .3rem .7rem; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }
.link:hover { color: var(--text); }
.inline { display: inline; }

.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-ok { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 35%, transparent); background: color-mix(in srgb, var(--pos) 8%, transparent); }
.flash-error { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, transparent); background: color-mix(in srgb, var(--neg) 8%, transparent); }
.flash-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }

/* Tasks */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; }
.tabs a { padding: .35rem .8rem; border-radius: 7px; color: var(--muted); }
.tabs a.active { background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 500; }
.tasks { list-style: none; margin: 0; padding: 0; }
.tasks li { display: flex; gap: .75rem; align-items: flex-start; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.tasks li:last-child { border-bottom: 0; }
.tasks.compact li { padding: .45rem 0; }
.tasks li.done .task-body > a { color: var(--muted); text-decoration: line-through; }
.check {
  width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 1.5px solid var(--muted);
  background: none; cursor: pointer; color: var(--accent-text); font-size: .7rem; line-height: 1; padding: 0; margin-top: .15rem;
}
.check:hover { border-color: var(--accent); }
.done .check { background: var(--accent); border-color: var(--accent); }
.task-body { flex: 1; min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: .75rem; font-size: .8rem; color: var(--muted); }

/* Chart */
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin: -.25rem 0 .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.sw { width: .7rem; height: .7rem; border-radius: 2px; display: inline-block; }
.sw-inc, .bar-inc { background: var(--inc); }
.sw-exp, .bar-exp { background: var(--exp); }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: .4rem; height: 180px; }
.bar-group { display: flex; flex-direction: column; align-items: center; gap: .3rem; min-width: 0; }
.bar-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; border-bottom: 1px solid var(--border); }
.bar { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 0; }
.bar-label { font-size: .72rem; color: var(--muted); }

.qr { background: #fff; padding: 10px; width: max-content; border-radius: 8px; margin: .5rem 0; }
.steps { padding-left: 1.2rem; margin: .5rem 0; }

/* Responsive */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static; flex-direction: row; align-items: center;
    padding: .6rem 16px; border-right: 0; border-bottom: 1px solid var(--border); gap: .5rem; overflow-x: auto;
  }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a { white-space: nowrap; gap: .3rem; }
  .logout { margin: 0 0 0 auto; padding: 0; white-space: nowrap; }
  .main { padding: 1rem 16px 2rem; }
  .kpi strong { font-size: 1.2rem; }
  .bars { gap: .15rem; height: 140px; }
  .filters input, .filters select, .filters label { width: 100%; }
}

/* Barras horizontales divergentes (beneficio por frente) */
.hbars { display: flex; flex-direction: column; }
.hbar-row { display: grid; grid-template-columns: minmax(0, 9rem) 1fr auto; align-items: center; gap: .75rem; padding: .4rem 0; color: var(--text); border-bottom: 1px solid var(--border); }
.hbar-row:last-child { border-bottom: 0; }
.hbar-row:hover { text-decoration: none; background: var(--surface-2); }
.hbar-name { overflow: hidden; text-overflow: ellipsis; }
.hbar-track { position: relative; height: 14px; }
.hbar-track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--zero); }
.hbar { position: absolute; top: 0; bottom: 0; min-width: 2px; }
.hbar-pos { background: var(--gain); border-radius: 0 4px 4px 0; }
.hbar-neg { background: var(--loss); border-radius: 4px 0 0 4px; }
.hbar-val { min-width: 6.5rem; font-size: .9rem; }

.matrix td, .matrix th { padding: .45rem .4rem; font-size: .85rem; }
.table tr.selected td { background: var(--surface-2); }

.tooltip {
  position: fixed; z-index: 50; display: none; pointer-events: none; white-space: pre-line;
  background: var(--text); color: var(--bg); font-size: .8rem; line-height: 1.45;
  padding: .45rem .65rem; border-radius: 6px; max-width: 260px; font-variant-numeric: tabular-nums;
}
[data-tip] { cursor: default; }
a[data-tip] { cursor: pointer; }

@media (max-width: 720px) {
  .hbar-row { grid-template-columns: minmax(0, 6rem) 1fr auto; gap: .5rem; }
  .hbar-val { min-width: 0; font-size: .8rem; }
}

/* Fase 2: gastos fijos, hacienda, inventario */
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.form h3 { font-size: .85rem; margin: .4rem 0 -.3rem; color: var(--muted); font-weight: 600; }
.check-label { flex-direction: row !important; align-items: center; gap: .5rem !important; color: var(--text) !important; font-size: .9rem !important; }
.check-label input { width: auto; }
.checks { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem .8rem; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .4rem; }
.checks legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.calc { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; background: var(--surface-2); border-radius: 8px; padding: .7rem .9rem; font-size: .88rem; color: var(--muted); }
.calc strong { color: var(--text); font-variant-numeric: tabular-nums; margin-left: .25rem; }
.narrow-form { max-width: 560px; }
.table tfoot th { border-top: 2px solid var(--border); border-bottom: 0; color: var(--text); font-weight: 600; font-size: .9rem; padding-top: .6rem; }
.table tr.future td { color: var(--muted); }
.table tr.inactive td { opacity: .55; }
.notes { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .9rem; display: flex; flex-direction: column; gap: .4rem; }
@media (max-width: 900px) { .kpis-3 { grid-template-columns: 1fr 1fr; } }

/* Mini gestor: Hacienda y facturas */
.pill-bad { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.kpi strong.kpi-text { font-size: 1.05rem; }
details.quarter { padding: 0; }
details.quarter > summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; padding: 1rem 1.25rem; }
details.quarter > summary::-webkit-details-marker { display: none; }
details.quarter > summary::before { content: "\25B8"; color: var(--muted); }
details.quarter[open] > summary::before { content: "\25BE"; }
details.quarter > :not(summary) { margin-left: 1.25rem; margin-right: 1.25rem; }
details.quarter > p:last-child { margin-bottom: 1rem; }
.quarter-pills { margin-left: auto; display: inline-flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.quarter-body { margin-bottom: .5rem; }
.quarter-body h3 { font-size: .9rem; margin: 0 0 .5rem; }
.casillas td { padding: .35rem .5rem; font-size: .9rem; }
.casillas tr.total td { font-weight: 600; border-top: 2px solid var(--border); }
.box { display: inline-block; min-width: 1.9rem; text-align: center; font-size: .72rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 4px; padding: 0 .3rem; margin-right: .35rem; font-variant-numeric: tabular-nums; }
.filed { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.file-form { margin-top: .6rem; }
.file-form > summary { list-style: none; }
.file-form > summary::-webkit-details-marker { display: none; }
.file-form[open] > summary { margin-bottom: .6rem; }
.guide .notes { color: var(--text); }
.guide .notes ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.guide .steps li { margin-bottom: .35rem; }
.lines input { min-width: 5rem; }
.lines td:first-child input { min-width: 14rem; }
input.num { text-align: right; }
.form .check-label.only-gasto { align-self: end; padding-bottom: .5rem; }

/* Correo */
.badge-soft { background: var(--accent); color: var(--accent-text); }
.mail-list { padding: .6rem .5rem; }
.mail-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: 0 .5rem .6rem; border-bottom: 1px solid var(--border); }
.mails { list-style: none; margin: 0; padding: 0; }
.mails li { display: flex; align-items: center; gap: .6rem; padding: 0 .5rem; border-bottom: 1px solid var(--border); }
.mails li:last-child { border-bottom: 0; }
.mails li > input { width: auto; flex-shrink: 0; }
.mails li > a { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) auto; gap: .75rem; align-items: center; padding: .6rem 0; color: var(--text); }
.mails li > a:hover { text-decoration: none; }
.mails li:hover { background: var(--surface-2); }
.mail-from, .mail-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mails li.unread .mail-from, .mails li.unread .mail-subj { font-weight: 650; }
.mail-side { display: flex; align-items: center; gap: .5rem; justify-content: flex-end; }
.mail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.mail-subject { font-size: 1.15rem; margin-bottom: .5rem; }
.mail-meta { display: flex; flex-direction: column; gap: .2rem; padding-bottom: .8rem; margin-bottom: .9rem; border-bottom: 1px solid var(--border); }
.mail-body { font-size: .93rem; line-height: 1.6; overflow-wrap: anywhere; max-height: 75vh; overflow-y: auto; }
@media (max-width: 900px) { .mail-layout { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .mails li > a { grid-template-columns: minmax(0, 1fr) auto; }
  .mail-side .tag { display: none; }
  .mail-line { grid-column: 1 / -1; grid-row: 2; }
}
code.wrap { display: block; white-space: normal; overflow-wrap: anywhere; padding: .5rem .65rem; }

/* Redactar */
.compose textarea[name="body"] { font: inherit; line-height: 1.55; min-height: 16rem; }
.signature { margin: -.4rem 0 0; padding: .6rem .8rem; border-left: 3px solid var(--border); color: var(--muted); font: .88rem/1.5 inherit; font-family: inherit; white-space: pre-wrap; }
.signature[hidden] { display: none; }
.mail-reply { margin-top: 1.2rem; padding: .8rem 0 0 .9rem; border-top: 1px solid var(--border); border-left: 3px solid var(--accent); }
.mail-reply .mail-body { max-height: none; margin-top: .4rem; }

/* Firmas */
.sigbox { border: 1px solid var(--border); border-radius: 8px; padding: .7rem .9rem .9rem; margin: 0; display: flex; flex-direction: column; gap: .8rem; }
.sigbox legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.sig-preview { background: #fff; color: #1d1d1b; border-radius: 8px; padding: .4rem 1rem 1rem; }
.sig-preview .muted { color: #6d6c66; }
.signature { margin: -.4rem 0 0; padding: .2rem 1rem 1rem; background: #fff; border: 0; border-radius: 8px; white-space: normal; }

/* Correo con formato */
.mail-view-opts { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .7rem; }
.mail-frame { display: block; width: 100%; min-height: 220px; height: 60vh; border: 0; border-radius: 8px; background: #fff; }

/* Adjuntos y documentos */
.attachments { display: flex; flex-direction: column; gap: .4rem; margin: -.3rem 0 1rem; padding-bottom: .9rem; border-bottom: 1px solid var(--border); }
.att { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-size: .9rem; }
.att-name { margin-right: auto; overflow-wrap: anywhere; }
a.pill { text-decoration: none; }

.att-fixed { padding: .55rem .8rem; background: var(--surface-2); border-radius: 8px; font-size: .9rem; }
