:root {
  --paper: #f3f4f2;
  --sheet: #ffffff;
  --ink: #1c2320;
  --ink-2: #4a5550;
  --ink-3: #74807a;
  --rule: #d9ddd9;
  --rule-soft: #e9ece9;
  --blue: #1f4e79;
  --blue-2: #2a63a0;
  --blue-tint: #e3ecf5;
  --amber: #d99a12;
  --amber-ink: #7a5300;
  --amber-tint: #fcf1d3;
  --green: #2e7d4f;
  --green-tint: #dff0e5;
  --red: #b23a2e;
  --red-tint: #f8e1dd;
  --radius: 4px;
  --rail: 232px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums lining-nums;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.shell > * { min-width: 0; }
.rail {
  background: var(--sheet);
  border-right: 1px solid var(--rule);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; padding: 4px 10px 18px; color: var(--ink); }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px; border-radius: var(--radius); color: var(--ink-2);
}
.nav a:hover { background: var(--paper); text-decoration: none; }
.nav a.active { background: var(--blue-tint); color: var(--blue); font-weight: 600; }
.nav .count { font-size: 12px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.nav .count.amber { background: var(--amber-tint); color: var(--amber-ink); }
.nav .count.blue { background: var(--blue-tint); color: var(--blue); }
.rail .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--rule-soft); font-size: 13px; color: var(--ink-2); }
.rail .me b { display: block; color: var(--ink); font-weight: 600; }
.rail .me button { margin-top: 8px; }

.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; min-width: 0; }
.topbar { display: none; }

@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--sheet); border-bottom: 1px solid var(--rule);
    position: sticky; top: 0; z-index: 5;
  }
  .topbar .brand { padding: 0; font-size: 16px; }
  .topbar .brand small { display: none; }
  .main { padding: 16px 16px 90px; }
  .tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--sheet); border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { padding: 10px 4px 8px; text-align: center; font-size: 12px; color: var(--ink-2); position: relative; }
  .tabbar a.active { color: var(--blue); font-weight: 600; }
  .tabbar a .count { position: absolute; top: 4px; right: 18%; font-size: 10px; font-weight: 700; background: var(--amber); color: #fff; border-radius: 8px; padding: 0 5px; }
}
@media (min-width: 781px) { .tabbar { display: none; } }

/* ---------- type & bits ---------- */
h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 10px; }
h2 small { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.lede { color: var(--ink-2); margin: 0 0 18px; max-width: 70ch; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 8px; }
.ok { color: var(--green); }
.bad { color: var(--red); }
.warn { color: var(--amber-ink); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--rule); background: var(--sheet); cursor: pointer; line-height: 1.2;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--blue-2); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--blue); padding: 0; }
.btn.link:hover { text-decoration: underline; }

.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--ink-2); }
.field input, .field select, .field textarea {
  min-width: 0;
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet); width: 100%;
}
.field textarea { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 10px;
  background: var(--rule-soft); color: var(--ink-2); white-space: nowrap;
}
.chip.blue { background: var(--blue-tint); color: var(--blue); }
.chip.amber { background: var(--amber-tint); color: var(--amber-ink); }
.chip.green { background: var(--green-tint); color: var(--green); }
.chip.red { background: var(--red-tint); color: var(--red); }
.chip.ink { background: var(--ink); color: #fff; }

.notice { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--rule); background: var(--sheet); margin: 0 0 16px; }
.notice.amber { background: var(--amber-tint); border-color: #f0d38a; color: var(--amber-ink); }
.notice.red { background: var(--red-tint); border-color: #e6b1aa; color: var(--red); }
.notice.green { background: var(--green-tint); border-color: #b9dcc6; color: var(--green); }

.empty { padding: 28px 16px; text-align: center; color: var(--ink-3); border: 1px dashed var(--rule); border-radius: var(--radius); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule-soft); }
.table th { font-size: 12.5px; font-weight: 600; color: var(--ink-2); background: #fafbfa; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f7f9fb; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 16px; }
.filters button {
  padding: 6px 12px; border-radius: 16px; border: 1px solid var(--rule); background: var(--sheet); cursor: pointer; color: var(--ink-2);
}
.filters button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.search { padding: 8px 12px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet); min-width: 240px; }

/* ---------- weeks board ---------- */
.weeks { display: grid; gap: 10px; }
.week-row {
  display: grid; grid-template-columns: 112px 1fr auto; gap: 16px; align-items: center;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px;
  color: inherit;
}
.week-row:hover { text-decoration: none; border-color: var(--ink-3); }
.stamp { line-height: 1; }
.stamp .cw { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stamp .cw span { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-right: 4px; letter-spacing: 0; }
.stamp .dates { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; white-space: nowrap; }
.week-mid { min-width: 0; }
.week-mid .line1 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.week-mid .site { font-weight: 600; }
.week-mid .counts { font-size: 13px; color: var(--ink-2); margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; }
.week-mid .counts b { font-weight: 600; color: var(--ink); }
.rail-bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; width: 160px; }
.rail-bar i { height: 6px; border-radius: 3px; background: var(--rule); }
.rail-bar i.on { background: var(--blue); }
.rail-bar i.done { background: var(--green); }
.rail-label { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; text-align: right; }
@media (max-width: 600px) {
  .week-row { grid-template-columns: 96px 1fr; }
  .week-row .week-end { grid-column: 1 / -1; }
  .rail-bar { width: 100%; }
  .rail-label { text-align: left; }
}

/* ---------- week detail ---------- */
.week-head { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 8px; }
.week-head .stamp .cw { font-size: 40px; }
.week-head .meta { display: grid; gap: 4px; color: var(--ink-2); }
.week-head .meta b { color: var(--ink); font-size: 18px; font-weight: 600; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin: 18px 0 16px; overflow-x: auto; }
.tabs button { padding: 9px 12px; border: 0; background: none; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.tabs button .count { margin-left: 6px; font-size: 12px; color: var(--ink-3); }
.tabs button .count.amber { color: var(--amber-ink); font-weight: 700; }

.flag { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 14px; background: var(--sheet); border: 1px solid var(--rule); border-left: 3px solid var(--amber); border-radius: var(--radius); }
.flag.resolved { border-left-color: var(--green); }
.flag.waived { border-left-color: var(--ink-3); }
.flag .stack { align-content: start; justify-items: end; }
.flag .who { font-weight: 600; }
.flag .reason { margin-top: 2px; }
.flag .sub { font-size: 13px; color: var(--ink-3); margin-top: 4px; }

.doc { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.doc .name { font-weight: 500; overflow-wrap: anywhere; }
.doc .sub { font-size: 13px; color: var(--ink-3); }

.comment { padding: 10px 14px; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.comment .by { font-size: 13px; color: var(--ink-3); margin-bottom: 3px; }
.comment .body { white-space: pre-wrap; overflow-wrap: anywhere; }

.hours-table td.h { text-align: right; min-width: 44px; }
.hours-table td.h.ot { color: var(--amber-ink); }
.hours-table td.h.leave { color: var(--ink-3); font-style: italic; }
.hours-table td.h.flagged { background: var(--amber-tint); }

/* ---------- inbox ---------- */
.mail { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; }
.mail .subject { font-weight: 600; overflow-wrap: anywhere; }
.mail .from { font-size: 13px; color: var(--ink-2); }
.mail .reasons { font-size: 13px; color: var(--amber-ink); display: grid; gap: 2px; }
.mail .atts { font-size: 13px; color: var(--ink-3); overflow-wrap: anywhere; }
.mail .file-form { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--rule-soft); display: grid; gap: 10px; }

/* ---------- rates ---------- */
.rate-group { margin-bottom: 22px; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(28,35,32,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; padding: 0; }
@media (min-width: 600px) { .modal-back { align-items: center; padding: 20px; } }
.modal { background: var(--sheet); border-radius: 8px 8px 0 0; padding: 20px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; display: grid; gap: 14px; }
@media (min-width: 600px) { .modal { border-radius: 8px; } }
.modal h3 { margin: 0; font-size: 17px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--red); }
@media (max-width: 780px) { .toast { bottom: 76px; } }

/* ---------- sign in ---------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin .card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 32px 28px; width: 100%; max-width: 420px; display: grid; gap: 16px; }
.signin h1 { margin: 0; }
.signin p { margin: 0; color: var(--ink-2); }
.ms-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 11px 16px; border-radius: var(--radius); background: var(--ink); color: #fff; border: 0; cursor: pointer; font-weight: 600; }
.ms-btn:hover { background: #2a332f; }
.ms-btn svg { width: 18px; height: 18px; }

.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.health { font-size: 13px; color: var(--ink-3); margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--rule-soft); }
.health b { color: var(--ink-2); font-weight: 600; }
