:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #5d6b7c;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e0f2ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --info-soft: #e8f0fe;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1e252e;
    --border: #2c3540;
    --text: #e6eaef;
    --muted: #9aa7b5;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-soft: #123a36;
    --danger: #f97066;
    --danger-soft: #3b1714;
    --warn: #f5c451;
    --warn-soft: #3a2e0c;
    --ok: #4ade80;
    --ok-soft: #12311c;
    --info-soft: #172a45;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.danger { color: var(--danger); }
.mt { margin-top: 1rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .92em; }

/* Layout */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 1.5rem; min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--surface);
  display: grid; place-items: center; font-size: .8rem; font-weight: 800;
}
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--muted); padding: .4rem .7rem; border-radius: 6px; font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.userbox { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 440px; margin: 8vh auto; padding: 0 16px; }
.guest-brand { justify-content: center; font-size: 1.15rem; margin-bottom: 1.25rem; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: .25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: .5rem; }
.card-head h2 { margin: 0; }
.stack > * + * { margin-top: 1rem; }

.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: .85rem; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 1rem 0; }

dl.details { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: .5rem 1.25rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }

/* Badges */
.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--accent); }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); }

/* Forms */
form.inline { display: inline; }
.field { margin-bottom: 1rem; }
.field label, .label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
.field .help { font-size: .82rem; color: var(--muted); margin-top: .25rem; }
.field .error { font-size: .85rem; color: var(--danger); margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local],
input[type=number], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 100px; resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-bottom: .5rem; }
.check input { width: auto; }
.checks { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.form-row { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem .25rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--surface); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.link { background: none; border: 0; color: var(--muted); padding: 0; font-weight: 500; }
.btn.link:hover { color: var(--text); text-decoration: underline; }

.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.qr { background: #fff; padding: 12px; border-radius: var(--radius); display: inline-block; }
.qr svg { display: block; width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .35rem 1rem; font-family: ui-monospace, Consolas, monospace; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 180px; }

.pagination { display: flex; gap: .25rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-size: .9rem;
}
.pagination .current { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.pagination .disabled { color: var(--muted); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 1rem 1rem; position: relative; }
.timeline li::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  position: absolute; left: -6px; top: .4rem;
}
.timeline .when { font-size: .82rem; color: var(--muted); }
.timeline .notes { white-space: pre-line; margin-top: .25rem; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: .5rem; align-items: baseline; padding: .25rem 0; }
.checklist .tick { color: var(--ok); font-weight: 700; }
.checklist .cross { color: var(--muted); font-weight: 700; }

/* Leave calendar */
.cal { font-size: .8rem; border-collapse: separate; border-spacing: 0; }
.cal th, .cal td { padding: 0; text-align: center; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal th { padding: .3rem 0; min-width: 28px; text-transform: none; letter-spacing: 0; }
.cal th.name, .cal td.name { text-align: left; padding: .35rem .6rem; min-width: 180px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.cal td { height: 30px; }
.cal .we { background: var(--surface-2); }
.cal .hol { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, var(--surface) 4px, var(--surface) 8px); }
.cal .today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .lv { background: var(--accent); color: var(--surface); font-weight: 700; }
.cal .lv.pending { background: var(--warn-soft); color: var(--warn); }
.cal .lv.other { background: var(--info-soft); color: var(--text); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: .75rem; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.legend .l-approved::before { background: var(--accent); }
.legend .l-pending::before { background: var(--warn-soft); border: 1px solid var(--warn); }
.legend .l-other::before { background: var(--info-soft); }
.legend .l-hol::before { background: var(--surface-2); border: 1px dashed var(--muted); }

@media (max-width: 720px) {
  .topbar-inner { gap: .5rem; padding-top: .5rem; padding-bottom: .5rem; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 1 1 100%; overflow-x: auto; flex-wrap: nowrap; }
  dl.details { grid-template-columns: 1fr; gap: .1rem; }
  dl.details dd { margin-bottom: .5rem; }
}
