:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1f2a24;
  --muted: #69736b;
  --line: #e3e1d8;
  --accent: #166558;
  --accent-ink: #ffffff;
  --accent-soft: #e9f1ec;
  --side: #102624;
  --side-ink: #cfd9d2;
  --side-active: #1d3c38;
  --warn: #a35f00;
  --warn-soft: #fbefdc;
  --danger: #b0372f;
  --danger-soft: #f8e3e1;
  --info: #2b5a85;
  --info-soft: #e1ebf5;
  --income: #166558;
  --expense: #c98a3d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23, 34, 28, .06), 0 4px 16px rgba(23, 34, 28, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121814; --surface: #1a221d; --surface-2: #1f2822; --ink: #e6ebe7; --muted: #98a39b; --line: #2c3730;
    --accent: #5fae86; --accent-ink: #0f1712; --accent-soft: #213a2c; --side: #0d120f; --side-ink: #b8c4bc; --side-active: #1e2a23;
    --warn: #e0a24c; --warn-soft: #3a2c15; --danger: #e57a72; --danger-soft: #3d2120; --info: #7fb0dc; --info-soft: #1c2b3a;
    --income: #5fae86; --expense: #e0a24c; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.boot { padding: 40px; color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
label.btn { flex-direction: row; color: inherit; }
label.btn.primary { color: var(--accent-ink); }
.mt-s { margin-top: 6px; }
.mono {font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .8rem; word-break: break-all; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.brand img { width: 28px; height: 28px; }
.brand-mark { display: grid; place-items: center; flex: none; background: var(--accent); color: #fff; width: 36px; height: 36px; border-radius: 10px; font-family: Georgia, "Times New Roman", serif; font-size: 23px; font-weight: 400; }
.side .brand-mark { background: #2b8a77; }
.brand small { display: block; font-size: .72rem; font-weight: 400; letter-spacing: .3px; opacity: .8; margin-top: 1px; }
.brand .word { letter-spacing: 1.5px; }
.side a { color: var(--side-ink); padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; font-size: .93rem; }
.side a:hover { background: var(--side-active); text-decoration: none; }
.side a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.side .badge { margin-left: auto; background: #3c5a48; color: #fff; border-radius: 99px; font-size: .72rem; padding: 1px 7px; }
.side .spacer { flex: 1; }
.side .who { border-top: 1px solid #2a3a30; padding: 12px 10px 0; font-size: .82rem; }
.side .who b { color: #fff; display: block; }
.main { padding: 26px 32px 60px; max-width: 1240px; width: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.menu-btn { display: none; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.c2 { grid-template-columns: 2fr 1fr; }
.grid.h2 { grid-template-columns: 1fr 1fr; }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.pos { color: var(--income); }
.neg { color: var(--danger); }

.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; font-size: .9rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: .82rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chip { display: inline-block; border-radius: 99px; padding: 2px 9px; font-size: .75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: .92rem; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--ink); border-color: var(--accent); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .3px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }

form .row, form.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 12px; align-items: end; }
form.row.card { margin-bottom: 0; }
label > .btn { align-self: flex-start; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input, select, textarea { font: inherit; font-size: .92rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
.lines-table input, .lines-table select { padding: 6px 8px; }
.lines-table td { padding: 5px 6px; }
.lines-table { table-layout: fixed; min-width: 620px; }
#inv .lines-table { min-width: 860px; }
#inv .lines-table th:nth-child(2) { width: 76px; }
#inv .lines-table th:nth-child(3) { width: 104px; }
#inv .lines-table th:nth-child(4) { width: 92px; }
#inv .lines-table th:nth-child(5) { width: 128px; }
#inv .lines-table th:nth-child(6) { width: 128px; }
#inv .lines-table th:nth-child(7) { width: 104px; }
#inv .lines-table th:last-child { width: 44px; }
.le.lines-table th:nth-child(2) { width: 80px; }
.le.lines-table th:nth-child(3) { width: 110px; }
.le.lines-table th:nth-child(4) { width: 92px; }
.le.lines-table th:nth-child(5) { width: 110px; }
.le.lines-table th:last-child { width: 44px; }
#me .lines-table th:nth-child(1) { width: 140px; }
#me .lines-table th:nth-child(3), #me .lines-table th:nth-child(4) { width: 130px; }
#me .lines-table th:last-child { width: 48px; }
.totals { margin-left: auto; width: min(340px, 100%); }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.hint { font-size: .8rem; color: var(--accent); margin-top: 2px; }
.notice { border-radius: 8px; padding: 10px 14px; font-size: .88rem; background: var(--info-soft); color: var(--info); margin-bottom: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

.list { display: flex; flex-direction: column; }
.list a, .list .item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); color: var(--ink); }
.list a:last-child, .list .item:last-child { border-bottom: 0; }
.list a:hover { text-decoration: none; background: var(--surface-2); }

.entry { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
.entry-head { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.entry-head .desc { flex: 1; min-width: 200px; font-weight: 600; }
.entry-head .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.entry table td, .entry table th { padding: 6px 14px; }
.entry table { table-layout: fixed; }
.entry table td:first-child { width: 90px; }
.entry table td:nth-child(3), .entry table td:nth-child(4) { width: 150px; }
.entry.reversed { opacity: .6; }

.chart { width: 100%; height: 220px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .li { background: var(--income); }
.legend .le { background: var(--expense); }
.bar-i { fill: var(--income); }
.forecast-line { fill: none; stroke: var(--info); stroke-width: 2.5; }
.legend .lb { background: var(--info); }
.bar-e { fill: var(--expense); }
.grid-line { stroke: var(--line); }

table.annual td.indent { padding-left: 24px; }
table.annual tr.sec td { border-top: 1px solid var(--line); background: var(--surface-2); }
table.annual tr.total td { border-top: 2px solid var(--ink); }
.doc table.annual tr.sec td { background: #f6f5f0; }
.doc table.annual tr.total td { border-top-color: #1f2a24; }
ol.small li { margin-bottom: 6px; }
details > summary { cursor: pointer; padding: 8px 0; }
pre.mono { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }
.vf-legend { letter-spacing: .5px; color: #1f2a24; }
#multi .item input[type=number] { width: 120px; flex: none; }
#multi label.check { flex: 1; min-width: 0; }
.score {font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.suggestion { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.suggestion .grow { flex: 1; }

.doc { background: #fff; color: #1f2a24; border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 40px; }
.doc .head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.doc h2 { font-size: 1.6rem; }
.doc table th { color: #69736b; }
.doc .vf { margin-top: 28px; border-top: 1px dashed #c9c6bb; padding-top: 14px; font-size: .8rem; color: #69736b; display: flex; gap: 18px; align-items: flex-start; }
.doc .vf > div:last-child { min-width: 0; }
.doc .qr { flex: none; text-align: center; font-size: .75rem; }
.doc .qr img { display: block; width: 132px; height: 132px; }
@media print { .doc .qr img { width: 35mm; height: 35mm; } }
@media (max-width: 760px) { .doc .vf { flex-direction: column; } }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.wide { width: min(780px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 22, 18, .45); }
#dialog-body { padding: 22px 24px; max-height: 85vh; overflow: auto; }
#dialog-body h2 { margin-bottom: 14px; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.error { background: var(--danger); }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: min(480px, 100%); padding: 30px; }
.auth .brand { color: var(--ink); padding: 0 0 18px; }
.auth h1 { margin-bottom: 6px; }
.auth h1.serif { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: 2rem; letter-spacing: -.5px; margin: 6px 0 8px; }
.auth .fine { font-size: .75rem; color: var(--muted); margin-top: 18px; }
.auth form .check { margin: 4px 0 2px; }
/* ---------- nóminas TuniverS ---------- */
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.lines-table { table-layout: fixed; width: 100%; }
.lines-table input { width: 100%; min-width: 0; }
.lines-table th:nth-child(1) { width: 64px; } .lines-table th:nth-child(3), .lines-table th:nth-child(4) { width: 82px; } .lines-table th:nth-child(5) { width: 104px; }
.lines-table th:nth-child(6), .lines-table th:nth-child(7) { width: 58px; text-align: center; } .lines-table th:nth-child(8) { width: 44px; }
td.mono { white-space: nowrap; }
dialog.xwide { width: min(1240px, 96vw); max-width: 96vw; }
.summary-table td:first-child { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.summary-table td.num, .summary-table th.num { white-space: nowrap; }
.lines-table td { padding: 3px 4px; vertical-align: middle; }
.lines-table .w-code { width: 70px; } .lines-table .w-num { width: 90px; } .lines-table .w-chk { width: 54px; text-align: center; }
.calc-box { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.calc-box div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.calc-box b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.calc-box span { font-size: .75rem; color: var(--muted); }
.summary-table td, .summary-table th { font-size: .78rem; padding: 4px 6px; }
.summary-table tr.band td { background: var(--accent-soft); font-weight: 700; }
.summary-table tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
@media (max-width: 760px) { .calc-box { grid-template-columns: repeat(2, 1fr); } }

@media (max-width: 960px) {
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c2, .grid.h2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .side { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .doc { padding: 20px; }
}
@media print {
  .side, .topbar, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .doc { border: 0; padding: 0; }
  body { background: #fff; }
}

/* ERP: TPV, embudo CRM y fichaje */
.btn.block { width: 100%; justify-content: center; }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.pos-item { flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px; min-height: 84px; text-align: left; white-space: normal; }
.kanban { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 12px; overflow-x: auto; max-width: 100%; padding-bottom: 4px; }
.kanban > .card + .card { margin-top: 0; }
.kanban .col { padding: 12px; }
.deal { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; cursor: pointer; color: var(--ink); font: inherit; }
.deal:hover { border-color: var(--accent); }
.clock-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 28px; }
.btn.big { font-size: 1.15rem; padding: 14px 32px; }
.main { min-width: 0; }
.qr-box { display: flex; justify-content: center; margin: 8px 0; }
.qr-box svg { width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 6px; }
pre.codes { font-family: ui-monospace, monospace; font-size: 1rem; line-height: 1.7; columns: 2; background: var(--surface-2); padding: 12px 16px; border-radius: 8px; }
.form-actions.start { justify-content: flex-start; flex-wrap: wrap; }

/* Miniatura de la firma del cliente en un presupuesto aceptado */
.sig-thumb { max-height: 60px; background: #fff; border-radius: 6px; }
.logo-preview { max-height: 48px; vertical-align: middle; background: #fff; border-radius: 4px; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 12px 32px; }
.sig-pad { border: 1px dashed var(--muted); border-radius: 8px; background: #fff; touch-action: none; width: 100%; height: 170px; display: block; cursor: crosshair; }
/* Arrastrar y soltar en los tableros (CRM y tareas) */
.kanban .col.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.deal[draggable="true"] { cursor: grab; }
.pre { white-space: pre-wrap; }
/* Gantt */
.gantt-wrap { overflow-x: auto; }
.gantt { width: 100%; min-width: 700px; height: auto; font-size: 11px; }
.gantt .g-grid { stroke: var(--line); }
.gantt .g-month, .gantt .g-label { fill: var(--muted); }
.gantt .g-label { fill: var(--ink); }
.gantt .g-bar { fill: var(--accent); cursor: pointer; }
.gantt .g-bar.pendiente { fill: var(--muted); }
.gantt .g-bar.hecha { fill: var(--accent-soft); stroke: var(--accent); }
.gantt .g-bar.conflict { fill: #c0392b; }
.gantt .g-dep.conflict { stroke: #c0392b; }
.gantt .g-dep { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.gantt .g-arrow { fill: var(--muted); }
.gantt .g-today { stroke: #c0392b; stroke-dasharray: 4 3; }
/* Calendario */
.cap { text-transform: capitalize; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head div { font-size: .75rem; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-day { min-height: 92px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: var(--surface); overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.cal-day.empty { background: transparent; border-color: transparent; }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-n { font-size: .75rem; color: var(--muted); }
.cal-ev { display: block; font-size: .72rem; line-height: 1.25; padding: 1px 4px; border-radius: 4px; background: var(--surface-2); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.ok { background: var(--accent-soft); }
.cal-ev.bad { background: #f7dcd8; color: #7a1d12; }
.cal-ev.warn { background: #fbecc6; color: #6b4b00; }
@media (max-width: 700px) { .cal-day { min-height: 56px; } .cal-ev { font-size: .65rem; } }
.budget-grid input.bm { width: 84px; }
