:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #182033;
  --muted: #627084;
  --line: #e1e5ec;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #e9efff;
  --danger: #c0322a;
  --ok: #0f7a4d;
  --shadow: 0 1px 2px rgba(20, 30, 55, .05), 0 6px 20px rgba(20, 30, 55, .05);

  /* Tipos de día: fondo / texto */
  --T-bg: #dbe6ff;  --T-fg: #1d3fae;
  --D-bg: transparent; --D-fg: #9aa5b6;
  --V-bg: #c6efd9;  --V-fg: #0b6540;
  --AP-bg: #e5dbff; --AP-fg: #5630b4;
  --F-bg: #ffd8d4;  --F-fg: #ad241c;
  --AC-bg: #ffe6b3; --AC-fg: #825000;
  --BA-bg: #ffd5e9; --BA-fg: #a01c5f;
  --OT-bg: #dde2e9; --OT-fg: #3b4656;

  /* Marcas dentro del día */
  --m-med: #0891b2;
  --m-acomp: #d97706;
  --m-esp: #ea580c;
  --m-enc: #182033;
  --m-coche: #16a34a;

  --radius: 14px;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1219;
    --surface: #161b26;
    --surface-2: #1b212e;
    --ink: #e7ebf3;
    --muted: #8d98ab;
    --line: #272e3d;
    --accent: #7c9cff;
    --accent-ink: #0c1326;
    --accent-soft: #1d2847;
    --danger: #ff8a80;
    --ok: #6fdba8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);

    --T-bg: #22335f;  --T-fg: #bccdff;
    --D-fg: #5d6779;
    --V-bg: #12452f;  --V-fg: #8fe0b6;
    --AP-bg: #35275f; --AP-fg: #cdbbff;
    --F-bg: #5a211e;  --F-fg: #ffb3ac;
    --AC-bg: #4f3a10; --AC-fg: #ffd47f;
    --BA-bg: #55203c; --BA-fg: #ffb0d4;
    --OT-bg: #2c3442; --OT-fg: #c5ccd8;

    --m-med: #38c6e6;
    --m-acomp: #fbbf24;
    --m-esp: #fb8a4c;
    --m-enc: #f1f4fa;
    --m-coche: #4ade80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.pad { padding: 32px 0; }
.grow { flex: 1; }
.num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Controles ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  min-height: 40px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field { display: grid; gap: 5px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 32px; padding: 0 11px; font-size: .86rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent;
  cursor: pointer; color: var(--muted); font-size: 1rem;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }

.alert {
  padding: 10px 12px; border-radius: 9px;
  background: var(--F-bg); color: var(--F-fg); font-weight: 600; font-size: .9rem;
}

/* ---------- Acceso ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: min(400px, 100%); display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px 28px; box-shadow: var(--shadow);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand-lg { font-size: 1.2rem; margin-bottom: 6px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  background-image:
    linear-gradient(var(--accent-ink), var(--accent-ink)),
    linear-gradient(var(--accent-ink), var(--accent-ink));
  background-size: 14px 2.5px, 9px 2.5px;
  background-position: 6px 9px, 6px 14.5px;
  background-repeat: no-repeat;
}

/* ---------- Cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 1360px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 22px; min-height: 56px;
}
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: .92rem; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a[aria-current=page] { color: var(--accent); background: var(--accent-soft); }
.who { display: flex; align-items: center; gap: 6px; }
.who-name { font-size: .88rem; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wrap { max-width: 1360px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.card > h2, .card > h3 { margin-bottom: 12px; }
.stack { display: grid; gap: 14px; align-content: start; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }

/* ---------- Calendario ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.side { position: sticky; top: 76px; }

.year-nav { display: inline-flex; align-items: center; gap: 4px; }
.year-nav .yr { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; min-width: 4.2ch; text-align: center; font-variant-numeric: tabular-nums; }
.year-nav .icon-btn { font-size: 1.25rem; border: 1px solid var(--line); background: var(--surface); }

.legend-bar { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-bottom: 14px; }
.legend-bar span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.sw.st-D { border: 1px dashed var(--D-fg); }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px; font-size: .92rem;
}
.banner .btn { margin-left: auto; }

.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: 14px; user-select: none; }
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px 12px; }
.month h3 { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; }
.month h3 small { font-weight: 500; color: var(--muted); font-size: .76rem; }
.month.now h3 { color: var(--accent); }
.wd, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.wd span { text-align: center; font-size: .68rem; font-weight: 600; color: var(--muted); padding-bottom: 3px; }

.day {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 0;
  border: 0; border-radius: 8px; cursor: pointer;
  background: var(--D-bg); color: var(--ink);
  font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums;
  display: grid; place-items: center;
}
.day:hover { box-shadow: inset 0 0 0 2px var(--accent); }
.day.st-none { color: var(--ink); font-weight: 500; }
.day.st-T { background: var(--T-bg); color: var(--T-fg); }
.day.st-D { color: var(--D-fg); font-weight: 500; }
.day.st-V { background: var(--V-bg); color: var(--V-fg); }
.day.st-AP { background: var(--AP-bg); color: var(--AP-fg); }
.day.st-F { background: var(--F-bg); color: var(--F-fg); }
.day.st-AC { background: var(--AC-bg); color: var(--AC-fg); }
.day.st-BA { background: var(--BA-bg); color: var(--BA-fg); }
.day.st-OT { background: var(--OT-bg); color: var(--OT-fg); }
/* Cambio manual respecto al patrón (trabajaste un descanso o al revés) */
.day.swap { box-shadow: inset 0 0 0 1.5px currentColor; }
.day.swap.st-D { box-shadow: inset 0 0 0 1.5px var(--muted); color: var(--muted); }
.day.today::after {
  content: ""; position: absolute; inset: -2px; border-radius: 10px;
  border: 2px solid var(--ink); pointer-events: none;
}
.day.sel { box-shadow: inset 0 0 0 2px var(--accent); background-image: linear-gradient(color-mix(in srgb, var(--accent) 22%, transparent), color-mix(in srgb, var(--accent) 22%, transparent)); }
.marks { position: absolute; left: 0; right: 0; bottom: 3px; display: flex; justify-content: center; gap: 2px; }
.marks i, .dot { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.dot { width: 9px; height: 9px; flex: none; }
.m-med { background: var(--m-med); }
.m-acomp { background: var(--m-acomp); }
.m-esp { background: var(--m-esp); }
.m-enc { background: var(--m-enc); }
.m-coche { background: var(--m-coche); }
.day .rem {
  position: absolute; top: 3px; right: 3px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1.5px var(--surface);
}

.sw.st-T, .chip-sw.st-T { background: var(--T-bg); } .sw.st-V, .chip-sw.st-V { background: var(--V-bg); }
.sw.st-AP, .chip-sw.st-AP { background: var(--AP-bg); } .sw.st-F, .chip-sw.st-F { background: var(--F-bg); }
.sw.st-AC, .chip-sw.st-AC { background: var(--AC-bg); } .sw.st-BA, .chip-sw.st-BA { background: var(--BA-bg); }
.sw.st-OT, .chip-sw.st-OT { background: var(--OT-bg); }

/* ---------- Saldos ---------- */
.bal { display: grid; gap: 6px; }
.bal + .bal { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.bal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bal-name { font-weight: 600; font-size: .9rem; }
.bal-left { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bal-left small { font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.bal-left.over { color: var(--danger); }
.bar { height: 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bal-sub { font-size: .8rem; color: var(--muted); }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; font-size: .9rem; }
.kv dt { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.bal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 16px; }

/* ---------- Listas ---------- */
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.mini-list li { display: flex; align-items: flex-start; gap: 9px; padding: 6px 0; font-size: .9rem; }
.mini-list .when { color: var(--muted); font-size: .78rem; display: block; }
.mini-list .late .when { color: var(--danger); font-weight: 600; }
.mini-list input[type=checkbox], .rem-item input[type=checkbox], .check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.empty { color: var(--muted); font-size: .88rem; padding: 4px 0; }

.rem-form { display: grid; grid-template-columns: minmax(0, 1fr) 160px 120px auto; gap: 8px; }
.rem-list { list-style: none; margin: 0; padding: 0; }
.rem-item { display: flex; align-items: flex-start; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.rem-item:first-child { border-top: 0; }
.rem-item .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rem-item.done .txt { text-decoration: line-through; color: var(--muted); }
.rem-item .when { font-size: .8rem; color: var(--muted); display: block; }
.rem-item.late .when { color: var(--danger); font-weight: 600; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 700; border-bottom: 0; }
td.zero { color: var(--D-fg); }
td.actions { display: flex; gap: 6px; justify-content: flex-end; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .76rem; font-weight: 600; background: var(--OT-bg); color: var(--OT-fg); }
.tag.st-T { background: var(--T-bg); color: var(--T-fg); } .tag.st-D { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--line); }
.tag.st-V { background: var(--V-bg); color: var(--V-fg); } .tag.st-AP { background: var(--AP-bg); color: var(--AP-fg); }
.tag.st-F { background: var(--F-bg); color: var(--F-fg); } .tag.st-AC { background: var(--AC-bg); color: var(--AC-fg); }
.tag.st-BA { background: var(--BA-bg); color: var(--BA-fg); }

.log { list-style: none; margin: 0; padding: 0; }
.log li { border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log button {
  width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 9px 4px; background: none; border: 0; cursor: pointer; text-align: left;
}
.log button:hover { background: var(--surface-2); }
.log .d { width: 108px; font-weight: 600; font-size: .88rem; font-variant-numeric: tabular-nums; }
.log .n { color: var(--muted); font-size: .84rem; flex-basis: 100%; padding-left: 118px; overflow-wrap: anywhere; }

/* ---------- Ajustes ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form { display: grid; gap: 12px; }
.pattern { border: 1px solid var(--line); border-radius: 11px; padding: 12px; display: grid; gap: 10px; background: var(--surface-2); }
.pattern-head { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.pattern-head .field { flex: 1; max-width: 200px; }
.blocks { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.block { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px 3px 3px 6px; }
.block select { width: auto; min-height: 32px; padding: 4px 6px; border: 0; background: transparent; font-weight: 600; }
.block input { width: 54px !important; min-height: 32px !important; padding: 4px 6px !important; text-align: center; }
.block .icon-btn { width: 28px; height: 28px; font-size: .8rem; }
.strip { display: flex; flex-wrap: wrap; gap: 3px; }
.strip i { width: 16px; height: 16px; border-radius: 4px; }
.strip i.T { background: var(--T-bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--T-fg) 25%, transparent); }
.strip i.D { border: 1px dashed var(--D-fg); }
.hint { font-size: .8rem; color: var(--muted); }

/* ---------- Diálogo ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(540px, calc(100vw - 20px)); max-height: calc(100dvh - 20px);
  box-shadow: 0 20px 60px rgba(10, 15, 30, .3);
}
dialog::backdrop { background: rgba(10, 15, 30, .45); }
dialog[open] { display: flex; }
#dayForm { display: flex; flex-direction: column; min-height: 0; width: 100%; }
.dlg-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.dlg-head h2::first-letter { text-transform: uppercase; }
.dlg-body { padding: 10px 20px 16px; overflow-y: auto; display: grid; gap: 16px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.fs { border: 0; margin: 0; padding: 0; display: grid; gap: 9px; min-width: 0; }
.fs legend, .legend { font-size: .82rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px;
  border: 1px solid var(--line); border-radius: 99px; font-size: .86rem; font-weight: 600;
}
.chip-sw { width: 11px; height: 11px; border-radius: 3px; }
.chip-sw.st-D, .chip-sw.st- { border: 1px dashed var(--muted); }
.chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.hours-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hours-label { display: inline-flex; align-items: center; gap: 8px; width: 150px; font-weight: 600; font-size: .9rem; }
.inline { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .88rem; }
.inline input { width: 118px !important; }
.inline input[type=number] { width: 84px !important; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-weight: 600; font-size: .9rem; }
.check span { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check small { font-weight: 500; color: var(--muted); }
.add-inline { display: flex; gap: 8px; }

/* ---------- Avisos ---------- */
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; font-size: .9rem; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- Adaptación ---------- */
@media (max-width: 1020px) {
  .cal-layout { grid-template-columns: 1fr; }
  .side { position: static; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 720px) {
  .top-in { flex-wrap: wrap; gap: 0 12px; padding: 6px 16px 0; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -16px; padding: 4px 12px 6px; }
  .who { margin-left: auto; }
  .wrap { padding: 16px 16px 60px; }
  .rem-form { grid-template-columns: 1fr 1fr; }
  .rem-form > :first-child { grid-column: 1 / -1; }
  .rem-form .btn { grid-column: 1 / -1; }
  .hours-label { width: 100%; }
  .log .n { padding-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
