:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #171a21;
  --muted: #5d6474;
  --border: #dde1ea;
  --primary: #1f4e9c;
  --primary-ink: #ffffff;
  --primary-soft: #dce6ff;
  --danger: #c62828;
  --success: #2e7d32;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --plate: #ffcc00;
  --plate-ink: #1a1a1a;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101217;
    --surface: #1a1d24;
    --surface-2: #232733;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --border: #2e3340;
    --primary: #8fb0ff;
    --primary-ink: #0b1a3a;
    --primary-soft: #22345e;
    --danger: #ff8a80;
    --success: #81c784;
    --warn-bg: #3a2f10;
    --warn-ink: #ffe08a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.muted-h { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .25rem 0; white-space: pre-line; }
[hidden] { display: none !important; }

/* Placa */
.plate {
  display: inline-block;
  background: var(--plate);
  color: var(--plate-ink);
  border: 2px solid var(--plate-ink);
  border-radius: 6px;
  font: 800 1rem/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: .12em;
  padding: .3em .55em;
}
.plate-lg { font-size: 1.8rem; margin-bottom: 1rem; }
.plate-sm { font-size: .8rem; }
.plate-xs { font-size: .65rem; padding: .2em .4em; border-width: 1px; }

/* Botones e inputs */
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: .55rem 1rem;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label { display: block; font-weight: 600; font-size: .9rem; margin: .75rem 0; }
input, select, textarea {
  display: block; width: 100%;
  margin-top: .3rem;
  font: inherit; font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .65rem;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox] { display: inline; width: auto; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; text-align: center; }
.login-card label { text-align: left; }
.login-card .btn { width: 100%; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.tabs { display: flex; gap: .25rem; flex: 1; justify-content: center; }
.tabs button {
  font: inherit; font-weight: 600; color: var(--muted);
  background: none; border: 0; border-radius: 8px; padding: .45rem .9rem; cursor: pointer;
}
.tabs button[aria-selected=true] { background: var(--primary-soft); color: var(--text); }
.tab { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

/* Reglas */
.rules-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1.25rem; align-items: start; padding-bottom: 5rem; }
.city-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; position: sticky; top: 72px; }
.city-list-head { display: flex; justify-content: space-between; align-items: center; }
.city-list ul { list-style: none; padding: 0; margin: .5rem 0; }
.city-list li button {
  width: 100%; text-align: left; font: inherit;
  background: none; border: 0; border-radius: 8px; padding: .5rem .65rem; cursor: pointer; color: var(--text);
  display: flex; justify-content: space-between; align-items: center;
}
.city-list li button[aria-current=true] { background: var(--primary-soft); font-weight: 600; }
.badge { font-size: .7rem; font-weight: 700; border-radius: 99px; padding: .1rem .5rem; background: var(--warn-bg); color: var(--warn-ink); }
.badge.ok { background: transparent; color: var(--muted); font-weight: 500; }

.editor { display: grid; gap: 1rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.row label { margin: 0; }
.rule-card { border-left: 4px solid var(--primary); }
.rule-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.rule-head h3 { font-size: 1rem; margin: 0; }
.status-pill { font-size: .75rem; font-weight: 700; border-radius: 99px; padding: .15rem .6rem; }
.status-pill.active { background: #d8f0da; color: #1b5e20; }
.status-pill.future { background: var(--primary-soft); color: var(--text); }
.status-pill.expired { background: var(--warn-bg); color: var(--warn-ink); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }

.digit-grid { border-collapse: collapse; margin-top: .75rem; width: 100%; max-width: 560px; }
.digit-grid th { font-size: .8rem; color: var(--muted); font-weight: 600; padding: .2rem; }
.digit-grid th.day { text-align: left; padding-right: .75rem; white-space: nowrap; color: var(--text); }
.digit-grid td { padding: 2px; text-align: center; }
.digit {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 700 .95rem ui-monospace, Menlo, monospace;
}
.digit[aria-pressed=true] { background: var(--danger); border-color: var(--danger); color: #fff; }
.day-toggles { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.day-toggles .digit { width: auto; padding: 0 .6rem; font-family: inherit; font-size: .85rem; }
.day-toggles .digit[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.link-btn { margin-left: .35rem; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 .2rem; }
.link-btn:hover { color: var(--danger); }
.inline-actions { display: flex; gap: .5rem; margin-top: .6rem; }

.dayopts { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.dayopts summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.dayopt-row { display: grid; grid-template-columns: 90px 130px 130px 1fr; gap: .6rem; align-items: end; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.dayopt-row strong { align-self: center; }
.dayopt-row label { font-size: .8rem; }
.dayopt-row input { margin: 0; }
.weeks { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.digit.week { width: auto; padding: 0 .5rem; font-family: inherit; font-size: .8rem; }
.digit.week[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.special-row { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.special-row .row { grid-template-columns: 170px 120px 120px 1fr; }
.special-digits { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-top: .5rem; }
.special-digits .btn { margin-left: auto; }

.preview { width: 100%; border-collapse: collapse; }
.preview td { padding: .4rem .5rem; border-top: 1px solid var(--border); }
.preview td:last-child { font-family: ui-monospace, Menlo, monospace; font-weight: 700; text-align: right; }
.preview tr.none td { color: var(--muted); }

.exempt-row { display: grid; grid-template-columns: 170px 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.exempt-row input { margin: 0; }

.publish-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(900px, calc(100% - 32px));
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  padding: .65rem .75rem .65rem 1rem;
}
.publish-bar input { margin: 0; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #f5a623; flex: none; }

/* Push */
.push-layout { display: grid; grid-template-columns: 1fr 360px; gap: 1.25rem; align-items: start; }
.counter { float: right; font-weight: 400; color: var(--muted); font-size: .8rem; }
.banner { border-radius: 10px; padding: .75rem 1rem; margin-bottom: .5rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notif-preview { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: .9rem 1rem; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.notif-preview p { margin: .2rem 0 0; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.notif-app { font-size: .75rem; color: var(--muted); margin-bottom: .35rem; display: flex; align-items: center; gap: .4rem; }
.log { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.log li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; }
.log .meta { font-size: .75rem; color: var(--muted); }
.log .err { color: var(--danger); }

/* Tabla */
.table { width: 100%; border-collapse: collapse; margin-top: .75rem; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; color: var(--muted); }
.table td:last-child { text-align: right; white-space: nowrap; }

dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); max-width: 440px; padding: 1.5rem; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
#toast {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); border-radius: 10px; padding: .6rem 1rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; padding: .6rem 16px; }
  .tabs { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .tab { padding: 16px; }
  .rules-layout, .push-layout { grid-template-columns: 1fr; }
  .city-list { position: static; }
  .publish-bar { flex-wrap: wrap; }
  .publish-bar input { flex-basis: 100%; order: 3; }
  .exempt-row { grid-template-columns: 1fr auto; }
  .exempt-row input[type=text] { grid-column: 1 / -1; }
  .digit { width: 28px; height: 30px; }
  .dayopt-row { grid-template-columns: 1fr 1fr; }
  .dayopt-row strong, .dayopt-row .weeks { grid-column: 1 / -1; }
  .special-row .row { grid-template-columns: 1fr 1fr; }
  .special-row .row label:first-child, .special-row .row .grow { grid-column: 1 / -1; }
}
.add-day { display: flex; gap: .5rem; align-items: center; font-size: .85rem; margin-top: .6rem; }
.add-day select { width: auto; margin: 0; }
