:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c2030;
  --muted: #5d6478;
  --line: #e2e5ee;
  --primary: #2f5bd3;
  --on-primary: #ffffff;
  --primary-soft: #e8eefc;
  --danger: #c0352b;
  --warn: #b7791f;
  --ok: #2f855a;
  --weekend: #f0f1f6;
  --holiday: #fdecec;
  --shadow: 0 1px 2px rgb(20 25 40 / 6%), 0 4px 16px rgb(20 25 40 / 6%);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1d2029;
    --text: #e8eaf1;
    --muted: #a0a6b8;
    --line: #2f3340;
    --primary: #7d9cf5;
    --on-primary: #0e1424;
    --primary-soft: #262f4a;
    --danger: #f08a80;
    --warn: #e7b14f;
    --ok: #6fcf97;
    --weekend: #191b22;
    --holiday: #2c1d20;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.4; }
h1, h2, h3 { margin: 0 0 0.75rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); font-weight: normal; }
.h { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Controls ---------- */
input, select, button, .button { font: inherit; color: inherit; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: 0.6; cursor: default; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--primary-soft); }
.danger { color: var(--danger); }
.small { min-height: 36px; padding: 0.25rem 0.75rem; font-size: 0.9rem; }
.icon { min-width: 44px; padding: 0.25rem; font-size: 1.2rem; }
.big { width: 100%; }
.link { background: none; border: none; padding: 0; min-height: 0; color: var(--primary); text-decoration: underline; cursor: pointer; font-weight: 600; }
.chip { min-height: 44px; padding: 0.25rem 0.7rem; font-size: 0.9rem; flex: none; }
label { display: block; margin: 0.9rem 0 0.35rem; font-weight: 600; font-size: 0.9rem; }
.suggest { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.4rem; }
.suggest .chip { min-height: 36px; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 0; }
.actions { margin-top: 1rem; }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 0; margin: 0.5rem 0 0; }
.error:empty { display: none; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0 0; }
.hint:empty { display: none; }
.badge { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 99px; background: var(--primary-soft); color: var(--text); white-space: nowrap; }
.badge.none { background: color-mix(in srgb, var(--warn) 25%, transparent); }
h3 .badge { margin-left: 0.5rem; font-weight: normal; vertical-align: middle; }
/* One client per month: the contract is preselected by date, so it only needs a small, changeable line. */
.contract-line { display: flex; gap: 0.4rem; align-items: center; margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }
.contract-line label { margin: 0; font-size: inherit; font-weight: normal; color: inherit; }
.contract-line select { width: auto; min-height: 32px; padding: 0.1rem 0.4rem; font-size: inherit; border-color: transparent; background-color: transparent; color: var(--muted); }
.contract-line select:hover, .contract-line select:focus { border-color: var(--line); color: var(--text); }
.badge.active { background: var(--ok); color: var(--surface); }

.hours { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.hours input { width: 6.5rem; flex: none; text-align: center; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; border: 1px solid var(--line); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; }
.tabs { display: flex; gap: 0.25rem; flex: 1; overflow-x: auto; }
.tabs button { border: none; background: transparent; color: var(--muted); font-weight: 600; }
.tabs button[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.banner { margin: 0; padding: 0.6rem 1rem; background: var(--danger); color: var(--surface); font-weight: 600; text-align: center; }
.view { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 6rem; display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.grid-2 > *, .card { min-width: 0; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.toolbar h2 { margin: 0; min-width: 10rem; text-align: center; }
.toolbar select { width: auto; max-width: 16rem; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(100%, 380px); }
.login h1 { text-align: center; margin-top: 0.5rem; }
.login-icon { display: block; margin: 0 auto; }
.login .primary { margin-top: 1.25rem; }

/* ---------- Entries ---------- */
#day-list { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: flex; align-items: center; gap: 0.25rem; border-radius: 8px; }
.entry:hover, .entry.is-editing { background: var(--primary-soft); }
.entry-main {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.4rem 0.5rem;
}
.entry-main .task { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stepper { display: inline-flex; align-items: center; flex: none; }
.stepper .h { min-width: 3.2rem; text-align: center; font-weight: 600; }
.hours-btn { min-height: 36px; padding: 0 0.25rem; border-radius: 6px; cursor: text; }
.hours-btn:hover { background: var(--primary-soft); text-decoration: underline dotted; }
.hours-input { width: 4rem; min-height: 36px; padding: 0.15rem 0.3rem; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.step { min-width: 36px; min-height: 36px; padding: 0; font-size: 1.15rem; color: var(--primary); }
.entry .icon { opacity: 0.55; font-size: 0.95rem; }
.entry:hover .icon, .entry .icon:focus-visible { opacity: 1; }
.day + .day { margin-top: 1rem; }
.day h3 { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--muted); margin: 0 0 0.25rem; padding: 0 0.5rem; }
.day h3 .link { color: var(--muted); text-decoration: none; }
.day h3 .badge { margin-right: auto; }
.total { display: flex; justify-content: space-between; font-weight: 700; padding: 0.5rem calc(44px + 36px + 0.5rem) 0 0.5rem; margin: 0.25rem 0 0; border-top: 1px solid var(--line); }
.total .h { min-width: 3.2rem; text-align: center; }

/* ---------- Tiles ---------- */
.tiles { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: grid; gap: 0.2rem; }
.tile .label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.tile .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .note { color: var(--muted); font-size: 0.8rem; }

/* ---------- Calendar ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.4rem; padding: 0.75rem; }
.weekday { text-align: center; font-weight: 600; font-size: 0.85rem; color: var(--muted); padding: 0.25rem 0; }
.calendar .day { margin: 0; min-height: 6.5rem; border: 1px solid var(--line); border-radius: 8px; padding: 0.3rem; display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.8rem; }
.calendar .day.weekend { background: var(--weekend); }
.calendar .day.holiday { background: var(--holiday); }
.calendar .day.filled { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.calendar .day.today .num { background: var(--primary); color: var(--on-primary); border-radius: 99px; padding: 0 0.4rem; }
.day-head { display: flex; align-items: center; gap: 0.3rem; }
.day-head .num { font-weight: 700; }
.holiday-name { color: var(--danger); font-size: 0.7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.day-head .add { margin-left: auto; min-width: 28px; min-height: 28px; font-size: 1rem; opacity: 0; }
.calendar .day:hover .add, .day-head .add:focus-visible { opacity: 1; }
.cal-entry { min-height: 0; padding: 0.1rem 0.25rem; border: none; background: transparent; justify-content: space-between; font-size: 0.75rem; gap: 0.25rem; border-radius: 4px; }
.cal-entry:hover { background: var(--primary-soft); }
.cal-entry .task { overflow: hidden; text-overflow: ellipsis; }
.day-sum { margin-top: auto; text-align: right; font-weight: 700; color: var(--primary); border-top: 1px solid var(--line); padding-top: 0.1rem; }
@media (hover: none) { .day-head .add { opacity: 1; } }

/* ---------- Charts ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.bars li { display: grid; grid-template-columns: 7rem 1fr auto; gap: 0.75rem; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.9rem; }
.bar { height: 0.8rem; background: var(--weekend); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.daily { position: relative; display: flex; align-items: stretch; gap: 3px; height: 220px; padding-bottom: 1.4rem; }
.daily::after { content: ""; position: absolute; left: 0; right: 0; bottom: calc(1.4rem + var(--soll) * (220px - 1.4rem)); border-top: 1px dashed var(--muted); opacity: 0.6; pointer-events: none; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.col-bar { width: 100%; max-width: 28px; background: var(--primary); border-radius: 4px 4px 0 0; }
.col.free .col-bar { opacity: 0.5; }
.col-value { font-size: 0.65rem; color: var(--muted); }
.col-label { position: absolute; bottom: -1.3rem; font-size: 0.7rem; color: var(--muted); }
.col.free .col-label { opacity: 0.6; }

/* ---------- Contracts ---------- */
#contract-list { display: grid; gap: 1rem; }
.contract-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); font-size: 0.8rem; }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.progress { height: 0.6rem; background: var(--weekend); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }
.progress.mid span { background: var(--warn); }
.progress.high span { background: var(--danger); }
.contract p { margin: 0.5rem 0 0; font-size: 0.9rem; }

/* ---------- Dialog & toast ---------- */
dialog { border: none; border-radius: var(--radius); padding: 1.5rem; width: min(560px, calc(100% - 2rem)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid > h2, .form-grid > .error, .form-grid > .actions { grid-column: 1 / -1; }
.form-grid label input { margin-top: 0.35rem; font-weight: normal; }
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 1rem;
  align-items: center;
  max-width: calc(100% - 2rem);
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.toast .link { color: var(--bg); }

/* ---------- Drag & drop, locked entries, ticket links ---------- */
.drag { min-width: 28px; min-height: 36px; padding: 0; color: var(--muted); cursor: grab; touch-action: none; font-size: 1rem; }
.drag:active { cursor: grabbing; }
.entry.dragging { background: var(--primary-soft); box-shadow: var(--shadow); opacity: 0.9; outline: 2px dashed var(--primary); }
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.entry.locked { padding: 0.4rem 0.5rem; color: var(--muted); gap: 0.5rem; }
.entry.locked .entry-main { display: flex; gap: 0.4rem; align-items: center; padding: 0; }
.drag-space { width: 28px; text-align: center; font-size: 0.8rem; }
.locked-hours { min-width: 3.2rem; text-align: center; margin-right: calc(36px + 44px); }
.ticket-link { color: var(--primary); text-decoration: none; padding: 0.25rem; font-weight: 700; }

/* ---------- Gaps, day progress ---------- */
.gaps { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0.75rem 1rem; border-color: var(--warn); }
.gaps > span { font-weight: 600; margin-right: 0.25rem; }
.day-progress { height: 0.35rem; background: var(--weekend); border-radius: 99px; overflow: hidden; margin: -0.25rem 0 0.5rem; }
.day-progress span { display: block; height: 100%; background: var(--primary); }
.day-progress.done span { background: var(--ok); }

/* ---------- Month lock, forecast, year table, footer ---------- */
#month-close.is-closed { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.forecast { margin: 0.5rem 0 0; font-size: 0.9rem; }
.forecast.warn { color: var(--warn); }
.table-wrap { overflow-x: auto; }
table.year { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 0.95rem; }
table.year th, table.year td { padding: 0.4rem 0.5rem; text-align: right; border-bottom: 1px solid var(--line); }
table.year th:first-child { text-align: left; font-weight: 600; }
table.year thead th { color: var(--muted); font-size: 0.8rem; }
table.year tr.current { background: var(--primary-soft); }
table.year tfoot th, table.year tfoot td { font-weight: 700; border-bottom: none; }
table.year .bar { display: block; }
table.year .link { text-decoration: none; color: var(--text); }
.app-footer { display: flex; gap: 1.5rem; justify-content: center; flex-wrap: wrap; padding: 0 1rem 2rem; font-size: 0.9rem; }
.app-footer a { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 0.25rem 0.5rem; }
  .tabs { order: 3; flex-basis: 100%; }
  .brand span { display: none; }
  .calendar { gap: 2px; padding: 0.25rem; }
  .calendar .day { min-height: 4rem; padding: 0.15rem; }
  .cal-entry .task, .holiday-name { display: none; }
  .cal-entry { justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .bars li { grid-template-columns: 5rem 1fr auto; }
  .col-value { display: none; }
  .hide-sm { display: none; }
  h3 .badge { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
  table.year { font-size: 0.8rem; }
  table.year th, table.year td { padding: 0.35rem 0.2rem; }
  table.year th:first-child { width: 26%; }
  .entry-main { padding-inline: 0.25rem; }
  .entry .icon { min-width: 36px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
