:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2430;
  --muted: #667085;
  --border: #e2e5ea;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e3f3f1;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --vacation: #2563eb;
  --sick: #dc2626;
  --special: #7c3aed;
  --unpaid: #6b7280;
  --comp: #d97706;
  --home: #0891b2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #182029;
    --surface-2: #1f2933;
    --text: #e6e9ed;
    --muted: #98a2b3;
    --border: #2a3541;
    --primary: #2dd4bf;
    --primary-ink: #04231f;
    --primary-soft: #133a36;
    --danger: #f87171;
    --danger-soft: #3a1a1a;
    --warn: #fbbf24;
    --warn-soft: #3a2c10;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --info: #93b4ff;
    --info-soft: #1a2647;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 0 0 16px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Layout */
.app { min-height: 100vh; }
.main { padding: 16px 16px calc(var(--nav-h) + 24px); max-width: 1100px; margin: 0 auto; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.brand span { color: var(--primary); }
.who { font-size: .85rem; color: var(--muted); text-align: right; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; min-width: 0;
}
.nav a .ico { font-size: 1.3rem; line-height: 1; }
.nav a.active { color: var(--primary); font-weight: 600; }
.nav .badge { position: relative; }
.nav .dot {
  position: absolute; top: -4px; right: -10px; background: var(--danger); color: #fff;
  font-size: .65rem; border-radius: 9px; padding: 0 5px; min-width: 16px; text-align: center;
}
.nav .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
  .topbar { grid-column: 1 / -1; }
  .nav {
    position: sticky; top: 57px; height: calc(100vh - 57px); flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--border); padding: 12px 8px; gap: 2px;
  }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: .92rem; }
  .nav a.active { background: var(--primary-soft); }
  .nav a.more-link { display: none; }
  .nav .dot { position: static; margin-left: auto; }
  .main { padding: 24px 32px 48px; margin: 0; max-width: 1200px; }
}
@media (max-width: 899px) {
  .nav a.desk-only { display: none; }
}

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 1.35rem; font-weight: 700; }
.stat .k { font-size: .8rem; color: var(--muted); }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* Punch hero */
.hero { text-align: center; padding: 24px 16px; }
.hero .clock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero .state { margin: 6px 0 18px; font-weight: 600; }
.hero .state.in { color: var(--ok); }
.punch-btn {
  width: 100%; max-width: 360px; padding: 20px; border-radius: 16px; border: 0; font-size: 1.15rem; font-weight: 700;
  cursor: pointer; color: #fff; background: var(--ok);
}
.punch-btn.out { background: var(--danger); }
.punch-btn:disabled { opacity: .6; }
.timeline { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 16px; }

/* Chips & tags */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.chip.home { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip.manual { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.tag.vacation { background: var(--info-soft); color: var(--vacation); }
.tag.sick { background: var(--danger-soft); color: var(--sick); }
.tag.special { background: #f1eaff; color: var(--special); }
.tag.unpaid { background: var(--surface-2); color: var(--unpaid); }
.tag.comp { background: var(--warn-soft); color: var(--comp); }
.tag.pending { background: var(--warn-soft); color: var(--warn); }
.tag.approved { background: var(--ok-soft); color: var(--ok); }
.tag.rejected, .tag.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.tag.in { background: var(--ok-soft); color: var(--ok); }
.tag.in_home { background: var(--info-soft); color: var(--home); }
.tag.out, .tag.off { background: var(--surface-2); color: var(--muted); }
.tag.absent, .tag.flag { background: var(--danger-soft); color: var(--danger); }
.tag.holiday { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .tag.special { background: #2a1f45; } }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.weekend td { background: var(--surface-2); color: var(--muted); }
tr.today td { background: var(--primary-soft); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* Day list (mobile month) */
.days { list-style: none; margin: 0; padding: 0; }
.days li { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: start; }
.days li.weekend { opacity: .6; }
.days li.today { background: var(--primary-soft); border-radius: 8px; padding-left: 6px; padding-right: 6px; }
.days .d { font-weight: 700; }
.days .d small { display: block; font-weight: 400; color: var(--muted); }
.days .pairs { display: flex; flex-wrap: wrap; gap: 4px; }
.days .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: auto; margin-right: 8px; transform: scale(1.2); }
.check { display: flex; align-items: center; font-weight: 500; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { margin: 0; display: flex; align-items: center; font-weight: 500; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h1 { margin: 0; }
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav strong { min-width: 120px; text-align: center; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }
.login .brand { font-size: 1.3rem; text-align: center; margin-bottom: 4px; }

/* Messages */
.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .9rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--info-soft); color: var(--info); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 50;
  background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 1.2rem; padding: 10px; background: var(--surface-2); border-radius: 8px; text-align: center; user-select: all; }

/* Dialog */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100% - 24px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .dlg { padding: 18px; max-height: 85vh; overflow: auto; }

/* List items */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.person { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: inherit; }
.person .n { font-weight: 600; }

/* Team calendar */
.cal { border-collapse: separate; border-spacing: 2px; font-size: .75rem; }
.cal th, .cal td { padding: 0; border: 0; text-align: center; min-width: 24px; height: 26px; }
.cal th.name, .cal td.name { text-align: left; padding-right: 8px; white-space: nowrap; font-size: .85rem; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.cal td.c { background: var(--surface-2); border-radius: 4px; }
.cal td.c.off { background: transparent; }
.cal td.c.vacation { background: var(--vacation); }
.cal td.c.sick { background: var(--sick); }
.cal td.c.special { background: var(--special); }
.cal td.c.unpaid { background: var(--unpaid); }
.cal td.c.comp { background: var(--comp); }
.cal td.c.pending { opacity: .45; }
.cal td.c.half { background-image: linear-gradient(135deg, transparent 50%, var(--surface) 50%); }
.cal th.we { color: var(--muted); }
.cal th.hol { color: var(--primary); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: .8rem; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend i.vacation { background: var(--vacation); }
.legend i.sick { background: var(--sick); }
.legend i.special { background: var(--special); }
.legend i.unpaid { background: var(--unpaid); }
.legend i.comp { background: var(--comp); }
.legend i.pending { background: var(--vacation); opacity: .45; }

.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.mt { margin-top: 16px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.spinner { text-align: center; padding: 40px; color: var(--muted); }
pre.audit { white-space: pre-wrap; word-break: break-word; font-size: .78rem; margin: 0; color: var(--muted); }
.mt-xs { margin-top: 4px; }
.center { text-align: center; }
.row > div { min-width: 0; }
input[type=date], input[type=time] { min-width: 0; -webkit-appearance: none; appearance: none; min-height: 44px; }
.chip .btn { padding: 0 2px 0 4px; border: 0; min-height: 0; font-size: .75rem; color: var(--muted); }

/* Branding */
.logo { display: block; height: auto; }
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 600; min-width: 0; }
.topbar .brand .logo { width: 92px; }
.topbar .brand span { color: var(--muted); font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 10px; border-left: 1px solid var(--border); }
.login-brand { text-align: center; margin-bottom: 8px; }
.login-brand .logo { width: 170px; margin: 4px auto 10px; }
.login-brand .app-title { font-size: 1.15rem; font-weight: 600; letter-spacing: .01em; }
@media (prefers-color-scheme: dark) { .logo { filter: invert(1); } }
@media (max-width: 420px) { .topbar .brand span { font-size: .8rem; } .topbar .who { display: none; } }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
td select { width: auto; min-width: 120px; padding: 6px 8px; }
.toolbar .actions { margin-top: 0; }

/* Day details */
.days li { grid-template-columns: 54px 1fr; }
.chip.pair { gap: 2px; padding: 3px 6px; }
.chip.pair .pt { display: inline-flex; align-items: center; border-radius: 6px; padding: 0 2px; }
.chip.pair .pt.home { color: var(--info); }
.chip.pair .pt.manual { color: var(--warn); }
.chip.pair .dash { color: var(--muted); }
.chip .x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .7rem; padding: 0 2px 0 3px; line-height: 1; }
.chip .x:hover { color: var(--danger); }
.daysum { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: .85rem; font-variant-numeric: tabular-nums; }
.daysum .k { color: var(--muted); }
.dayactions { display: flex; gap: 4px; margin-top: 4px; }
.dayactions .btn { padding: 2px 8px; font-size: .78rem; font-weight: 500; color: var(--muted); }
input.inline { padding: 5px 8px; border-radius: 8px; font-size: .88rem; }
input.inline.email { min-width: 200px; }
input.inline.hours { width: 70px; }
input.inline.saved { outline: 2px solid var(--ok); }

/* Day filter */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fchip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.fchip .cnt { color: var(--muted); font-size: .78rem; margin-left: 2px; }
.fchip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.fchip.on .cnt { color: inherit; opacity: .8; }
.fchip.f-missing:not(.on), .fchip.f-incomplete:not(.on) { color: var(--danger); }
.fchip.f-pending:not(.on) { color: var(--warn); }

/* Help */
details.help { border-bottom: 1px solid var(--border); }
details.help:last-child { border-bottom: 0; }
details.help summary { cursor: pointer; padding: 12px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
details.help summary::-webkit-details-marker { display: none; }
details.help summary::after { content: '+'; color: var(--muted); font-weight: 400; }
details.help[open] summary::after { content: '−'; }
details.help ul { margin: 0 0 12px; padding-left: 20px; }
details.help li { margin-bottom: 6px; }

/* Range calendar */
.rcal { margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.rc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.rc-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.rc-wd { text-align: center; font-size: .72rem; color: var(--muted); font-weight: 600; padding: 2px 0; }
.rc-day { height: 38px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; position: relative; }
.rc-day:hover { outline: 2px solid var(--primary); }
.rc-day.we { background: transparent; color: var(--muted); }
.rc-day.hol { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.rc-day.today { box-shadow: inset 0 0 0 2px var(--text); }
.rc-day.busy::after { content: ''; position: absolute; left: 25%; right: 25%; bottom: 4px; height: 3px; border-radius: 2px; background: var(--vacation); }
.rc-day.busy.sick::after { background: var(--sick); }
.rc-day.busy.special::after { background: var(--special); }
.rc-day.busy.unpaid::after { background: var(--unpaid); }
.rc-day.busy.comp::after { background: var(--comp); }
.rc-day.busy.pend::after { opacity: .45; }
.rc-day.sel { background: var(--primary); color: var(--primary-ink); }
.rc-day.sel.we, .rc-day.sel.hol { background: color-mix(in srgb, var(--primary) 45%, var(--surface)); color: var(--primary-ink); }
.rc-hols { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: .8rem; color: var(--primary); }
.rc-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .75rem; color: var(--muted); }
.rc-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.rc-legend i.sel { background: var(--primary); }
.rc-legend i.hol { background: var(--primary-soft); border: 1px solid var(--primary); }
.rc-legend i.busy { background: var(--vacation); height: 3px; vertical-align: 2px; }
#rangeInfo { margin-top: 6px; }
.basics h3 { margin: 14px 0 6px; font-size: .95rem; color: var(--primary); }
.basics h3:first-of-type { margin-top: 4px; }
.basics ol { margin: 0 0 4px; padding-left: 22px; }
.basics li { margin-bottom: 6px; }
.langs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.card .langs { justify-content: flex-start; }
.langs .btn.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.person.me { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.tag.vacation, .tag.sick { white-space: nowrap; }
td input[type=checkbox].inline { transform: scale(1.3); cursor: pointer; }
td input[type=checkbox].inline:disabled { cursor: not-allowed; opacity: .35; }
