/* =====================================================================
   Control Eventos · estilos
   - Colores y medidas en variables (:root). Modo oscuro automático.
   - Móvil: tablas → tarjetas, calendario → puntos + agenda.
   ===================================================================== */

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;          /* campos, cabeceras de tabla, cajas de total */
  --text: #1c2230;
  --muted: #667085;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e6eefe;
  --primary-text: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --success: #15803d;
  --success-soft: #e3f6ea;
  --warn: #a15c07;
  --warn-soft: #fff4e0;
  --warn-border: #f3c77a;

  --st-presupuesto: #a15c07; --st-presupuesto-bg: #fdf0d5;
  --st-confirmado: #1d4ed8;  --st-confirmado-bg: #e1eafd;
  --st-realizado: #15803d;   --st-realizado-bg: #dcf3e4;
  --st-cancelado: #667085;   --st-cancelado-bg: #eceef2;

  --blocked-bg: repeating-linear-gradient(45deg, #fdeeee 0 7px, #fff7f7 7px 14px);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --focus: 0 0 0 3px rgba(37, 99, 235, .35);
  --field-h: 2.6rem;
  --container: 1200px;
  --gutter: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1218;
    --surface: #181c24;
    --surface-2: #10141b;
    --text: #e7e9ee;
    --muted: #98a2b3;
    --border: #2a303b;
    --border-strong: #3a4250;
    --primary: #5b8dff;
    --primary-hover: #7aa3ff;
    --primary-soft: #1a2a4a;
    --primary-text: #0b1020;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --success: #6ce39a;
    --success-soft: #11301f;
    --warn: #fdb022;
    --warn-soft: #2e2410;
    --warn-border: #6b5118;

    --st-presupuesto: #fcd34d; --st-presupuesto-bg: #362a0f;
    --st-confirmado: #9ec0ff;  --st-confirmado-bg: #182a4d;
    --st-realizado: #86efac;   --st-realizado-bg: #12311f;
    --st-cancelado: #98a2b3;   --st-cancelado-bg: #232833;

    --blocked-bg: repeating-linear-gradient(45deg, #2c1718 0 7px, #221416 7px 14px);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
    --focus: 0 0 0 3px rgba(91, 141, 255, .45);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4.5rem; }
body {
  margin: 0; min-height: 100vh;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; line-height: 1.3; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
small, .small { font-size: .85em; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 0 .35em; border-radius: 5px; font-size: .85em; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.muted { color: var(--muted); }
.mt { margin-top: 1.25rem; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.okc { color: var(--success); }
.inline { display: inline; }

/* ---------- barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  position: relative; max-width: var(--container); margin: 0 auto; padding: .55rem var(--gutter);
  display: flex; align-items: center; gap: 1rem; min-height: 3.5rem;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; display: flex; align-items: center; gap: .4rem; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .15rem; align-items: center; margin-left: auto; }
.topbar nav a, .topbar nav .linklike {
  display: block; padding: .45rem .7rem; border-radius: var(--radius-sm);
  color: var(--text); font: inherit; font-size: .95rem; white-space: nowrap;
}
.topbar nav a:hover, .topbar nav .linklike:hover { text-decoration: none; background: var(--surface-2); }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topbar nav form { margin: 0; }
.linklike { background: none; border: 0; cursor: pointer; color: var(--muted) !important; }
.navtoggle { position: absolute; opacity: 0; pointer-events: none; }
.burger { display: none; }

@media (max-width: 1050px) {
  .burger {
    display: grid; place-items: center; margin-left: auto; width: 2.5rem; height: 2.5rem;
    font-size: 1.35rem; cursor: pointer; border-radius: var(--radius-sm); color: var(--text);
  }
  .burger:hover { background: var(--surface-2); }
  .navtoggle:focus-visible + .burger { box-shadow: var(--focus); }
  .topbar nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: 0; margin: 0;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg);
    padding: .4rem var(--gutter) .8rem;
  }
  .topbar nav a, .topbar nav .linklike { padding: .75rem .8rem; width: 100%; text-align: left; }
  .navtoggle:checked ~ nav { display: flex; }
}

/* ---------- layout ---------- */
main { max-width: var(--container); margin: 0 auto; padding: 1.4rem var(--gutter) 4rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.pagehead > div:first-child { min-width: 0; }
.pagehead p { margin: .35rem 0 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.intro { margin: -.5rem 0 1.25rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card > :last-child { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }

@media (max-width: 860px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) {
  :root { --gutter: .85rem; }
  main { padding-top: 1rem; }
  h1 { font-size: 1.35rem; }
  .card { padding: .95rem 1rem; border-radius: 10px; }
  .pagehead > .actions, .pagehead > .btn { width: 100%; }
  .pagehead > .actions > .btn, .pagehead > .actions > form, .pagehead > .actions > form .btn { flex: 1; justify-content: center; }
  .pagehead > .btn { justify-content: center; }
}

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: var(--field-h); padding: 0 1rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { min-height: 2rem; padding: 0 .7rem; font-size: .85rem; }
.btn.icon { width: var(--field-h); padding: 0; flex: none; }
.btn.small.icon { width: 2rem; }
.btn.big { min-height: 2.9rem; padding: 0 1.8rem; font-size: 1.02rem; }
.btn[disabled], .htmx-request.btn, .htmx-request .btn { opacity: .55; pointer-events: none; }

/* ---------- formularios ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); margin-bottom: .85rem; min-width: 0; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .5rem .7rem; width: 100%; min-width: 0; min-height: var(--field-h);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); background: var(--surface); }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; accent-color: var(--primary); flex: none; }
input[type=file] { padding: .35rem; }
input[type=file]::file-selector-button {
  font: inherit; font-size: .85rem; margin-right: .75rem; padding: .35rem .8rem; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text);
}
select { cursor: pointer; }
input[readonly] { color: var(--muted); }

label.check { flex-direction: row; align-items: center; gap: .55rem; color: var(--text); font-size: .95rem; cursor: pointer; }

.fgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1rem; align-items: start; }
.fgrid .span2 { grid-column: span 2; }
.fgrid .span3 { grid-column: span 3; }
.fgrid .full { grid-column: 1 / -1; }
.fgrid > .btn, .fgrid > div > .btn { margin-top: 1.55rem; }
@media (max-width: 760px) {
  .fgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fgrid .span3 { grid-column: span 2; }
}
@media (max-width: 420px) {
  .fgrid { grid-template-columns: minmax(0, 1fr); }
  .fgrid .span2, .fgrid .span3 { grid-column: auto; }
  .fgrid > .btn, .fgrid > div > .btn { margin-top: 0; width: 100%; }
}
.inputrow { display: flex; gap: .4rem; }
.inputrow select { flex: 1; }

/* caja de importe (Base / Total) alineada con los campos */
.totalbox {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  min-height: var(--field-h); margin: 1.55rem 0 .85rem; padding: .45rem .8rem;
  border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong);
  font-variant-numeric: tabular-nums;
}
.totalbox b { font-size: 1.05rem; white-space: nowrap; }
@media (max-width: 420px) { .totalbox { margin-top: 0; } }

/* resumen de facturación del formulario */
.billsum {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem 1.5rem;
  padding: .75rem .9rem; margin: 0 0 1rem; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
}
.billsum span { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.billsum b { color: var(--text); font-variant-numeric: tabular-nums; }
.billsum .grand { margin-left: auto; font-size: 1.02rem; color: var(--text); }
.billsum .grand b { font-size: 1.15rem; }
@media (max-width: 520px) { .billsum .grand { margin-left: 0; width: 100%; padding-top: .35rem; border-top: 1px solid var(--border); } }

/* facturado / cobrado + su fecha */
.statusfields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.statusfield { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .65rem .8rem .1rem; }
.statusfield label.check { margin-bottom: .6rem; font-weight: 600; }
@media (max-width: 520px) { .statusfields { grid-template-columns: minmax(0, 1fr); gap: .75rem; } }

/* barra fija de guardar */
.formactions {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; justify-content: flex-end; align-items: center; gap: .6rem;
  margin: 1rem calc(-1 * var(--gutter)) -4rem; padding: .75rem var(--gutter);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
}
.card .formactions { position: static; margin: .5rem 0 0; padding: 0; background: none; border: 0; backdrop-filter: none; }
@media (max-width: 600px) { .formactions .btn { flex: 1; } }

/* ---------- filtros ---------- */
.filters { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(0, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.filters.single { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 1000px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .filters input[type=search] { grid-column: 1 / -1; } }

/* ---------- avisos ---------- */
.flash { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.flash.ok { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.flash.err { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.flash.warn { background: var(--warn-soft); border-color: var(--warn-border); }
.flash.warn div + div { margin-top: .3rem; }
.flash a { font-weight: 600; }

/* ---------- badges y estados ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .25rem; padding: .12rem .55rem; border-radius: 999px;
  font-size: .76rem; font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: middle;
}
.st-presupuesto { background: var(--st-presupuesto-bg); color: var(--st-presupuesto); }
.st-confirmado  { background: var(--st-confirmado-bg);  color: var(--st-confirmado); }
.st-realizado   { background: var(--st-realizado-bg);   color: var(--st-realizado); }
.st-cancelado   { background: var(--st-cancelado-bg);   color: var(--st-cancelado); }
.badge.st-cancelado { text-decoration: line-through; }
.bill-pendiente { background: var(--warn-soft); color: var(--warn); }
.bill-facturado { background: var(--st-confirmado-bg); color: var(--st-confirmado); }
.bill-cobrado   { background: var(--st-realizado-bg); color: var(--st-realizado); }
.badge.kind-badge { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); font-size: .78rem; }
.badge.holded { background: var(--primary-soft); color: var(--primary); padding: .05rem .45rem; font-size: .7rem; }
.blockedbadge { background: var(--blocked-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }

.statusbar { display: flex; gap: .4rem; flex-wrap: wrap; margin: 0; }
.chip {
  border: 1.5px solid transparent; border-radius: 999px; padding: .32rem .85rem;
  cursor: pointer; font: inherit; font-size: .86rem; font-weight: 500;
  filter: saturate(.35); opacity: .75; transition: opacity .12s, filter .12s;
}
.chip:hover { opacity: 1; filter: none; }
.chip.on { opacity: 1; filter: none; border-color: currentColor; font-weight: 700; }
.chip.st-cancelado { text-decoration: none; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 960px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 400px) { .kpis { gap: .6rem; } }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; display: flex; flex-direction: column; gap: .1rem; min-width: 0;
  color: var(--text); box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); }
.kpi.warn::before { background: #f59e0b; } .kpi.alert::before { background: var(--danger); } .kpi.good::before { background: #16a34a; }
.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi-label { font-size: .8rem; color: var(--muted); }
.kpi-value { font-size: clamp(1.1rem, 2.4vw, 1.5rem); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: .76rem; color: var(--muted); }

/* ---------- listas ---------- */
.evline {
  display: grid; grid-template-columns: 6.8rem minmax(0, 1fr) auto; gap: .2rem .85rem; align-items: center;
  padding: .6rem .25rem; border-bottom: 1px solid var(--border); color: var(--text);
}
.evline:last-child { border-bottom: 0; }
.evline:hover { text-decoration: none; background: var(--surface-2); }
.evdate { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; line-height: 1.3; }
.evdate b { display: block; color: var(--text); font-size: .92rem; font-weight: 600; }
.evtitle { min-width: 0; font-weight: 500; line-height: 1.35; }
.evtitle small { display: block; color: var(--muted); font-weight: 400; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 460px) {
  .evline { grid-template-columns: minmax(0, 1fr) auto; }
  .evline .evdate { grid-column: 1 / -1; }
  .evdate b { display: inline; margin-right: .3rem; }
}

.row-action { display: flex; gap: .5rem .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.row-action:last-child { border-bottom: 0; }
.row-action .grow { flex: 1 1 14rem; min-width: 0; color: var(--text); line-height: 1.35; }
.row-action .grow small { color: var(--muted); }
.row-action .side { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
a.grow:hover { text-decoration: none; color: var(--primary); }

.dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.dl .sep { grid-column: 1 / -1; border-top: 1px solid var(--border); margin: .2rem 0; }
.notes { white-space: pre-wrap; background: var(--surface-2); padding: .75rem .85rem; border-radius: var(--radius-sm); overflow-wrap: anywhere; }

.billtoggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin-top: 1rem; }
.toggle {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  min-height: 3.4rem; padding: .6rem; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-strong); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; transition: border-color .12s, background .12s;
}
.toggle:hover { border-color: var(--primary); }
.toggle small { font-weight: 500; color: inherit; opacity: .8; }
.toggle.on { border-style: solid; border-color: var(--success); background: var(--success-soft); color: var(--success); }

.dangerzone { display: flex; justify-content: space-between; align-items: center; gap: .75rem 1rem; flex-wrap: wrap; margin-top: 1rem; }
.dangerzone form { margin: 0; }
.upload { display: flex; gap: .5rem; margin-top: .9rem; }
.upload input { flex: 1; }
@media (max-width: 520px) { .upload { flex-direction: column; } }

/* ---------- tablas ---------- */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .tablewrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; font-weight: 600; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table tr.dim td { opacity: .5; }
.table .title { color: var(--text); font-weight: 600; }
.table tr.clickable:hover .title { color: var(--primary); }
.table td small { color: var(--muted); }

/* Tablas → tarjetas en móvil. Cada <td> lleva data-label. */
@media (max-width: 700px) {
  .tablewrap.cards { background: none; border: 0; box-shadow: none; overflow: visible; border-radius: 0; }
  .cards .table thead { display: none; }
  .cards .table, .cards .table tbody, .cards .table tfoot, .cards .table td { display: block; width: 100%; }
  .cards .table tr { display: flex; flex-direction: column; }
  .cards .table td.primary { order: -1; }
  .cards .table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .7rem .9rem; margin-bottom: .6rem; box-shadow: var(--shadow);
  }
  .cards .table td { border: 0; padding: .18rem 0; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; text-align: right; min-height: 0; }
  .cards .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  .cards .table td.primary { display: block; text-align: left; font-size: 1rem; padding-bottom: .4rem; margin-bottom: .25rem; border-bottom: 1px solid var(--border); }
  .cards .table td.primary::before { content: none; }
  .cards .table td:empty { display: none; }
  .cards .table td.num { white-space: normal; }
  .cards .table tr.clickable:hover td { background: none; }
  .cards .table tfoot tr { background: var(--surface-2); }
  .cards .table tfoot td { background: none; border: 0; }
}

/* ---------- calendario ---------- */
.calnav { display: flex; align-items: center; gap: .5rem; margin-bottom: .9rem; flex-wrap: wrap; }
.calnav h2 { margin: 0; min-width: 11.5rem; text-align: center; font-size: 1.2rem; }
.calnav .check { margin: 0 0 0 auto; font-size: .9rem; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.calhead { background: var(--surface-2); text-align: center; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .45rem 0; font-weight: 600; }
.calday { background: var(--surface); min-height: 7rem; padding: .35rem; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.calday.weekend { background: color-mix(in srgb, var(--surface) 65%, var(--surface-2)); }
.calday.out { background: var(--surface-2); }
.calday.out .calnum a { color: var(--muted); font-weight: 500; }
.calday.out .calev { opacity: .6; }
.calday.blocked { background: var(--blocked-bg); }
.calnum { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 600; min-height: 1.6rem; }
.calnum a { color: var(--text); display: inline-grid; place-items: center; min-width: 1.6rem; height: 1.6rem; border-radius: 999px; }
.calnum a:hover { background: var(--primary-soft); text-decoration: none; }
.calday.today .calnum a { background: var(--primary); color: var(--primary-text); }
.calev {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: .75rem; line-height: 1.3; padding: 2px 6px; border-radius: 5px; overflow-wrap: anywhere;
  border-left: 3px solid currentColor;
}
.calev:hover { text-decoration: none; filter: brightness(.96); }
.calev.st-cancelado { text-decoration: line-through; }
.caldots { display: none; }
.legend { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .9rem; }

/* agenda del mes (solo móvil) */
.agenda { display: none; margin-top: 1rem; }
.agenda h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.1rem 0 .45rem; }
.agenda .card { padding: .2rem .9rem; }

@media (max-width: 700px) {
  .calnav h2 { min-width: 0; flex: 1; font-size: 1.05rem; }
  .calnav .check { width: 100%; margin: 0; }
  .calhead { font-size: .65rem; letter-spacing: 0; }
  .calday { min-height: 3.2rem; padding: .25rem .1rem; align-items: center; gap: 3px; }
  .calnum { justify-content: center; min-height: 0; }
  .calnum span { display: none; }
  .calnum a { min-width: 1.75rem; height: 1.75rem; font-size: .8rem; }
  .calday .calev { display: none; }
  .caldots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
  .caldots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .caldots i.st-presupuesto, .caldots i.st-confirmado, .caldots i.st-realizado, .caldots i.st-cancelado { background: currentColor; }
  .agenda { display: block; }
  .legend { display: none; }
}

/* ---------- tipo de evento y jornadas ---------- */
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.segmented label { position: relative; margin: 0; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex; flex-direction: column; gap: .15rem; height: 100%;
  padding: .8rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-weight: 600; font-size: 1rem; transition: border-color .12s, background .12s;
}
.segmented span small { font-weight: 400; color: var(--muted); font-size: .82rem; }
.segmented label:hover span { border-color: var(--border-strong); }
.segmented input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

.days { display: flex; flex-direction: column; gap: .45rem; }
.dayrow {
  display: grid; grid-template-columns: minmax(9rem, 1.5fr) minmax(6.5rem, 1fr) minmax(6.5rem, 1fr) 4rem var(--field-h);
  gap: .5rem; align-items: center;
}
.dayrow.dayhead { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.dayrow .hrs { font-size: .85rem; text-align: right; font-variant-numeric: tabular-nums; }
.dayrow .btn { width: var(--field-h); padding: 0; }
@media (max-width: 600px) {
  .dayrow.dayhead { display: none; }
  .dayrow {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--field-h);
    grid-template-areas: "date date del" "start end hrs";
    padding: .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  }
  .dayrow input { background: var(--surface); }
  .dayrow input[name=day_date] { grid-area: date; }
  .dayrow input[name=day_start] { grid-area: start; }
  .dayrow input[name=day_end] { grid-area: end; }
  .dayrow .hrs { grid-area: hrs; text-align: center; font-size: .78rem; }
  .dayrow .btn { grid-area: del; }
}

.kindchoice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.kindchoice .card { margin: 0; }
@media (max-width: 600px) { .kindchoice { grid-template-columns: minmax(0, 1fr); } }
.kindcard { display: flex; flex-direction: column; gap: .4rem; color: var(--text); padding: 1.4rem; border-width: 1.5px; transition: border-color .12s, transform .12s; }
.kindcard:hover, .kindcard:focus-visible { border-color: var(--primary); text-decoration: none; transform: translateY(-1px); }
.kindcard b { font-size: 1.15rem; }
.kindicon { font-size: 2rem; line-height: 1; }

.daylist { display: grid; grid-template-columns: max-content max-content 1fr; gap: .3rem 1.2rem; margin: 0; font-variant-numeric: tabular-nums; }
.daylist dt { color: var(--text); }
.daylist dd { margin: 0; }
@media (max-width: 420px) { .daylist { grid-template-columns: max-content 1fr; } .daylist dd.muted { display: none; } }

/* ---------- login ---------- */
.loginpage { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login { width: 100%; max-width: 380px; padding: 1.6rem; box-shadow: var(--shadow-lg); }
.login h1 { margin-bottom: 1.2rem; text-align: center; font-size: 1.35rem; }
.login .btn { width: 100%; margin-top: .25rem; }

/* ---------- impresión ---------- */
@media print {
  .topbar, .formactions, .actions, .dangerzone, .upload, .billtoggles { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
.evline.nodate { grid-template-columns: minmax(0, 1fr) auto; }

/* ---------- facturas y gastos ---------- */
@media (max-width: 1250px) and (min-width: 1051px) {
  .topbar nav a, .topbar nav .linklike { padding: .45rem .5rem; font-size: .9rem; }
}
.filters.fin { grid-template-columns: minmax(200px, 2fr) repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .filters.fin { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.badge.st-vencida { background: var(--danger-soft); color: var(--danger); }
.rowactions { white-space: nowrap; text-align: right; }
.rowactions > * { display: inline-flex; vertical-align: middle; margin-left: .3rem; }
.rowactions form { margin: 0; }
@media (max-width: 700px) {
  .cards .table td.rowactions { justify-content: flex-end; gap: .4rem; padding-top: .5rem; margin-top: .3rem; border-top: 1px solid var(--border); }
  .cards .table td.rowactions::before { content: none; }
  .cards .table td.rowactions > * { margin: 0; }
}
.cats { display: flex; flex-direction: column; gap: .45rem; }
.cat { display: grid; grid-template-columns: minmax(8rem, 16rem) minmax(0, 1fr) auto; gap: .75rem; align-items: center; font-size: .9rem; }
.catname { display: flex; align-items: center; gap: .45rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catname i, .catchip i { width: .65rem; height: .65rem; border-radius: 3px; flex: none; display: inline-block; }
.catbar { height: .55rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.catbar span { display: block; height: 100%; border-radius: 999px; min-width: 2px; }
@media (max-width: 560px) { .cat { grid-template-columns: minmax(0, 1fr) auto; } .catbar { grid-column: 1 / -1; order: 3; } }
.catchip { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; white-space: nowrap; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; position: relative;
  min-height: 6.5rem; margin: 0; padding: 1rem; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); color: var(--text);
}
.dropzone:hover { border-color: var(--primary); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.dz-file { font-size: .85rem; }
.quarter-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.quarter-head h2 { margin: 0; }
.qgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem; }
.qgrid > div { display: flex; flex-direction: column; gap: .1rem; padding: .65rem .8rem; border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.qgrid span { font-size: .8rem; }
.qgrid b { font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qgrid small { font-size: .75rem; }
.qgrid .qresult { background: var(--primary-soft); }
.qgrid .qresult b { color: var(--primary); }
@media (max-width: 960px) { .qgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .qgrid .qresult { grid-column: 1 / -1; order: -1; } }
