:root {
  --blue: #005eb8; --blue-dk: #003087; --bg: #f0f4f5; --card: #ffffff; --line: #d8dde0;
  --text: #212b32; --muted: #4c6272; --we: #e8edf3; --we-text: #33475b; --bh: #ffb81c; --bh-text: #6b4600;
  --green: #007f3b; --red: #d5281b; --radius: 10px; --bar-h: 72px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.35;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--bar-h) + 12px + env(safe-area-inset-bottom, 0px));
}
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Sticky header with live progress */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--blue); color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 10px; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.top .row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.top h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }
.top .who { font-size: .85rem; opacity: .95; white-space: nowrap; background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 12px; }
.stats { display: flex; gap: 8px; margin-top: 8px; }
.stat { flex: 1; background: rgba(255,255,255,.14); border-radius: 8px; padding: 6px 8px; font-size: .78rem; line-height: 1.2; }
.stat b { font-size: 1.2rem; display: block; }
.stat.ok { background: rgba(0,127,59,.6); }
.stat.ok b::after { content: " ✓"; font-size: .9rem; }
.top .sub { font-size: .8rem; margin-top: 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; opacity: .95; }

main { padding: 8px 12px 0; }
.hint { font-size: .9rem; color: var(--muted); margin: 6px 2px 10px; }
.banner { background: #fff3cd; color: #5c4400; border: 1px solid #ffe08a; border-radius: 8px; padding: 8px 10px; font-size: .88rem; margin: 4px 0 10px; }
.bhkey { display: inline-block; background: var(--bh); color: var(--bh-text); font-size: .7rem; font-weight: 700; border-radius: 4px; padding: 0 4px; }

/* Most shifts wanted */
.limit { background: var(--card); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.limit-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.limit label { font-weight: 600; font-size: .95rem; }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 46px; min-height: 46px; border: 0; background: #f0f4f5; color: var(--blue); font-size: 1.4rem; font-weight: 700; padding: 0; }
.stepper button:disabled { color: #aeb7bd; }
.stepper input { width: 84px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font: inherit; font-size: 1.1rem; font-weight: 700; color: var(--text); padding: 0 4px; -moz-appearance: textfield; }
.stepper input::placeholder { font-size: .85rem; font-weight: 500; color: var(--muted); }
.limit-hint { margin: 6px 0 0; font-size: .85rem; color: var(--muted); }
.linkish { background: none; border: 0; color: var(--blue); text-decoration: underline; padding: 6px 2px; min-height: 36px; font-size: .85rem; }

/* Month blocks */
.month { background: var(--card); border-radius: var(--radius); padding: 10px 8px 8px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.month > header { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 6px; }
.month h2 { font-size: 1rem; margin: 0; }
.month .bulk { display: flex; gap: 6px; }
.month .bulk button { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; color: var(--blue); font-weight: 600; min-height: 36px; font-size: .85rem; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { text-align: center; font-size: .72rem; color: var(--muted); font-weight: 600; padding: 2px 0; }
.dow.we { color: var(--we-text); }
.day {
  position: relative; min-height: 48px; border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  color: var(--text); font-weight: 600; font-size: 1rem; padding: 0; user-select: none; -webkit-user-select: none;
}
.day.we { background: var(--we); color: var(--we-text); }
.day.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.day.we.on { background: var(--blue-dk); border-color: var(--blue-dk); }
.day.bh { border-left: 4px solid var(--bh); }
.day.bh small { position: absolute; right: 3px; bottom: 3px; font-size: .58rem; font-weight: 700; color: var(--bh-text); background: var(--bh); border-radius: 4px; padding: 0 3px; line-height: 1.3; }
.day.on::before { content: "✓"; position: absolute; left: 5px; top: 3px; font-size: .62rem; opacity: .9; }
.day:disabled { opacity: .28; cursor: default; }
.blank { min-height: 0; }
.pair {
  grid-column: 6 / 8; min-height: 44px; border: 1px dashed var(--blue); background: #eef4fb; color: var(--blue);
  border-radius: 8px; font-size: .78rem; font-weight: 600; line-height: 1.15; padding: 4px 6px;
}
.pair.on { background: var(--green); color: #fff; border-style: solid; border-color: var(--green); }

/* Fixed bottom action bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 1px solid var(--line);
}
.bar button { flex: 1; min-height: 50px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: .88rem; padding: 0 6px; line-height: 1.15; }
.bar .primary { background: var(--green); color: #fff; border-color: var(--green); flex: 1.35; font-size: .95rem; }

/* Toast with undo */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--bar-h) + 10px + env(safe-area-inset-bottom, 0px)); z-index: 7;
  background: #212b32; color: #fff; padding: 10px 6px 10px 14px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.3); font-size: .9rem;
}
.toast button { background: none; border: 0; color: #8fd3ff; font-weight: 700; padding: 6px 10px; min-height: 40px; }

/* Code dialog */
dialog { border: 0; border-radius: 14px; padding: 18px 16px; width: min(92vw, 420px); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 6px; font-size: 1.15rem; }
.code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; word-break: break-all; background: #f0f4f5;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px; user-select: all; -webkit-user-select: all; text-align: center; letter-spacing: .5px; margin-top: 10px;
}
.actions { display: grid; gap: 8px; margin: 14px 0 8px; }
.actions button, .actions a { display: block; text-align: center; text-decoration: none; min-height: 48px; line-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--blue); font-weight: 600; font-size: 1rem; }
.actions .primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; min-height: 44px; width: 100%; }

/* No-link screen */
.nolink { max-width: 420px; margin: 40px auto; padding: 20px; background: #fff; border-radius: var(--radius); }

/* Desktop: months side by side */
@media (min-width: 760px) {
  main { max-width: 1100px; margin: 0 auto; }
  .top .inner { max-width: 1100px; margin: 0 auto; }
  .months { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; align-items: start; }
  .month { margin: 0; }
  .bar { justify-content: center; }
  .bar button { max-width: 240px; }
}
