:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d221f;
  --ink-2: #5c6560;
  --ink-3: #8c948f;
  --line: #e2ded5;
  --accent: #1f5b47;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --weekend: #ebe8e0;
  --today: #d9ebe3;
  --warn: #b5541c;
  --warn-soft: #fbeadf;
  --info: #6b6f3a;
  --danger: #a8322a;
  --vac: #2f6690;  --vac-soft: #e1edf6;
  --sick: #8a4b8f; --sick-soft: #f2e5f3;
  --comp: #7a6420; --comp-soft: #f4eed9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --surface: #1c211e; --surface-2: #232925;
    --ink: #e8ece9; --ink-2: #a9b2ad; --ink-3: #78817c; --line: #2e3531;
    --accent: #5cc29c; --accent-ink: #0d1a14; --accent-soft: #1f3a2f;
    --weekend: #181c1a; --today: #1f3a2f;
    --warn: #f0a070; --warn-soft: #3a2519; --info: #c9cc8a;
    --danger: #f08a80;
    --vac: #8cc1ea; --vac-soft: #1d2d3a; --sick: #d8a6dc; --sick-soft: #33233a;
    --comp: #e0c46e; --comp-soft: #353020;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger, .link.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 26px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; font-size: 17px; }
.brand-mark { width: 26px; height: 26px; display: block; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border-radius: 16px; padding: 28px 24px;
  box-shadow: var(--shadow); display: grid; gap: 16px;
}
.login-card .brand { font-size: 20px; margin-bottom: 4px; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--ink-2); font-weight: 500; }
input:not([type=checkbox]):not([type=file]), select {
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px; width: 100%;
}
select { appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 19px, calc(100% - 11px) 19px; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--danger); margin: 0; font-size: 14px; min-height: 0; }
.form-error:empty, .form-ok:empty { display: none; }
.form-ok { color: var(--accent); margin: 0; font-size: 14px; }
.hint { color: var(--ink-3); font-size: 13px; margin: 0; font-weight: 400; }

/* ---------- Layout ---------- */
#app { max-width: 760px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 4px; }

.month-head { padding: 8px 0 16px; }
.month-nav { display: flex; align-items: center; gap: 4px; margin-left: -10px; }
.month-nav h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; flex: 1; }
.summary { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin: 8px 0 16px; }
.total { display: grid; }
.total span { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.total small { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.stats { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 2px; }
.stats li { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; color: var(--ink-2); }
.stats li b { color: var(--ink); font-weight: 600; }
.stats li.warn { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 599px) {
  #todayBtn {
    position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 5;
    min-height: 54px; font-size: 17px; border-radius: 14px; box-shadow: 0 6px 20px rgba(31,91,71,.35);
  }
  .head-actions .btn:not(#todayBtn) { flex: 1; }
}

/* ---------- Day list ---------- */
.days { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.day {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; min-height: 56px;
}
.day:first-child { border-top: 0; }
.day:hover { background: var(--surface-2); }
.day.weekend, .day.holiday { background: var(--weekend); }
.day.today { box-shadow: inset 4px 0 0 var(--accent); background: var(--today); }
.day .date { display: grid; line-height: 1.1; }
.day .date b { font-size: 19px; font-weight: 650; }
.day .date span { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.day .what { min-width: 0; display: grid; gap: 2px; }
.day .times { font-weight: 550; }
.day .meta { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .meta .hol { color: var(--accent); font-weight: 600; }
.day .empty { color: var(--ink-3); }
.day .hours { font-weight: 700; font-size: 17px; text-align: right; display: flex; align-items: center; gap: 8px; }
.day .hours small { font-weight: 500; color: var(--ink-3); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.info { background: var(--ink-3); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; width: max-content; }
.badge.vacation { background: var(--vac-soft); color: var(--vac); }
.badge.sick { background: var(--sick-soft); color: var(--sick); }
.badge.comp { background: var(--comp-soft); color: var(--comp); }
.badge.open { background: var(--accent-soft); color: var(--accent); }

/* ---------- Dialogs ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: min(520px, 100vw - 32px); max-height: min(92dvh, 860px); border-radius: 18px; box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(10, 15, 12, .45); }
dialog.sheet > form, .sheet-scroll { padding: 18px 20px 20px; display: grid; gap: 16px; max-height: inherit; overflow-y: auto; }
@media (max-width: 599px) {
  dialog.sheet {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0;
    max-height: 94dvh; padding-bottom: env(safe-area-inset-bottom);
  }
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.sheet-head .sub { margin: 2px 0 0; color: var(--ink-3); font-size: 14px; }
.sheet-head .sub:empty { display: none; }
.close { font-size: 18px; margin: -6px -10px 0 0; }
.sheet-foot { display: flex; gap: 8px; align-items: center; padding-top: 4px; }
.sheet-foot .spacer { flex: 1; }
@media (max-width: 420px) { .sheet-foot .btn:not(.ghost) { flex: 1; } .sheet-foot .spacer { display: none; } }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 600; cursor: pointer; }
.seg button[aria-checked=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

#workFields { display: grid; gap: 14px; }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.block2 { padding-top: 12px; border-top: 1px dashed var(--line); }
.block2 .link { grid-column: 1 / -1; padding: 0; }
.time-field { display: grid; gap: 6px; }
.lbl { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.tp { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; }
.tp select { text-align: center; font-size: 20px; font-weight: 600; min-height: 52px; padding: 0 24px 0 10px; background-position: calc(100% - 14px) 25px, calc(100% - 9px) 25px; }
.tp .colon { font-weight: 700; font-size: 20px; color: var(--ink-3); }
.row-field { grid-template-columns: auto 1fr; align-items: center; gap: 12px; }
.row-field.note { grid-template-columns: 1fr; }
.calc { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--accent-soft); border-radius: 12px; font-size: 14px; color: var(--ink-2); }
.calc b { color: var(--ink); font-size: 18px; }
.calc .net { text-align: right; }
.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.warnings:empty { display: none; }
.warnings li { background: var(--warn-soft); color: var(--warn); padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.warnings li.info { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Settings ---------- */
.stack { display: grid; gap: 12px; }
.stack h3 { margin: 8px 0 0; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.sheet-scroll > .stack + .stack { border-top: 1px solid var(--line); padding-top: 14px; }
.rule { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 15px; }
.rule select { width: auto; }
.inset { background: var(--surface-2); padding: 14px; border-radius: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.users { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.users li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface-2); border-radius: 10px; }
.users li span { flex: 1; min-width: 0; }
.users li small { color: var(--ink-3); }
.users .link { padding: 4px 6px; font-size: 14px; }
.import-result { list-style: none; margin: 0; padding: 0; font-size: 14px; display: grid; gap: 4px; color: var(--ink-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
