:root {
  --bg: #f4f6f6;
  --card: #ffffff;
  --ink: #1b2425;
  --muted: #5d6b6d;
  --line: #dde3e3;
  --brand: #0f5e63;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn-bg: #fff4d6;
  --ok: #1f7a3a;
  --ok-bg: #e6f4ea;

  --c-M: #fff1c2;  --c-M-ink: #6b4e00;
  --c-E: #d7e8fb;  --c-E-ink: #12446f;
  --c-N: #e3dcf5;  --c-N-ink: #3d2a78;
  --c-G: #eceff0;  --c-G-ink: #3b4446;
  --c-O: #dff1e3;  --c-O-ink: #1c5b2c;
  --c-L: #fde0dc;  --c-L-ink: #8a1c12;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 72px;
}
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: .95rem; margin: 0 0 .4rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
}
.brand { color: inherit; font-weight: 700; text-decoration: none; }
#nav { display: none; gap: 4px; flex: 1; }
#nav a { color: #d7eeee; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
#nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.topbar .link { margin-left: auto; color: #fff; }
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar a { flex: 1; text-align: center; padding: 10px 2px; font-size: .78rem; color: var(--muted); text-decoration: none; }
#tabbar a.on { color: var(--brand); font-weight: 600; }
#tabbar a .ico { display: block; font-size: 1.15rem; line-height: 1.2; }
@media (min-width: 820px) {
  #nav { display: flex; }
  #tabbar { display: none; }
  body { padding-bottom: 0; }
}

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
main.wide { max-width: none; padding: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 8px 14px; text-decoration: none; display: inline-block;
}
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); border-color: #f1b8b2; }
button.link { background: none; border: 0; padding: 4px; color: var(--brand); text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  font: inherit; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.2em; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: .85rem;
  background: var(--c-G); color: var(--c-G-ink);
}
.code-M { background: var(--c-M); color: var(--c-M-ink); }
.code-E { background: var(--c-E); color: var(--c-E-ink); }
.code-N { background: var(--c-N); color: var(--c-N-ink); }
.code-ME { background: linear-gradient(90deg, var(--c-M) 50%, var(--c-E) 50%); color: var(--c-M-ink); }
.code-O, .code-H { background: var(--c-O); color: var(--c-O-ink); }
.code-leave { background: var(--c-L); color: var(--c-L-ink); }

.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--c-G); color: var(--c-G-ink); }
.badge.pending, .badge.peer_ok { background: var(--warn-bg); color: #7a5200; }
.badge.approved, .badge.published { background: var(--ok-bg); color: var(--ok); }
.badge.rejected, .badge.cancelled { background: var(--danger-bg); color: var(--danger); }
.badge.draft { background: var(--warn-bg); color: #7a5200; }

.alert { border-radius: 10px; padding: 10px 12px; background: var(--warn-bg); color: #5c3d00; }
.alert.bad { background: var(--danger-bg); color: var(--danger); }
.alert.good { background: var(--ok-bg); color: var(--ok); }

/* Staff home */
.hero { background: var(--brand); color: #fff; border-radius: var(--radius); padding: 16px; }
.hero .big { font-size: 1.6rem; font-weight: 700; }
.week { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; cursor: pointer; }
.day.today { outline: 2px solid var(--brand); }
.day .d { font-size: .8rem; color: var(--muted); }
.day .chip { margin: 6px 0 4px; }
.day .team { font-size: .75rem; color: var(--muted); }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .h { text-align: center; font-size: .75rem; color: var(--muted); }
.cal .c { background: var(--card); border: 1px solid var(--line); border-radius: 8px; min-height: 52px; padding: 4px; text-align: center; cursor: pointer; }
.cal .c.today { outline: 2px solid var(--brand); }
.cal .c .n { font-size: .75rem; color: var(--muted); display: block; }
.cal .c .chip { font-size: .75rem; min-width: 0; padding: 1px 6px; }

/* Day board */
.board { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.board .card.short { border-color: #f1b8b2; background: #fffafa; }
.board ul { list-style: none; margin: 0; padding: 0; }
.board li { padding: 5px 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; gap: 8px; }
.board li:last-child { border: 0; }
.count { font-weight: 700; }
.count.bad { color: var(--danger); }
.senior { font-size: .7rem; color: var(--muted); }

/* Roster grid */
.gridwrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); max-height: 75vh; }
table.roster { border-collapse: separate; border-spacing: 0; font-size: .75rem; width: 100%; }
table.roster th, table.roster td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; text-align: center; height: 30px; }
table.roster thead th { position: sticky; top: 0; background: #f8fafa; z-index: 2; font-weight: 600; min-width: 26px; }
table.roster thead th.we { color: var(--danger); }
table.roster .name { position: sticky; left: 0; background: #fff; z-index: 1; text-align: left; padding: 0 6px; white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
table.roster thead .name { z-index: 3; }
table.roster td.cell { cursor: pointer; font-weight: 600; min-width: 26px; letter-spacing: -.02em; }
table.roster td.cell.auto { font-style: italic; opacity: .85; }
table.roster td.cell.pend { box-shadow: inset 0 0 0 2px #e0a100; }
table.roster td.cell.today, table.roster th.today { box-shadow: inset 0 -3px 0 var(--brand); }
table.roster tr.me .name { color: var(--brand); font-weight: 700; }
table.roster tr.cov td { font-weight: 700; background: #fafbfb; }
table.roster tr.cov td.bad { background: var(--danger-bg); color: var(--danger); }
table.roster tr.cov .name { background: #fafbfb; }

.picker {
  position: fixed; z-index: 50; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 8px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; width: 250px;
}
.picker button { padding: 6px 0; font-weight: 600; font-size: .8rem; border-radius: 8px; }
.picker .full { grid-column: 1 / -1; font-weight: 400; }
.picker div.full { margin-top: 4px; }
table.roster td.cell sub, .picker sub { font-size: .7em; line-height: 0; }

.list .item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.list .item:last-child { border: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: .8rem; }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: #1b2425; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60;
}
#toast.show { opacity: 1; }

.login { max-width: 380px; margin: 8vh auto 0; }

@media print {
  .topbar, #tabbar, .noprint, button { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
  .gridwrap { max-height: none; overflow: visible; border: 0; }
  .card { break-inside: avoid; }
}
