:root {
  --bg: #fff7e8;
  --surface: #ffffff;
  --ink: #3a2a22;
  --muted: #7a6455;
  --line: #f1e2c9;
  --sun: #ffc93c;
  --sun-deep: #f0b000;
  --sun-soft: #fff0bf;
  --coral: #ff6f59;
  --coral-ink: #d8452f;
  --teal: #1aa39a;
  --teal-ink: #0c6f69;
  --teal-soft: #dcf4f0;
  --danger: #c93a2b;
  --shadow: 0 2px 0 rgb(58 42 34 / 0.05), 0 12px 28px rgb(140 90 20 / 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(520px 320px at 100% -40px, rgb(255 201 60 / 0.38), transparent 70%),
    radial-gradient(460px 300px at -80px 0, rgb(255 111 89 / 0.16), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  font: 15px/1.5 ui-rounded, "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 800; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.muted { color: var(--muted); }

/* ---------- buttons & fields ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 999px; font-weight: 700;
  border: 2px solid var(--line); background: var(--surface); color: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--sun); background: var(--sun-soft); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--sun); border-color: var(--sun); box-shadow: 0 3px 0 var(--sun-deep); }
.btn.primary:hover { background: #ffd35c; border-color: #ffd35c; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sun-deep); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--sun-soft); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px 16px; font-size: 16px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--bg);
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--sun-soft); color: var(--ink); }

.field { display: grid; gap: 5px; font-size: 14px; color: var(--muted); }
.field > span { font-weight: 700; }
.field input, .field select {
  width: 100%; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--teal); outline: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 14px; }

.form-error { color: var(--danger); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }
.empty { color: var(--muted); padding: 4px 0; }

/* ---------- brand & login ---------- */

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.logo { width: 44px; height: 44px; display: block; flex: none; }
.wordmark { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.wordmark em { font-style: normal; color: var(--coral-ink); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.card {
  background: var(--surface); border: 2px solid var(--line); border-radius: 28px;
  box-shadow: var(--shadow); padding: 28px;
}
.login { width: min(400px, 100%); display: grid; gap: 16px; text-align: center; }
.login .logo { width: 84px; height: 84px; margin: 0 auto; }
.login h1 { font-size: 26px; }
.login .lead { color: var(--muted); margin-top: -8px; }
.login .field { text-align: left; }

/* ---------- shell ---------- */

.shell { max-width: 1120px; margin: 0 auto; padding: 0 16px 56px; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 16px 0 8px; }
.who { display: flex; align-items: center; gap: 4px; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--sun-soft); border-radius: 999px; }
.tab { border: none; background: transparent; padding: 6px 18px; border-radius: 999px; cursor: pointer; font-weight: 800; color: var(--muted); }
.tab[aria-current="page"] { background: var(--sun); color: var(--ink); box-shadow: 0 2px 0 var(--sun-deep); }

.welcome { margin: 18px 0 20px; }
.welcome h1 { font-size: 30px; }
.welcome p { color: var(--muted); margin-top: 4px; }

/* ---------- toolbar ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 14px; }
.month-nav { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.month-nav h2 { font-size: 24px; min-width: 9.5ch; text-align: center; }
.month-nav .btn:not(.ghost) { width: 40px; height: 40px; padding: 0; font-size: 20px; line-height: 1; }
.toolbar .field { display: flex; align-items: center; gap: 8px; }
.toolbar .field select { width: auto; padding: 8px 14px; }

/* ---------- calendar ---------- */

.cal { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.cal-head {
  text-align: center; padding: 2px 0; font-size: 13px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--teal-ink);
}

.cell {
  display: flex; flex-direction: column; gap: 5px; align-items: stretch;
  min-height: 124px; padding: 10px; text-align: left;
  border: 2px solid var(--line); border-radius: 18px; background: var(--surface); cursor: pointer;
}
.cell:hover { border-color: var(--sun); box-shadow: var(--shadow); transform: translateY(-1px); }
.cell.blank { background: transparent; border-color: transparent; cursor: default; box-shadow: none; transform: none; }
.cell.today { background: var(--sun-soft); border-color: var(--sun); }
.cell-top { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.dnum { font-weight: 800; font-size: 15px; min-width: 28px; height: 28px; display: inline-grid; place-items: center; border-radius: 50%; }
.today .dnum { background: var(--sun); box-shadow: 0 2px 0 var(--sun-deep); }
.dname { display: none; color: var(--muted); font-weight: 700; }
.add-hint { margin-left: auto; color: var(--teal-ink); font-size: 20px; font-weight: 800; line-height: 1; opacity: 0; }
.cell:hover .add-hint, .cell:focus-visible .add-hint { opacity: 1; }

.chip {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 3px 10px; border-radius: 999px; font-size: 12.5px; line-height: 1.35;
  background: color-mix(in srgb, var(--c) 22%, #fff);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.chip.mine { background: color-mix(in srgb, var(--c) 42%, #fff); box-shadow: 0 0 0 2px var(--c); font-weight: 800; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
.chip-time { color: var(--ink); opacity: 0.72; white-space: nowrap; font-variant-numeric: tabular-nums; }
.extra { display: none; }
.more { font-size: 12px; font-weight: 700; color: var(--teal-ink); padding-left: 6px; }

/* ---------- totals ---------- */

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 30px 0 12px; }
.section-title { font-size: 18px; }
.totals { display: flex; flex-wrap: wrap; gap: 10px; }
.total {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px;
}
.total.me { border-color: var(--teal); background: var(--teal-soft); }
.total span:last-child { color: var(--muted); font-size: 14px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }

/* ---------- people ---------- */

.two-col { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 18px; }
.table-wrap { overflow-x: auto; border: 2px solid var(--line); border-radius: 22px; background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 16px; text-align: left; border-bottom: 2px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--teal-ink); background: var(--sun-soft); }
.role-select { padding: 4px 10px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: 13px; cursor: pointer; }
.role-select:focus { border-color: var(--teal); outline: none; }
.person { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 9px; border-radius: 999px; background: var(--teal-soft); color: var(--teal-ink);
}
.pill-off { color: var(--muted); font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--bg); }

.banner {
  display: grid; gap: 8px; padding: 16px 18px; margin-top: 18px;
  border: 2px solid var(--teal); background: var(--teal-soft); border-radius: 22px;
}
.banner code {
  display: inline-block; padding: 4px 12px; border-radius: 10px; background: var(--surface);
  border: 2px solid var(--line); font: 700 16px ui-monospace, "Cascadia Mono", Consolas, monospace; user-select: all;
}
.banner .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- dialogs ---------- */

dialog.dlg {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
  padding: 22px; border: none; border-radius: 28px;
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgb(58 42 34 / 0.3);
}
dialog.dlg.narrow { width: min(420px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgb(58 42 34 / 0.45); }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dlg-head h2 { font-size: 21px; }
.dlg-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }

.shift-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.shift-row {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  border-radius: 18px; background: color-mix(in srgb, var(--c) 16%, #fff);
}
.shift-row.editing { box-shadow: 0 0 0 3px var(--teal); }
.shift-main { display: grid; min-width: 0; flex: 1; }
.shift-main .time { font-variant-numeric: tabular-nums; }
.shift-main .note { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 6px; }

.shift-form { display: grid; gap: 12px; padding-top: 16px; border-top: 2px dashed var(--line); }
.shift-form h3 { font-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input, .pill input { accent-color: var(--teal); }
.repeat { display: grid; gap: 10px; padding: 14px; border-radius: 18px; background: var(--sun-soft); }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; font-size: 13px; font-weight: 700;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer;
}
.pill:has(input:checked) { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-ink); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.lock-note { font-size: 13px; color: var(--muted); }

/* ---------- toast ---------- */

#toast {
  position: fixed; inset: auto auto 24px 50%; transform: translateX(-50%); margin: 0;
  padding: 10px 20px; border: none; border-radius: 999px; max-width: min(92vw, 460px);
  background: var(--ink); color: #fff; box-shadow: var(--shadow); font-weight: 700;
}
#toast.err { background: var(--danger); }

/* ---------- phones: the grid becomes a day-by-day list ---------- */

@media (max-width: 720px) {
  .shell { padding: 0 12px 40px; }
  .topbar { padding-top: 12px; }
  .wordmark { font-size: 19px; }
  .logo { width: 40px; height: 40px; }
  .who { order: 2; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .welcome h1 { font-size: 26px; }
  .cal { grid-template-columns: 1fr; gap: 8px; }
  .cal-head, .cell.blank { display: none; }
  .cell { min-height: 0; padding: 10px 14px; }
  .dname { display: inline; }
  .add-hint { opacity: 1; }
  .extra { display: flex; }
  .more { display: none; }
  .chip { font-size: 13.5px; }
  .two-col { grid-template-columns: 1fr; }
  .month-nav { width: 100%; justify-content: space-between; }
  .month-nav h2 { font-size: 21px; }
  .card { padding: 22px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .cell, .tab { transition: background-color 0.12s, border-color 0.12s, transform 0.12s, box-shadow 0.12s; }
}
