:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #17202b;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --brand: #1f3a5f;
  --brand-2: #2d5b91;
  --accent: #e8a317;
  --ok: #1e8a4c;
  --warn: #b26a00;
  --bad: #c62828;
  --weekend: #eceff3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #19202a; --surface-2: #222b37; --text: #e8edf3; --muted: #9aa8b8;
    --line: #2e3a48; --brand: #8fb6e8; --brand-2: #a9c8f0; --weekend: #1d252f;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #1f3a5f; color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { font-size: 13px; opacity: .85; }
.topbar button { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.tabs { display: flex; gap: 4px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; padding: 12px 12px; cursor: pointer; color: var(--muted); font-weight: 600;
  border-bottom: 3px solid transparent; white-space: nowrap; position: relative;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; text-align: center; margin-left: 4px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
main.wide { max-width: none; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.hero { background: #1f3a5f; color: #fff; border-color: #1f3a5f; }
.stat.hero .k, .stat.hero .s { color: rgba(255,255,255,.8); }
.bar { height: 8px; background: rgba(255,255,255,.25); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 4px; }
.action { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 14px 10px; cursor: pointer; text-align: center; font-weight: 600; box-shadow: var(--shadow); }
.action .ic { display: block; font-size: 24px; margin-bottom: 4px; }
.action:hover { border-color: var(--brand-2); }
@media (max-width: 420px) { .action { font-size: 13px; padding: 12px 6px; } }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: #1f3a5f; border-color: #1f3a5f; color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea, input.in {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--surface); padding: 10px 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #1f3a5f; color: #fff; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.item .main { flex: 1; min-width: 200px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; border: 1px solid transparent; }
.pill.pending { background: #fff4d6; color: #7a5200; }
.pill.approved { background: #dff3e6; color: #12603a; }
.pill.rejected { background: #fde2e2; color: #9b1c1c; }
.pill.cancelled { background: var(--surface-2); color: var(--muted); }
.code { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 4px; border-radius: 5px; font-size: 12px; font-weight: 700; color: #111; }
.warn { color: var(--warn); font-size: 13px; }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* tables */
.tablewrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 190px); }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.t th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--muted); z-index: 1; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.sec td { background: var(--surface-2); font-weight: 700; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
.neg { color: var(--bad); font-weight: 700; }

/* planner grid */
.planner { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.planner th, .planner td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; text-align: center; }
.planner td.d { width: 30px; min-width: 30px; height: 28px; cursor: pointer; font-weight: 700; color: #111; }
.planner td.d:hover { outline: 2px solid var(--brand-2); outline-offset: -2px; }
.planner td.we { background: var(--weekend); }
.planner td.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.planner .nm { position: sticky; left: 0; background: var(--surface); text-align: left; padding: 0 10px; white-space: nowrap; z-index: 2; min-width: 170px; font-weight: 500; font-size: 13px; }
.planner .nm.leaver { color: var(--muted); font-style: italic; }
.planner thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 3; padding: 4px 0; font-size: 11px; }
.planner thead th.nm { z-index: 4; }
.planner thead th.today { background: var(--accent); color: #111; }
.planner tr.sec th { background: #1f3a5f; color: #fff; text-align: left; padding: 6px 10px; position: sticky; left: 0; font-size: 13px; }
.planner tr.cnt td { font-size: 11px; color: var(--muted); height: 20px; background: var(--surface-2); }
.planner tr.cnt td.over { background: #fde2e2; color: #9b1c1c; font-weight: 700; }
.planner td.tot { padding: 0 8px; font-variant-numeric: tabular-nums; background: var(--surface-2); min-width: 44px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin: 10px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* calendar (profile) */
.cal { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.month h3 { margin: 0 0 6px; font-size: 14px; }
.month .g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: 11px; text-align: center; }
.month .g b { color: var(--muted); font-weight: 600; }
.month .g i { font-style: normal; padding: 4px 0; border-radius: 4px; }
.month .g i.we { color: var(--muted); }
.month .g i.c { color: #111; font-weight: 700; }
.month .g i.today { outline: 2px solid var(--brand-2); }

/* training / college: striped so it reads as "not leave" (never counted against holiday) */
.tr-training { background: repeating-linear-gradient(135deg, #a9dcd1 0 5px, #e3f5f0 5px 10px) !important; color: #0b4d40 !important; }
.tr-college { background: repeating-linear-gradient(135deg, #f3c2a8 0 5px, #fdebe2 5px 10px) !important; color: #7a3410 !important; }
.tr-also { box-shadow: inset 0 -4px 0 #2a9d8f; }
.tr-clash { outline: 2px dashed var(--bad); outline-offset: -3px; }
.notice { border-left: 4px solid var(--brand-2); }
.warn-box { border-left: 4px solid var(--warn); background: #fff4dd; color: #4d3200; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .warn-box { background: #3a2c10; color: #ffdca6; } }
details summary { cursor: pointer; color: var(--brand-2); }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 25, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 20px 16px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal { border-radius: 16px; padding: 22px; } }
.modal h2 { margin-top: 0; }
.modal .foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.picker button { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px; cursor: pointer; text-align: left; font-size: 13px; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #17202b; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

/* login */
.login { max-width: 400px; margin: 8vh auto; padding: 16px; }
.login .logo { width: 56px; height: 56px; border-radius: 14px; background: #1f3a5f; color: #fff; display: grid; place-items: center; font-size: 28px; margin-bottom: 12px; }
.pinslips { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.pinslips div { border: 1px dashed var(--line); padding: 10px; border-radius: 8px; }
@media print {
  .topbar, .tabs, .noprint { display: none !important; }
  body { background: #fff; }
}
