:root {
  --ink: #1f2a37;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f5f7;
  --card: #ffffff;
  --accent: #f2a900;       /* safety amber */
  --accent-ink: #1f2a37;
  --blue: #1d4ed8;
  --blue-bg: #e8efff;
  --green: #15803d;
  --green-bg: #e7f6ec;
  --red: #b91c1c;
  --red-bg: #fdecec;
  --amber-bg: #fff6dd;
  --amber: #8a5a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 10px; height: 22px; background: var(--accent); border-radius: 2px; }
.who { margin-left: auto; font-size: 13px; opacity: .85; text-align: right; }
.who b { display: block; font-weight: 600; opacity: 1; }
.tabs {
  max-width: 1200px; margin: 0 auto;
  display: flex; gap: 4px; padding: 0 12px; overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; color: #cbd5e1; cursor: pointer;
  padding: 10px 12px; border-bottom: 3px solid transparent; white-space: nowrap;
  font-weight: 600; font-size: 14px;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  margin-bottom: 14px;
}
.page-head .spacer { flex: 1; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 14px; }
.stack > * + * { margin-top: 12px; }

.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.96); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 1px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid-3 { grid-template-columns: 1fr; } }

.week-nav { display: flex; align-items: center; gap: 6px; }
.week-nav .label { font-weight: 700; min-width: 170px; text-align: center; }

.notice {
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
  background: var(--blue-bg); color: #1e3a8a;
}
.notice.warn { background: var(--amber-bg); color: var(--amber); }
.notice.error { background: var(--red-bg); color: var(--red); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: #eef0f3; color: var(--ink-2);
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }

/* ---------- My week ---------- */
.days { display: grid; gap: 10px; }
.day {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; grid-template-columns: 74px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-left: 5px solid #d1d5db;
}
.day.has-shift { border-left-color: var(--green); }
.day.is-off { border-left-color: var(--blue); }
.day.missing { border-left-color: var(--accent); }
.day.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.day-date .dow { font-weight: 800; font-size: 15px; }
.day-date .dm { color: var(--ink-3); font-size: 13px; }
.day-body .hours { font-weight: 700; font-size: 16px; }
.day-body .site { color: var(--ink-2); }
.day-body .note { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.day-actions { display: flex; gap: 6px; }
@media (max-width: 520px) {
  .day { grid-template-columns: 60px 1fr; }
  .day-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---------- Site schedule grid ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select, .filters input[type=search] { width: auto; min-width: 160px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }

.table-wrap { overflow: auto; max-height: calc(100vh - 220px); border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 900px; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.grid thead th { position: sticky; top: 0; background: #f9fafb; z-index: 2; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-2); }
table.grid th.name, table.grid td.name { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 170px; border-right: 1px solid var(--line); }
table.grid thead th.name { z-index: 3; background: #f9fafb; }
table.grid tr.summary td { background: #fafafa; font-size: 12px; color: var(--ink-2); }
table.grid tr.summary td.name { background: #fafafa; font-weight: 700; }
table.grid td.today, table.grid th.today { background: #fffbeb; }
.cell { border-radius: 6px; padding: 4px 6px; line-height: 1.3; }
.cell.shift { background: var(--green-bg); }
.cell.shift .s { font-weight: 700; color: var(--green); }
.cell.off { background: var(--blue-bg); color: var(--blue); font-weight: 700; }
.cell.missing { background: var(--amber-bg); color: var(--amber); font-weight: 600; }
.cell.dim { opacity: .35; }
.cell.none { color: #c0c4cc; }
.role-tag { font-size: 11px; color: var(--ink-3); display: block; font-weight: 500; }

/* Day roster */
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.roster .card h3 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.roster ul { list-style: none; padding: 0; margin: 0; }
.roster li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.roster li:first-child { border-top: 0; }
.roster li .t { color: var(--ink-3); white-space: nowrap; }

/* ---------- Lists (time off, admin) ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 180px; }
.people-row select { width: auto; min-height: 34px; padding: 4px 8px; }

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .5); z-index: 50;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 480px;
  max-height: calc(100vh - 32px); overflow: auto; padding: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h2 { margin-bottom: 12px; }
.modal .btn-row { justify-content: flex-end; margin-top: 16px; }
.day-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.day-pick { position: relative; }
.day-pick input { position: absolute; opacity: 0; }
.day-pick span {
  display: inline-block; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer; background: #fff; user-select: none;
}
.day-pick input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.day-pick input:disabled + span { opacity: .4; cursor: not-allowed; text-decoration: line-through; }
.day-pick input:focus-visible + span { outline: 2px solid var(--blue); }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }

/* ---------- Login ---------- */
.login { width: 100%; max-width: 380px; }
.login .brand { color: var(--ink); font-size: 22px; margin-bottom: 4px; }
.login .brand-mark { height: 26px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #d1d5db; border-top-color: var(--ink);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .topbar, .filters, .page-head .btn, .week-nav .btn { display: none !important; }
  body { background: #fff; }
  .table-wrap { max-height: none; overflow: visible; box-shadow: none; }
}

/* ---------- v2 additions ---------- */
.tab-count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; line-height: 20px; text-align: center;
}
.pending-line { margin-top: 4px; font-size: 13px; color: var(--amber); background: var(--amber-bg); border-radius: 6px; padding: 3px 8px; display: inline-block; }
.cell.partial { background: #fef3c7; }
.cell.partial .s { color: var(--amber); }
.cell .cnote { font-size: 11px; color: var(--amber); margin-top: 2px; }
.cell.elsewhere { color: #9ca3af; font-size: 12px; font-style: italic; }
table.grid tr.group td { background: var(--ink); color: #fff; font-weight: 700; font-size: 13px; position: static; }
table.grid tr.group td .muted { color: #cbd5e1; }

.bld-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.bld-chip {
  background: #fff; border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
  padding: 10px 16px; text-align: left; min-width: 140px; box-shadow: var(--shadow);
}
.bld-chip:hover { border-color: #cbd5e1; }
.bld-chip.active { border-color: var(--ink); background: var(--ink); color: #fff; }
.bld-chip .bld-name { display: block; font-size: 20px; font-weight: 800; letter-spacing: .5px; }
.bld-chip .bld-meta { display: block; font-size: 12px; opacity: .75; }

.linkish { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--blue); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.req .req-head { margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.req-grid { display: grid; grid-template-columns: 90px 1fr; gap: 4px 12px; font-size: 14px; }

/* ---------- v3 additions ---------- */
.pm { display: inline-block; min-width: 34px; text-align: center; font-size: 12px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-right: 3px; }
.pm.st { background: var(--green-bg); color: var(--green); }
.pm.ot { background: var(--amber-bg); color: var(--amber); }
.pm.dt { background: var(--red-bg); color: var(--red); }
td.paycol { white-space: nowrap; }
.role-tag.nologin { color: var(--amber); }
.day-rules { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
@media (max-width: 760px) { .day-rules { grid-template-columns: repeat(2, 1fr); } }
fieldset.scope { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; margin: 0; }
.bld-chip .bld-meta + .bld-meta { margin-top: 0; }
a.btn { text-decoration: none; color: inherit; }

/* ---------- v4: work calendar ---------- */
.kchip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; white-space: nowrap; line-height: 1.5; }
.kchip.k-st { background: var(--green-bg); color: var(--green); }
.kchip.k-ot { background: var(--amber-bg); color: var(--amber); }
.kchip.k-dt { background: var(--red-bg); color: var(--red); }
.kchip.k-off { background: #eef0f3; color: var(--ink-3); }
.klabel { display: block; font-size: 11px; color: var(--ink-2); font-weight: 600; margin-top: 2px; }
table.grid thead th .kchip { text-transform: none; letter-spacing: 0; margin-top: 3px; }
table.grid thead th .klabel { text-transform: none; letter-spacing: 0; }
.day-date .dk { margin-top: 4px; }
.day.closed { opacity: .7; background: #f8f9fa; }
.pick-kind { display: block; font-size: 10px; font-weight: 600; opacity: .7; }

.cal-weeks { display: grid; gap: 8px; }
.cal-week {
  display: grid; grid-template-columns: 90px 1fr 60px; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; text-align: left; cursor: pointer; font: inherit; color: inherit;
}
.cal-week:hover { border-color: #9ca3af; }
.cal-week.this { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal-wk { font-size: 12px; color: var(--ink-3); }
.cal-wk b { font-size: 15px; color: var(--ink); }
.cal-edit { font-size: 13px; font-weight: 700; color: var(--blue); text-align: right; }
.cal-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { padding: 4px; border-radius: 6px; min-height: 48px; }
.cal-cell.custom { outline: 1.5px dashed #9ca3af; }
.cal-d { font-size: 11px; color: var(--ink-3); margin-bottom: 2px; }
.cal-pto { font-size: 10px; font-weight: 700; color: var(--blue); margin-top: 2px; }
@media (max-width: 760px) {
  .cal-week { grid-template-columns: 1fr; }
  .cal-row { grid-template-columns: repeat(4, 1fr); }
  .cal-edit { text-align: left; }
}

.quick { background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.wd-head, .wd-row { display: grid; grid-template-columns: 80px 150px 1fr 1fr; gap: 8px; align-items: center; }
.wd-head { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .3px; }
.wd-row select, .wd-row input { min-height: 36px; padding: 4px 8px; }
.wd-win { display: flex; align-items: center; gap: 4px; }
.wd-win.disabled { opacity: .35; }
.wd-win span { font-size: 12px; color: var(--ink-3); }
#tpl .wd-head, #tpl .wd-row { grid-template-columns: 60px 150px 1fr; }
@media (max-width: 640px) {
  .wd-head { display: none; }
  .wd-row { grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); padding-top: 8px; }
  .wd-row .wd-win { grid-column: 1 / -1; }
}
.modal:has(#wk), .modal:has(#tpl) { max-width: 780px; }
.day { grid-template-columns: 96px 1fr auto; }
.day-date .kchip { white-space: normal; }
@media (max-width: 520px) { .day { grid-template-columns: 88px 1fr; } }

/* ---------- language switch ---------- */
.lang-switch { display: inline-flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.lang-switch button { border: 0; background: #fff; padding: 8px 14px; font-weight: 600; cursor: pointer; min-height: 38px; }
.lang-switch button.on { background: var(--ink); color: #fff; }
.lang-mini { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: underline; }

/* ---------- schedule change alert ---------- */
.alerts-wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.alerts-wrap:empty { display: none; }
.alert-banner { margin-top: 14px; background: var(--amber-bg); border: 2px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; }
.alert-title { font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.alert-banner ul { margin: 0 0 10px; padding-left: 18px; }
.alert-banner li { margin: 6px 0; font-size: 14px; line-height: 1.45; }
.alert-todo { display: block; color: var(--ink-2); font-size: 13px; }
.alert-todo.warn { color: var(--red); font-weight: 700; }

/* ---------- supervisor adjustments ---------- */
[data-adj] { cursor: pointer; }
td[data-adj]:hover .cell, li[data-adj]:hover { outline: 2px solid var(--blue); outline-offset: -1px; border-radius: 6px; }
.cell.absent { background: var(--red-bg); color: var(--red); font-weight: 800; }
.day.absent { border-left-color: var(--red); }
.adj-line { margin-top: 4px; font-size: 13px; color: var(--red); background: var(--red-bg); border-radius: 6px; padding: 3px 8px; display: inline-block; }
.adj-mini { color: var(--red); }
.adj-now { background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 4px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg label { flex: 1; min-width: 140px; border: 1px solid #d1d5db; border-radius: 8px; padding: 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; font-weight: 600; }
.seg label:has(input:checked) { border-color: var(--ink); background: var(--ink); color: #fff; }

/* ---------- attendance ---------- */
.att-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 640px) { .att-cards { grid-template-columns: repeat(2, 1fr); } }
.att-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
.att-n { font-size: 26px; font-weight: 800; line-height: 1.1; }
.att-l { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.att-card.good .att-n { color: var(--green); }
.att-card.warn .att-n { color: var(--amber); }
.att-card.bad { border-color: #f5c2c2; } .att-card.bad .att-n { color: var(--red); }
table.att-table { min-width: 760px; }
table.att-table tbody tr { cursor: pointer; }
table.att-table tbody tr:hover td { background: #f9fafb; }
.seg-4 label { min-width: 120px; }
.btn.sick { border-color: #f5c2c2; color: var(--red); }
