:root {
  --bg: #f6f0e6;
  --surface: #fffcf7;
  --ink: #141210;
  --ink-2: #4a453e;
  --muted: #8a8278;
  --line: #e2d9cb;
  --line-strong: #141210;
  --accent: #e5402b;
  --accent-soft: #fbe3dd;
  --ok: #2f7a4b;
  --ok-soft: #dcefe2;
  --warn: #9a6b0f;
  --warn-soft: #f6ead0;
  --radius: 10px;
  --font: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1d1a17;
    --ink: #f3ece1;
    --ink-2: #c9c0b3;
    --muted: #8f877c;
    --line: #2f2a25;
    --line-strong: #f3ece1;
    --accent: #ff6a52;
    --accent-soft: #3a1d17;
    --ok: #7cc595;
    --ok-soft: #1b2e22;
    --warn: #e0b45a;
    --warn-soft: #33290f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 700; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 28px 18px; border-right: 1px solid var(--line);
}
.brand { text-decoration: none; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; display: flex; flex-direction: column; padding: 0 10px; }
.brand span { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0.02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .sidebar-foot a {
  text-decoration: none; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.sidebar nav a:hover, .sidebar-foot a:hover { background: var(--surface); color: var(--ink); }
.sidebar nav a.active, .sidebar-foot a.active { background: var(--ink); color: var(--bg); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot form { padding: 0 10px; }
.main { padding: 36px 44px 80px; max-width: 1180px; width: 100%; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 14px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .sidebar nav a { white-space: nowrap; }
  .sidebar-foot { flex-direction: row; align-items: center; justify-content: space-between; margin: 0; }
  .main { padding: 24px 16px 64px; }
  h1 { font-size: 24px; }
}

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Botones */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--ink); color: var(--bg);
  font: 600 14px var(--font); text-decoration: none; cursor: pointer;
}
.btn:hover { opacity: 0.88; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--ink); opacity: 1; }
.btn.danger { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
button.link:hover { color: var(--ink); }

/* Tarjetas y tablas */
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 2px; }
.stat.alert .value { color: var(--accent); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable:hover { background: var(--bg); }
td a { text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }
td .sub { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.card table th:first-child, .card table td:first-child { padding-left: 0; }
.card table th:last-child, .card table td:last-child { padding-right: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--muted); font-size: 13px; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok, .badge.aceptada, .badge.confirmado, .badge.pagado { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn, .badge.enviada, .badge.tentativo, .badge.pendiente { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.alert, .badge.rechazada, .badge.cancelado, .badge.vencido { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.alert-text { color: var(--accent); }

.empty { color: var(--muted); padding: 28px 0; text-align: center; margin: 0; }
.flash { background: var(--ok-soft); color: var(--ok); padding: 10px 14px; border-radius: 8px; margin: 0 0 20px; font-weight: 500; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a { text-decoration: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; font-weight: 500; color: var(--ink-2); }
.filters a.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Formularios */
form.stack { display: flex; flex-direction: column; gap: 16px; }
.fields { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
label, .label-text { font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  font: 15px var(--font); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: 40px; width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.check input { width: 18px; height: 18px; min-height: 0; }
.form-actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; align-items: center; }
.form-actions .right { display: flex; gap: 8px; margin-left: auto; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }

/* Editor de partidas */
.items { width: 100%; }
.items td { padding: 6px 6px; border: 0; }
.items th { padding: 6px; border-bottom: 1px solid var(--line); }
.items input { min-height: 38px; }
.items .qty { width: 80px; }
.items .price { width: 140px; }
.items .total { width: 130px; padding-top: 14px; }
.items .remove { width: 36px; }
.items .remove button { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; width: 36px; height: 38px; }
.items .remove button:hover { color: var(--accent); }
.totals { margin-left: auto; max-width: 340px; width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--line-strong); font-weight: 700; font-size: 17px; padding-top: 10px; margin-top: 4px; }
@media (max-width: 700px) {
  .items, .items tbody { display: block; }
  .items thead { display: none; }
  .items tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .items td { padding: 0; }
  .items td.desc { grid-column: 1 / -1; }
  .items .qty, .items .price, .items .total { width: auto; }
  .items .total { display: none; }
}

/* Calendario */
.cal-head { display: flex; align-items: center; gap: 8px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.calendar .dow { background: var(--surface); padding: 8px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.calendar .day { background: var(--surface); min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.calendar .day.out { background: var(--bg); }
.calendar .day.out .n { color: var(--muted); }
.calendar .n { font-size: 13px; font-weight: 600; text-decoration: none; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.calendar .day.today .n { background: var(--accent); color: #fff; }
.calendar .ev { display: block; font-size: 12px; line-height: 1.3; padding: 3px 6px; border-radius: 5px; text-decoration: none; background: var(--warn-soft); color: var(--warn); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar .ev.confirmado { background: var(--ok-soft); color: var(--ok); }
.calendar .ev.cancelado { background: var(--bg); color: var(--muted); text-decoration: line-through; }
@media (max-width: 700px) {
  .calendar { display: none; }
}
.agenda { display: none; }
@media (max-width: 700px) {
  .agenda { display: block; }
}

/* Acceso: fotografía corporativa de fondo con el logo en blanco */
body.auth {
  background: #1b1d22 url('/img/fondo-2400.jpg') center / cover no-repeat fixed;
  color: #fff;
}
@media (max-width: 1200px) {
  body.auth { background-image: url('/img/fondo-1200.jpg'); background-attachment: scroll; }
}
body.auth::before {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 11, 14, 0.15) 0%, rgba(10, 11, 14, 0.55) 55%, rgba(10, 11, 14, 0.8) 100%);
}
.bare-main { position: relative; min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; text-align: center;
  padding: 36px 28px 28px; border-radius: 18px;
  background: rgba(14, 15, 18, 0.5); border: 1px solid rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(18px) saturate(1.2); backdrop-filter: blur(18px) saturate(1.2);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-brand img { width: 220px; max-width: 100%; height: auto; }
.auth-brand span { font-size: 12px; font-weight: 600; letter-spacing: 0.24em; text-transform: uppercase; color: rgba(255, 255, 255, 0.7); }
.auth-card .btn { width: 100%; min-height: 48px; font-size: 15px; background: #fff; color: #111; border-color: #fff; }
.auth-card p { color: rgba(255, 255, 255, 0.85); }
.auth-card .hint { color: rgba(255, 255, 255, 0.6); }
.auth-card [data-passkey-status] { color: #ffb4a6; min-height: 1.5em; font-size: 14px; }
[data-passkey-status] { color: var(--accent); min-height: 1.5em; font-size: 14px; }

.logo-preview { background: #f6f0e6; border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: inline-block; }
.logo-preview img { max-height: 60px; max-width: 320px; display: block; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { font-size: 13px; }

/* Datos bancarios */
.bank-logo { display: inline-block; flex: none; border-radius: 9px; object-fit: contain; background: #fff; border: 1px solid var(--line); padding: 3px; }
.bank-logo.initials { display: inline-grid; place-items: center; padding: 0; background: var(--ink); color: var(--bg); font-weight: 700; border: 0; }
.bank-card header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bank-card header > div { flex: 1; min-width: 0; }
.bank-card header h2 { margin: 0; }
.bank-card header p { margin: 2px 0 0; font-size: 13px; }
.bank-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.bank-card dt { color: var(--muted); }
.bank-card dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bank-card.inactive { opacity: 0.6; }
.bank-option { padding: 6px 0; align-items: center; }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; font-size: 14px; cursor: pointer; }
.segmented input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.flash.error { background: var(--accent-soft); color: var(--accent); }
[hidden] { display: none !important; }
@media (max-width: 480px) { .bank-card dl { grid-template-columns: 1fr; gap: 0 0; } .bank-card dd { margin-bottom: 8px; } }
.subcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.subcard h3 { font-size: 15px; margin: 0 0 12px; }
.stat.ok .value { color: var(--ok); }
.line-edit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.line-edit input[name="name"] { width: auto; flex: 1; min-width: 160px; max-width: 320px; min-height: 34px; padding: 5px 9px; }
.steps { margin: 12px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
code { font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }
.grid > .card + .card { margin-top: 0; }
/* Eventos de varios días: barra continua entre celdas */
.calendar .ev.span-start { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: -6px; }
.calendar .ev.span-mid { border-radius: 0; margin: 0 -6px; }
.calendar .ev.span-end { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -6px; }
.range-box { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; margin-top: 14px; padding: 14px 16px; border-radius: 8px; background: var(--bg); }
.range-box > div:not(.actions) { display: flex; flex-direction: column; gap: 2px; }
.range-box strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.range-box .actions { margin-left: auto; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
.sheet-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 14px; padding: 22px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.sheet-dialog::backdrop { background: rgba(10, 10, 10, 0.45); }
.sheet-dialog h2 { margin-bottom: 6px; }
.nav-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 14px 10px 4px; }
.nav-group:first-child { padding-top: 0; }
.sidebar { overflow-y: auto; }
@media (max-width: 860px) { .nav-group { display: none; } }
.access-block { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--bg); font: 14px/1.5 var(--font); white-space: pre-wrap; }
