:root {
  --navy: #14213d;
  --navy-2: #1f3260;
  --gold: #c9a227;
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #667085;
  --line: #e4e7ec;
  --present: #157f3d;   --present-bg: #e6f4ea;
  --absent: #b42318;    --absent-bg: #fdecea;
  --half: #a15c07;      --half-bg: #fef3e2;
  --off: #475467;       --off-bg: #eef0f3;
  --leave: #5b3cc4;     --leave-bg: #efeafd;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --card: #171e2e; --ink: #e8ebf2; --muted: #98a2b3; --line: #273047;
    --present-bg: #12301f; --absent-bg: #3a1714; --half-bg: #35260b; --off-bg: #222a3b; --leave-bg: #2a2147;
    --present: #6fd38f; --absent: #ff8a80; --half: #f5b75b; --off: #b4bccc; --leave: #b6a4ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin-top: 0; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; }
.brand-name { font-weight: 650; letter-spacing: .2px; }
.brand-sub { font-size: 12.5px; opacity: .8; }
.icon-btn { background: transparent; border: 0; font-size: 26px; line-height: 1; padding: 4px 10px; cursor: pointer; color: inherit; border-radius: 10px; }
.icon-btn:active { background: rgba(127,127,127,.18); }

.menu { position: fixed; right: 12px; top: calc(58px + env(safe-area-inset-top)); z-index: 6; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.14); overflow: hidden; }
.menu button { display: block; width: 100%; padding: 12px 18px; background: none; border: 0; text-align: left; cursor: pointer; }
.menu button + button { border-top: 1px solid var(--line); }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 20px; }
.narrow { max-width: 420px; margin: 24px auto; }
h1 { font-size: 21px; margin: 0 0 6px; }
label { display: block; font-size: 13.5px; color: var(--muted); margin: 14px 0 0; }
input { display: block; width: 100%; margin-top: 6px; padding: 12px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: 16px; color: var(--ink); }
input:focus { outline: 2px solid var(--navy-2); outline-offset: 1px; }
button.primary { width: 100%; margin-top: 20px; padding: 13px; border: 0; border-radius: 10px; background: var(--navy);
  color: #fff; font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: .6; }
button.primary.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.link { background: none; border: 0; padding: 0; color: var(--navy-2); font-weight: 600; cursor: pointer; text-decoration: underline; }
@media (prefers-color-scheme: dark) { button.link { color: #9db4ff; } button.primary { background: #2c4687; } }
.switch { margin: 18px 0 0; font-size: 14px; color: var(--muted); }
.error { color: var(--absent); min-height: 1.2em; margin: 10px 0 0; font-size: 14px; }

.tabs { display: flex; gap: 6px; margin-top: 16px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.hr-bar { position: relative; margin-bottom: 12px; }
.hr-bar input { margin: 0; background: var(--card); }
.hr-results { position: absolute; left: 0; right: 0; top: 50px; z-index: 4; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; max-height: 300px; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.hr-results button { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; cursor: pointer; }
.hr-results button + button { border-top: 1px solid var(--line); }
.hr-results small { color: var(--muted); }
.hr-viewing { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 8px; font-size: 14px; }
.hr-viewing span { font-weight: 600; margin-right: auto; }

.month-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px; }
.month-label { font-weight: 650; font-size: 16.5px; }
.month-nav .icon-btn:disabled { opacity: .25; }

.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.present b { color: var(--present); } .stat.absent b { color: var(--absent); }
.stat.half b { color: var(--half); } .stat.leave b { color: var(--leave); }
.sync { font-size: 12.5px; color: var(--muted); margin: 10px 2px; }
.sync.stale { color: var(--half); font-weight: 600; }

.days { display: flex; flex-direction: column; gap: 8px; }
.day { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.day:active { transform: scale(.995); }
.day.today { border-color: var(--gold); box-shadow: inset 3px 0 0 var(--gold); }
.date-block { text-align: center; border-right: 1px solid var(--line); padding-right: 10px; }
.date-block .dd { font-size: 21px; font-weight: 700; line-height: 1.1; }
.date-block .dw { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.day-main { min-width: 0; }
.times { font-weight: 600; font-variant-numeric: tabular-nums; }
.times .sep { color: var(--muted); font-weight: 400; margin: 0 4px; }
.meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.second-row { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); }
.pill { font-size: 12px; font-weight: 650; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.s-present { color: var(--present); background: var(--present-bg); }
.s-absent { color: var(--absent); background: var(--absent-bg); }
.s-half { color: var(--half); background: var(--half-bg); }
.s-off { color: var(--off); background: var(--off-bg); }
.s-leave { color: var(--leave); background: var(--leave-bg); }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.hours { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(10,14,25,.45); z-index: 8; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; max-width: 640px; margin: 0 auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 10px 20px calc(18px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 18px; margin: 0 0 4px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 14px 0; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }
.punches { list-style: none; padding: 0; margin: 8px 0 0; }
.punches li { display: flex; justify-content: space-between; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.punches .t { font-weight: 650; font-variant-numeric: tabular-nums; }
.punches small { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; }
.sheet h3 { font-size: 14px; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; margin: 18px 0 0; }
