:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-ink: #fff; --accent-soft: #dbeafe;
  --ok: #16a34a; --ok-soft: #dcfce7;
  --warn: #d97706; --warn-soft: #fef3c7;
  --danger: #dc2626; --danger-soft: #fee2e2;
  --line-strong: #cbd5e1; --on-solid: #fff;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #181c24; --text: #e5e7eb; --muted: #9aa3b2; --line: #2b313c;
  --accent: #60a5fa; --accent-ink: #0b1220; --accent-soft: #1b3150;
  --ok: #4ade80; --ok-soft: #12301d;
  --warn: #fbbf24; --warn-soft: #362709;
  --danger: #f87171; --danger-soft: #3a1717;
  --line-strong: #47505e; --on-solid: #0f1218;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.05rem; } h3 { font-size: .9rem; margin-top: .9rem; color: var(--muted); }
.en { color: var(--muted); font-weight: 400; }
input, select, textarea { color: var(--text); background-color: var(--card); }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--muted); cursor: pointer; }
.theme-toggle:hover { color: var(--text); border-color: var(--line-strong); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: none; }
:root:not([data-theme-choice]) .icon-system, [data-theme-choice=system] .icon-system, [data-theme-choice=light] .icon-light, [data-theme-choice=dark] .icon-dark { display: block; }
code { font-size: .85em; background: var(--bg); padding: 0 .3em; border-radius: 4px; }
body { font-size: 14px; line-height: 1.4; }
h1 { font-size: 1.25rem; } h2 { font-size: .95rem; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .error { color: var(--danger); } .ok { color: var(--ok); margin: 0; }

/* ---- app shell ---- */
body.with-sidebar { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); padding: .9rem .7rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); padding: .2rem .5rem .9rem; font-size: 1rem; }
.brand img { border-radius: 6px; }
.side-nav { display: flex; flex-direction: column; gap: .15rem; }
.side-nav a { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: 8px; color: var(--text); font-size: .9rem; }
.side-nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.side-nav a:hover { background: var(--bg); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav a.active svg { color: var(--accent); }
.side-nav a .ext { margin-left: auto; color: var(--muted); font-size: .8rem; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: .7rem; display: flex; flex-direction: column; gap: .6rem; }
.me { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.me-text strong { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-tools { display: flex; align-items: center; justify-content: space-between; }
.content { padding: 1.2rem 1.6rem 2rem; max-width: 1180px; width: 100%; }
@media (max-width: 860px) {
  body.with-sidebar { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: .5rem; padding: .5rem .8rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 .4rem 0 0; }
  .side-nav { flex-direction: row; }
  .side-nav a span { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; align-items: center; }
  .me-text { display: none; }
  .content { padding: .8rem; }
}
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; gap: .8rem; align-items: center; }
.lang-switch { display: inline-flex; gap: .3rem; align-items: center; font-size: .8rem; }
.lang-switch a { color: var(--muted); font-weight: 600; }
.lang-switch a.active { color: var(--accent); }
.page { padding: 1rem; max-width: 1100px; margin: 0 auto; }
.footer { max-width: 1100px; margin: 1rem auto 0; padding: 1rem; font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; border-top: 1px solid var(--line); }

.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: .8rem; }
.avatar.md { width: 34px; height: 34px; font-size: .85rem; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.4rem; }

/* ---- page header ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .85rem; margin: .1rem 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem; }
.card + .card, .card + form, form + .card { margin-top: .8rem; }
.login { max-width: 440px; margin: 4rem auto; text-align: center; }
.login .btn { margin-top: .5rem; }

.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: .4rem .8rem; border-radius: 6px; cursor: pointer; font: inherit; font-size: .85rem; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.file-btn { position: relative; }

/* ---- forms ---- */
fieldset { border: 0; border-top: 1px solid var(--line); margin: 1rem 0 0; padding: .7rem 0 0; }
legend { font-weight: 600; padding: 0 .4rem 0 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem 1rem; }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.field label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea { font: inherit; padding: .38rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field .hint { color: var(--muted); font-size: .75rem; }
.field .field-error { color: var(--danger); font-size: .75rem; min-height: 1em; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.is-valid input, .field.is-valid select { border-color: var(--ok); }
.field.doc { grid-column: 1 / -1; }
.field.doc.has-file > label::after { content: " ✓"; color: var(--ok); }
.money { position: relative; }
.money input { padding-right: 2rem; text-align: right; font-variant-numeric: tabular-nums; }
.money .unit { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.doc-list { list-style: none; margin: .2rem 0 .4rem; padding: 0; font-size: .85rem; }
.doc-list li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.doc-list li:last-child { border-bottom: 0; }
.doc-list .rm { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.doc-list .rm:hover { color: var(--danger); }
.doc-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.doc-current { flex: 1; min-width: 160px; }
.actions { margin-top: 1rem; display: flex; gap: .6rem; align-items: center; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .88rem; }
th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: var(--bg); }
td .btn + .btn { margin-left: .3rem; }
.row-actions { white-space: nowrap; text-align: right; }
.person-cell { display: flex; align-items: center; gap: .6rem; }
.person-cell .sub { color: var(--muted); font-size: .78rem; }
.empty { text-align: center; padding: 2.5rem 1rem; }
.empty p { margin: .2rem 0 .8rem; }

.chip { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.chip.status-invited, .chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.status-submitted, .chip.link-pending { background: var(--accent-soft); color: var(--accent); }
.chip.complete, .chip.link-used { background: var(--ok-soft); color: var(--ok); }
.chip.status-added, .chip.link-expired, .chip.link-none { background: var(--line); color: var(--muted); }
.missing-list { margin-top: .15rem; max-width: 220px; }

/* ---- directory ---- */
.filters { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.filters input[type=search] { flex: 1; min-width: 200px; max-width: 340px; font: inherit; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 6px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { font: inherit; font-size: .8rem; padding: .35rem .65rem; border: 0; background: var(--card); color: var(--muted); cursor: pointer; border-left: 1px solid var(--line); }
.segmented button:first-child { border-left: 0; }
.segmented button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.add-user { display: flex; gap: .5rem; margin-top: .8rem; flex-wrap: wrap; }
.add-user input { flex: 1; font: inherit; padding: .4rem; border: 1px solid var(--line); border-radius: 6px; max-width: 360px; min-width: 200px; }

/* ---- profile ---- */
.profile-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.profile-id { flex: 1; min-width: 220px; }
.profile-id h1 { margin: 0 0 .1rem; }
.profile-id .sub { color: var(--muted); font-size: .85rem; margin: 0 0 .35rem; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.profile-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.completion { display: flex; align-items: center; gap: .8rem; padding: .55rem 1rem; margin-top: .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: .82rem; flex-wrap: wrap; }
.completion .progress { flex: 1; min-width: 140px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.completion .progress-fill { height: 100%; background: var(--ok); transition: width .3s; }
.completion .gaps { color: var(--warn); }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 1rem 0 .9rem; overflow-x: auto; }
.tabs a { padding: .55rem .8rem; color: var(--muted); font-size: .88rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { margin-left: .3rem; font-size: .72rem; background: var(--line); color: var(--muted); border-radius: 999px; padding: 0 .4rem; }
[data-tab] { display: none; }
[data-tab].active { display: block; }
.sec header { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; }
.sec header h2 { margin: 0; }
.sec .view { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem 1.2rem; margin: 0; }
@media (max-width: 640px) { .sec .view { grid-template-columns: 1fr; } }
.sec .view .row { display: grid; grid-template-columns: 46% 1fr; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); min-width: 0; }
.sec .view dt { color: var(--muted); font-size: .8rem; }
.sec .view dd { margin: 0; font-size: .88rem; overflow-wrap: anywhere; white-space: pre-line; }
.sec .view .row.missing dd { color: var(--warn); font-style: italic; }
.sec .edit[hidden] { display: none; }
.sec.editing .view { display: none; }
.card-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .8rem; }
.history { list-style: none; margin: .3rem 0 0; padding: 0; font-size: .84rem; max-height: 420px; overflow: auto; }
.history li { display: flex; gap: .8rem; padding: .3rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.history li:last-child { border-bottom: 0; }
.history .when { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 8.5rem; }
.history .by { min-width: 12rem; color: var(--muted); }
#vacation-table input.override { width: 5rem; font: inherit; padding: .3rem; border: 1px solid var(--line); border-radius: 6px; }
.link-box { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; align-items: center; }
.link-box input { flex: 1; min-width: 240px; font: inherit; font-size: .85rem; padding: .4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.dialog textarea, #invite-message { width: 100%; font: inherit; font-size: .85rem; padding: .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); resize: vertical; margin-top: .4rem; }

/* ---- dialogs ---- */
.dialog { border: 0; border-radius: 10px; padding: 0; width: min(560px, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--text); background: var(--card); }
.dialog::backdrop { background: rgba(17, 24, 39, .5); }
.dialog-body { padding: 1rem 1.2rem 1.2rem; margin: 0; display: flex; flex-direction: column; gap: .8rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 1.05rem; }
.dialog-head .close { background: none; border: 0; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .4rem; }
.step { display: flex; flex-direction: column; gap: .8rem; }
.step[hidden] { display: none; }
.step > p { margin: 0; }
.choices { display: grid; gap: .6rem; }
.choice { text-align: left; font: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem .9rem; cursor: pointer; display: flex; flex-direction: column; gap: .2rem; color: var(--text); }
.choice:hover, .choice:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.choice span { color: var(--muted); font-size: .85rem; }
.picks .pick { display: grid; grid-template-columns: auto 1fr; column-gap: .6rem; align-items: center; text-align: left; font: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; cursor: pointer; }
.picks .pick input { grid-row: 1 / span 2; width: 18px; height: 18px; }
.picks .pick span { color: var(--muted); font-size: .82rem; grid-column: 2; }
.picks .pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: .3rem; }

/* ---- onboarding (no sidebar) ---- */
.record-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 1rem; align-items: start; }
.record-side { position: sticky; top: 1rem; }
.record-main { min-width: 0; }
@media (max-width: 900px) { .record-layout { grid-template-columns: 1fr; } .record-side { position: static; } .section-nav { flex-direction: row; overflow-x: auto; } .section-nav a { white-space: nowrap; } .section-nav .count { display: none; } }
.progress-card h2 { font-size: 1rem; margin-bottom: .6rem; }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.progress-card #progress-text { margin: .4rem 0 .8rem; color: var(--muted); }
.section-nav { display: flex; flex-direction: column; gap: .15rem; }
.section-nav a { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem; border-radius: 6px; color: var(--text); font-size: .85rem; }
.section-nav a:hover { background: var(--bg); }
.section-nav a.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.section-nav .tick { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; }
.section-nav a.done .tick { background: var(--ok); border-color: var(--ok); color: var(--on-solid); }
.section-nav a.done .tick::after { content: "✓"; }
.section-nav a.has-error .tick { border-color: var(--danger); background: var(--danger-soft); }
.section-nav .count { margin-left: auto; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.record-form fieldset { scroll-margin-top: 1rem; }
.record-form legend .num { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--text); color: var(--card); font-size: .78rem; align-items: center; justify-content: center; margin-right: .3rem; }
.formbar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .9rem; margin-top: 1rem; box-shadow: 0 -4px 16px rgba(0,0,0,.06); z-index: 5; }
.formbar #formbar-text { color: var(--warn); margin-right: auto; }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: .55rem 1rem; border-radius: 8px; opacity: 0; transition: all .2s; pointer-events: none; max-width: 90vw; z-index: 50; font-size: .88rem; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); }
