:root {
    --bg: #f7f4fb;
    --surface: #ffffff;
    --ink: #2b2340;
    --muted: #6e6685;
    --line: #e7e1f0;
    --primary: #7c5cbf;
    --primary-soft: #efe8fb;
    --ok: #23865b;
    --ok-soft: #e2f4ea;
    --warn: #b8651b;
    --warn-soft: #fdf0e0;
    --danger: #c2423f;
    --danger-soft: #fbe7e6;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(43, 35, 64, .05), 0 4px 16px rgba(43, 35, 64, .05);
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 1.55rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: .4rem 0; }
code { background: var(--primary-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.warn-text { color: var(--warn); font-weight: 600; }
.spacer { flex: 1; }

.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 56px; }

/* ---------- Barra superior ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none; display: flex; gap: 8px; align-items: center; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 7px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.userbox { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.userbox a { color: var(--ink); text-decoration: none; font-weight: 500; }
.userbox a.active { color: var(--primary); }
.userbox form { margin: 0; }
@media (max-width: 760px) {
    .nav { order: 3; flex-basis: 100%; margin: 0 -6px; }
    .userbox { margin-left: auto; }
}

/* ---------- Bloques ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 640px; }
.empty-state { color: var(--muted); text-align: center; padding: 24px 8px; margin: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.alert-ok { background: var(--ok-soft); color: #1b6646; }
.alert-error { background: var(--danger-soft); color: #8f2d2b; }
.alert-info { background: var(--primary-soft); color: #4e3690; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge-ok, .badge-btn.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn, .badge-btn.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--primary-soft); color: var(--primary); font-size: .72rem; vertical-align: middle; }
.badge-btn { font: inherit; font-size: .8rem; font-weight: 600; border: 1px solid transparent; border-radius: 999px; padding: 3px 11px; cursor: pointer; white-space: nowrap; }
.badge-btn:hover { border-color: currentColor; }

/* ---------- Botones y formularios ---------- */
.btn {
    font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid transparent;
    cursor: pointer; text-decoration: none; white-space: nowrap; transition: filter .15s, border-color .15s, background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--primary); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { min-height: 32px; padding: 4px 11px; font-size: .86rem; }
.btn-block { width: 100%; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: .84rem; font-weight: 600; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], select {
    font: inherit; font-size: 1rem; color: var(--ink); background: #fff; width: 100%;
    border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; min-height: 42px;
}
input:focus, select:focus { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; color: var(--ink); min-height: 42px; cursor: pointer; }
.check input { width: 19px; height: 19px; accent-color: var(--primary); margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.form-grid .field-wide { grid-column: span 2; }
@media (max-width: 420px) { .form-grid .field-wide { grid-column: auto; } }
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { min-width: 180px; }
.inline-form { display: flex; gap: 6px; margin: 0; }
.inline-form select { width: auto; }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; background: var(--bg); border-radius: 10px; margin-bottom: 10px; }
.bulk .check { min-height: 32px; }

details summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 4px 0; }
.details-body { display: flex; flex-direction: column; gap: 14px; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 8px; }
.user-card .section-head { margin-bottom: 4px; }

pre.code { background: #1f1a2e; color: #eee; padding: 14px; border-radius: 10px; overflow-x: auto; font-size: .82rem; }

/* ---------- Tarjetas de resumen ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.stats-money { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-label { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat-value small { font-size: .8rem; font-weight: 600; color: var(--muted); }
.stat-sub { font-size: .8rem; color: var(--muted); }
.stat.hero { background: var(--primary); border-color: transparent; color: #fff; }
.stat.hero .stat-label { color: rgba(255, 255, 255, .82); }
.stat.hero .stat-value { font-size: 1.7rem; }
.stat.ok .stat-value { color: var(--ok); }
.stat.warn .stat-value { color: var(--warn); }
@media (max-width: 760px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stats-money { grid-template-columns: repeat(2, 1fr); }
    .stats-money .hero { grid-column: 1 / -1; }
    .stat-value { font-size: 1.2rem; }
}

/* ---------- Calendario ---------- */
.cal { padding: 12px; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head div { text-align: center; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 0 6px; }
.cal-cell {
    appearance: none; font: inherit; color: inherit; text-align: left; position: relative;
    display: flex; flex-direction: column; min-height: 84px; padding: 6px 8px;
    background: var(--bg); border: 1px solid transparent; border-radius: 10px;
}
button.cal-cell { cursor: pointer; transition: border-color .12s, transform .12s; }
button.cal-cell:hover { border-color: var(--primary); }
button.cal-cell:active { transform: scale(.97); }
button.cal-cell:focus-visible { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.cal-cell.is-empty { background: transparent; }
.cal-num { font-size: .85rem; font-weight: 600; color: var(--muted); }
.cal-hours { margin-top: auto; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-hours small { font-size: .75rem; font-weight: 600; }
.cal-flags { position: absolute; top: 5px; right: 7px; font-size: .78rem; font-weight: 700; }
.cal-cell.is-pending { background: var(--warn-soft); }
.cal-cell.is-pending .cal-hours { color: var(--warn); }
.cal-cell.is-paid { background: var(--ok-soft); }
.cal-cell.is-paid .cal-hours, .cal-cell.is-paid .cal-flags { color: var(--ok); }
.cal-cell.is-today { border-color: var(--primary); }
.cal-cell.is-today .cal-num { color: var(--primary); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--muted); margin-top: 12px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.dot-warn { background: #f3c48f; }
.dot-ok { background: #8fd3b1; }
@media (max-width: 560px) {
    .cal { padding: 8px; }
    .cal-head, .cal-grid { gap: 3px; }
    .cal-cell { min-height: 58px; padding: 4px 5px; border-radius: 8px; }
    .cal-num { font-size: .72rem; }
    .cal-hours { font-size: .95rem; }
    .cal-hours small { display: none; }
    .cal-flags { top: 3px; right: 4px; font-size: .65rem; }
    .hide-sm { display: none; }
}

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .obs { color: var(--muted); max-width: 280px; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; background: var(--bg); }
.tbl tr.is-current td { background: var(--primary-soft); }
.tbl td small { display: block; }
.cell-check input { width: 18px; height: 18px; accent-color: var(--primary); }

@media (max-width: 680px) {
    .tbl.cards thead { display: none; }
    .tbl.cards, .tbl.cards tbody, .tbl.cards tfoot, .tbl.cards tr, .tbl.cards td { display: block; width: 100%; }
    .tbl.cards tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: var(--surface); }
    .tbl.cards tfoot tr { background: var(--bg); }
    .tbl.cards td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 14px; text-align: right; max-width: none; background: transparent; }
    .tbl.cards td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
    .tbl.cards td:empty, .tbl.cards td.hide-cards { display: none; }
    .tbl.cards td small { display: inline; margin-left: 6px; }
}

/* ---------- Diálogo ---------- */
.dialog { border: 0; padding: 0; border-radius: 18px; width: min(430px, calc(100% - 24px)); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, .28); }
.dialog::backdrop { background: rgba(43, 35, 64, .45); }
.dialog-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dialog-head h2 { margin: 0; }
.icon-btn { background: none; border: 0; font-size: 1.7rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: .88rem; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.dialog-actions { display: flex; flex-direction: row-reverse; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }

/* ---------- Login / instalación ---------- */
.login-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; }
.install-card { width: 100%; max-width: 560px; }
.login-logo { font-size: 2.6rem; text-align: center; line-height: 1; margin-bottom: 6px; }

/* ---------- Impresión ---------- */
@media print {
    .topbar, .no-print, .alert { display: none !important; }
    body { background: #fff; }
    .container { max-width: none; padding: 0; }
    .card, .stat { box-shadow: none; border-color: #ccc; break-inside: avoid; }
    .stat.hero { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
    .stat.hero .stat-label { color: var(--muted); }
}
