:root {
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body {
  margin: 0;
  font:
    14px system-ui,
    -apple-system,
    sans-serif;
}
img {
  max-width: 100%;
}
[hidden] {
  display: none !important;
}

/* Layout: Stempelkarte — Kopf mit Monatswechsel, Kennzahlen, Tabelle nach Kalenderwochen, Seitenleiste mit Monaten & Einstellungen */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --sunk: #e9edeb;
  --line: #d5dcd8;
  --ink: #17201c;
  --muted: #5d6a64;
  --accent: #2b47c9;
  --accent-soft: #e3e8fb;
  --pos: #1b7a4a;
  --neg: #b4322a;
  --warn: #a96a00;
  --weekend: #eef1ef;
  --holiday: #f4ecdc;
  --font-display: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121715;
    --surface: #1a201d;
    --sunk: #222a26;
    --line: #313b36;
    --ink: #e7ece9;
    --muted: #97a39d;
    --accent: #8ea2ff;
    --accent-soft: #252d4d;
    --pos: #5fcf92;
    --neg: #ff8a80;
    --warn: #f0b54a;
    --weekend: #171c1a;
    --holiday: #2a2519;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121715;
  --surface: #1a201d;
  --sunk: #222a26;
  --line: #313b36;
  --ink: #e7ece9;
  --muted: #97a39d;
  --accent: #8ea2ff;
  --accent-soft: #252d4d;
  --pos: #5fcf92;
  --neg: #ff8a80;
  --warn: #f0b54a;
  --weekend: #171c1a;
  --holiday: #2a2519;
  color-scheme: dark;
}
* {
  box-sizing: border-box;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
}
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 20px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 18px;
}
h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}
.monthnav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.monthnav h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  margin: 0;
  min-width: 9.5ch;
  text-align: center;
}
button,
select,
input {
  font: inherit;
  color: inherit;
}
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn:hover {
  border-color: var(--accent);
}
.btn.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.status {
  font-size: 0.8rem;
  color: var(--muted);
}
.status.err {
  color: var(--neg);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat .lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.stat .val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
}
.stat .sub {
  font-size: 0.8rem;
  color: var(--muted);
}
.pos {
  color: var(--pos);
}
.neg {
  color: var(--neg);
}
@media (max-width: 760px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat .val {
    font-size: 1.25rem;
  }
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  min-width: 0;
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 780px;
}
td.diff {
  font-weight: 500;
}
th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
}
td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tr.day td:first-child {
  padding-left: 14px;
  white-space: nowrap;
}
tr.day.weekend td {
  background: var(--weekend);
}
tr.day.holiday td {
  background: var(--holiday);
}
tr.day.today td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
.dname {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.dname .wd {
  font-weight: 700;
  width: 2ch;
  color: var(--muted);
}
tr.today .dname .wd {
  color: var(--accent);
}
.dname .dt {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.hol {
  font-size: 0.72rem;
  color: var(--warn);
  font-weight: 600;
  display: block;
  line-height: 1.1;
}
tr.day {
  cursor: pointer;
}
tr.day td {
  padding-block: 9px;
}
tr.day:hover td {
  background: var(--accent-soft);
}
tr.day:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
td.t {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
td.note {
  color: var(--muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.addhint {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.82rem;
  opacity: 0;
}
tr.day:hover .addhint,
tr.day:focus-visible .addhint {
  opacity: 1;
}
td.net {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
  padding-right: 14px;
}
td.net .credit {
  color: var(--muted);
  font-weight: 500;
}
.flag {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--warn);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 4px;
  cursor: help;
  font-family: var(--font-body);
}
.chip {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
}
.chip.urlaub {
  background: var(--accent-soft);
  color: var(--accent);
}
.chip.krank {
  background: var(--holiday);
  color: var(--warn);
}
.chip.open {
  background: var(--sunk);
  color: var(--muted);
}

/* Dialog */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  display: grid;
  place-items: center;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.dlg {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  max-height: calc(100% - 16px);
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dlg header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 18px 10px;
}
.dlg header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 0;
  flex: 1;
}
.dlg header .hol {
  font-size: 0.8rem;
}
.dlg form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 18px 18px;
}
.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.seg label {
  text-align: center;
  padding: 8px 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  border-right: 1px solid var(--line);
}
.seg label:last-child {
  border-right: 0;
}
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg label:has(input:checked) {
  background: var(--accent);
  color: var(--surface);
}
.seg label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}
.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr;
  gap: 10px;
}
.fld {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.fld > span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.fld input {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}
.fld input:focus {
  border-color: var(--accent);
  outline: none;
}
.fld input.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.fld input.bad {
  border-color: var(--neg);
}
.now {
  all: unset;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
}
.now:focus-visible {
  outline: 2px solid var(--accent);
}
.preview {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--sunk);
  border-radius: 8px;
  padding: 10px 12px;
}
.preview .lbl {
  font-size: 0.8rem;
  color: var(--muted);
}
.preview .num {
  font-size: 1.25rem;
  font-weight: 600;
}
.warn {
  font-size: 0.82rem;
  color: var(--warn);
  margin: -6px 0 0;
}
.dlg footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.btn.danger {
  color: var(--neg);
  margin-right: auto;
}
.btn.danger:hover {
  border-color: var(--neg);
}
tr.week td {
  background: var(--sunk);
  padding: 9px 14px;
  border-bottom: 2px solid var(--line);
}
.weekrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
}
.weekrow .kw {
  font-weight: 700;
  font-family: var(--font-display);
}
.weekrow .range {
  color: var(--muted);
  font-size: 0.85rem;
}
.weekrow .figs {
  margin-left: auto;
  display: flex;
  gap: 16px;
  align-items: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.weekrow .figs b {
  font-weight: 600;
}
.bar {
  width: 120px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: var(--accent);
}
.bar i.over {
  background: var(--pos);
}
.weekrow .partial {
  font-size: 0.75rem;
  color: var(--muted);
}

aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.mlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.mlist button {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  align-items: baseline;
}
.mlist button:hover {
  background: var(--sunk);
}
.mlist button.cur {
  background: var(--accent-soft);
  font-weight: 600;
}
.mlist button:focus-visible {
  outline: 2px solid var(--accent);
}
.mlist .num {
  font-size: 0.85rem;
}
.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.field input {
  width: 76px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: var(--font-mono);
  text-align: right;
}
.settings > summary {
  display: inline-block;
  list-style: none;
  font-size: 0.8rem;
  padding: 5px 10px;
  color: var(--muted);
}
.settings > summary::-webkit-details-marker {
  display: none;
}
.settings[open] > summary {
  margin-bottom: 8px;
  color: var(--ink);
}
.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0 0;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 10px;
}
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
  border: 1px solid var(--line);
}
.legend .lw::before {
  background: var(--weekend);
}
.legend .lh::before {
  background: var(--holiday);
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
