:root {
  --red: #b3261e; --ink: #1d1d1f; --mute: #6b7280; --line: #e5e7eb; --bg: #f6f7f9; --card: #fff;
  --day: #fff8e1; --night: #eef0fb; --ok: #1a7f37; --warn: #b45309;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.pad { padding: 16px; }
.mute { color: var(--mute); }
.small { font-size: 12px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 20px 0 8px; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: #c5c9d0; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--red); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
input[type=text], input[type=tel], select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c5c9d0; border-radius: 8px; background: #fff; }

/* shell */
header.top { display: flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header.top .org { font-weight: 700; color: var(--red); margin-right: 12px; }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav button { border-color: transparent; background: none; }
header.top nav button.on { background: var(--ink); color: #fff; }

/* login */
.login { max-width: 380px; width: calc(100% - 32px); margin: min(10vh, 48px) auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; color: var(--red); }
.login button.primary { padding: 12px; font-size: 16px; }
.login form, .stack { display: grid; gap: 8px; }
.login hr { width: 100%; border: 0; border-top: 1px solid var(--line); }

/* schedule */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; flex-wrap: wrap; }
.toolbar .month { font-size: 18px; font-weight: 700; min-width: 150px; text-align: center; }
.toolbar .grow { flex: 1; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #e7f5ea; color: var(--ok); font-weight: 600; }
.badge.draft { background: #fef3c7; color: var(--warn); }
.hint { padding: 0 16px 8px; }
.sched { display: grid; grid-template-columns: 210px 1fr; gap: 12px; padding: 0 16px 24px; align-items: start; }

.people { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; }
.person { display: flex; align-items: center; gap: 4px; width: 100%; text-align: left; border: 0; border-radius: 6px; padding: 6px 8px; background: none; }
.person:hover { background: var(--bg); }
.person.sel { background: var(--ink); color: #fff; }
.person[draggable=true] { cursor: grab; }
.person .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q { font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 4px; background: #e5e7eb; color: #374151; }
.q.emt { background: #d1fae5; color: #065f46; }
.person .n { font-size: 12px; opacity: .7; min-width: 14px; text-align: right; }

.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.grid .dow { font-size: 12px; font-weight: 600; color: var(--mute); text-align: center; padding: 2px; }
.cell { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-height: 118px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; align-content: start; }
.cell.other { opacity: .5; }
.cell.today { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.cell.pref { background: #e7f5ea; }
.cell.unav { background: repeating-linear-gradient(45deg, #fde8e8, #fde8e8 6px, #fbd5d5 6px, #fbd5d5 12px); }
.cell.pick { cursor: pointer; }
.cell .hd { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.cell .hd .wd { display: none; }
.cell .hd .av { margin-left: auto; font-weight: 500; font-size: 11px; }
.wk { margin-left: auto; white-space: nowrap; font-size: 11px; background: var(--ink); color: #fff; border-radius: 99px; padding: 0 6px; }
.wk.full { background: var(--red); }

.shift { border-radius: 6px; padding: 2px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; background: var(--day); border: 1px solid transparent; }
.shift.night { background: var(--night); }
.shift.noemt { border-color: #f59e0b; }
.shift .lbl { font-size: 10px; color: var(--mute); display: flex; justify-content: space-between; padding: 0 2px; white-space: nowrap; overflow: hidden; }
.shift .lbl .w { color: var(--warn); font-weight: 700; }
.slot { display: flex; align-items: center; gap: 3px; min-height: 22px; border-radius: 5px; border: 1px dashed transparent; padding: 0 2px; font-size: 12px; }
.slot .r { font-size: 10px; font-weight: 700; color: var(--mute); width: 10px; }
.slot .empty { color: #9ca3af; }
.slot.ok { border-color: var(--ok); background: #e7f5ea; cursor: pointer; }
.slot.no { opacity: .45; }
.slot.over { outline: 2px solid var(--ok); }
.chip { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; background: #fff; border: 1px solid #d1d5db; border-radius: 5px; padding: 0 2px 0 5px; }
.chip .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.me { border-color: var(--red); font-weight: 700; }
.chip.sel { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.dim { opacity: .35; }
.chip[draggable=true] { cursor: grab; }
.chip .x { border: 0; background: none; padding: 0 3px; color: inherit; opacity: .5; line-height: 1; }
.chip .x:hover { opacity: 1; }
.chip .e { width: 6px; height: 6px; border-radius: 50%; background: #10b981; flex: none; }
/* "My schedule": blank out everyone else */
.only .chip.dim { visibility: hidden; }
.only .slot .empty, .only .shift .lbl .w { display: none; }
.only .shift.noemt { border-color: transparent; }

/* clock */
.clock { max-width: 520px; margin: 24px auto; padding: 0 16px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.clock .big { padding: 18px; font-size: 18px; width: 100%; }
.task { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.task input { width: 20px; height: 20px; accent-color: var(--ok); }
.task.done span { color: var(--mute); text-decoration: line-through; }
.cat { font-size: 12px; font-weight: 700; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 2px; }

/* admin */
.admin { padding: 12px 16px 32px; max-width: 1000px; margin: 0 auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--mute); border-top: 0; }
tr.off td { color: var(--mute); }
td.act { white-space: nowrap; text-align: right; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.list li .t { flex: 1; }
code { font-size: 12px; word-break: break-all; }

dialog { border: 0; border-radius: 14px; padding: 22px; max-height: calc(100dvh - 32px); overflow: auto; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog label { display: grid; gap: 3px; font-size: 13px; color: var(--mute); }
dialog label.chk { display: flex; gap: 6px; align-items: center; color: var(--ink); font-size: 15px; }
dialog textarea { width: 100%; min-height: 90px; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 10; }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.error { background: var(--red); }
.toast.warn { background: var(--warn); }

.chip .short, .cell .hd .wd { display: none; }

/* touch: bigger targets, and 16px inputs so iOS does not zoom on focus */
@media (pointer: coarse), (max-width: 1279px) {
  button, .btn { min-height: 40px; }
  input[type=text], input[type=tel], select, textarea { font-size: 16px; min-height: 40px; }
  .person { min-height: 40px; }
  .slot { min-height: 32px; }
  .chip { min-height: 28px; }
  .chip .x { min-height: 0; padding: 4px 6px; font-size: 16px; }
  .task { padding: 12px 0; }
  .task input { width: 24px; height: 24px; }
  dialog label.chk { padding: 6px 0; }
  dialog label.chk input { width: 22px; height: 22px; flex: none; }
}

/* tablet and small laptops: people strip above a full-width month grid */
@media (max-width: 1279px) {
  .sched { grid-template-columns: minmax(0, 1fr); }
  .people { position: static; display: flex; overflow-x: auto; max-height: none; }
  .person { width: auto; flex: none; }
  table { display: block; overflow-x: auto; }
  /* no room for the EMT dot: show it as a green edge instead */
  .chip .e { display: none; }
  .chip.emt { border-left: 3px solid #10b981; }
  .chip .x { padding: 4px 3px; }
  .slot { gap: 2px; }
  .chip { padding-left: 4px; }
}

/* tablet portrait: compact cells with short names */
@media (max-width: 900px) {
  .sched { padding: 0 8px 24px; gap: 8px; }
  .grid { gap: 3px; }
  .cell { padding: 2px; min-width: 0; }
  .cell .hd { padding: 2px 2px 0; }
  .shift { padding: 1px; }
  .slot { gap: 2px; padding: 0 1px; }
  .slot .r { width: 8px; }
  .chip { padding-left: 4px; }
  .chip .nm { font-size: 11.5px; letter-spacing: -.01em; }
  .chip .full, .hrs, .cell .av { display: none; }
  .chip .short { display: inline; }
  .chip .x { padding: 4px 2px; font-size: 14px; }
}

/* phone: day list, bottom tab bar, tables as cards */
@media (max-width: 640px) {
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  header.top { padding: 8px 12px; flex-wrap: nowrap; }
  header.top .org { flex: 1; }
  header.top nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card);
    border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 6px; }
  header.top nav button { flex: 1; min-height: 46px; font-weight: 600; font-size: 14px; white-space: nowrap; padding: 7px 4px; }
  #toasts { bottom: calc(78px + env(safe-area-inset-bottom)); width: calc(100% - 24px); }

  .toolbar { padding: 10px 12px; }
  .toolbar .month { flex: 1; min-width: 0; }
  .toolbar .month { white-space: nowrap; }
  .toolbar .grow { flex: 0 0 100%; height: 0; }
  .toolbar > button:not([aria-label]) { flex: 1 1 40%; }
  .hint { padding: 0 12px 8px; }
  .sched { padding: 0 12px 16px; gap: 12px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .grid .dow, .cell.other { display: none; }
  .cell { min-height: 0; padding: 8px; gap: 6px; }
  .cell .hd { font-size: 15px; }
  .cell .hd .wd { display: inline; }
  .shift { padding: 4px; gap: 4px; }
  .shift .lbl { font-size: 12px; }
  .hrs, .cell .av { display: inline; }
  .slot { min-height: 40px; font-size: 15px; gap: 6px; }
  .slot .r { font-size: 12px; width: 14px; }
  .chip .nm { font-size: inherit; letter-spacing: 0; }
  .chip { min-height: 36px; padding-left: 10px; }
  .chip .full { display: inline; }
  .chip .short { display: none; }
  .chip .x { padding: 6px 12px; font-size: 20px; }
  .chip .e { display: block; }
  .chip.emt { border-left: 1px solid #d1d5db; }
  .chip.emt.me { border-left-color: var(--red); }
  .chip.emt.sel { border-left-color: var(--ink); }

  .clock { margin: 12px auto; padding: 0 12px; }
  .admin { padding: 12px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px; }
  .tabs button { flex: none; }
  .row input[type=text] { flex: 1 1 100%; }
  .row select { flex: 1; }
  .days > span { flex-basis: 100%; }
  .days { gap: 4px; }
  .days button { flex: 1; padding: 7px 0; }
  .list li { flex-wrap: wrap; }
  .list li .t { flex-basis: 100%; }

  table, tbody, tr, td { display: block; }
  thead { display: none; }
  table { border: 0; background: none; overflow: visible; }
  tr { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
  td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
  td::before { content: attr(data-label); font-size: 12px; color: var(--mute); padding-top: 2px; }
  td:has(> div:empty) { display: none; }
  td.act { display: flex; gap: 8px; text-align: left; padding-top: 8px; }
  td.act::before { display: none; }
  td.act button { flex: 1; }
}

/* print: the whole calendar, or one person's shifts when a name is selected */
.print-title { display: none; }
@media print {
  @page { size: landscape; margin: 8mm; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  body { background: #fff; font-size: 10px; }
  header.top, .toolbar, .hint, .people, #toasts, .chip .x, .wk, .slot .empty, .cell .av { display: none !important; }
  .print-title { display: block; font-size: 16px; margin: 0 0 6px; }
  .sched { display: block; padding: 0; }
  .grid { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
  .grid .dow { display: block; }
  .cell { min-height: 0; break-inside: avoid; background: #fff !important; box-shadow: none !important; border-color: #999; }
  .cell.other { display: grid; opacity: .4; }
  .cell .hd .wd { display: none; }
  .slot, .slot.ok, .slot.no { min-height: 15px; font-size: 10px; opacity: 1; border-color: transparent; background: none; }
  .chip, .chip.sel { background: none; border: 0; color: #000; padding: 0; }
  .chip.sel, .chip.me { font-weight: 700; }
  .chip.dim { visibility: hidden; }
  .chip .full { display: inline; }
  .chip .short { display: none; }
  .chip { min-height: 0; }
  body { padding: 0; }
  .shift .lbl .w { display: none; }
  .shift.noemt { border-color: transparent; }
}
