:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #e1e5ec;
  --primary: #1f6feb;
  --danger: #d1242f;
  --under: #e8890c;
  --met: #1a7f37;
  --over: #1a7f37;
  --holiday: #8250df;
  --vacation: #0b8a8a;
  --sick: #c2410c;
  --event: #be185d;
  --radius: 14px;
  --nav-h: 60px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1218;
  --card: #181c24;
  --text: #e6e9ef;
  --muted: #9099ab;
  --border: #2a303c;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --card: #181c24;
    --text: #e6e9ef;
    --muted: #9099ab;
    --border: #2a303c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

body.with-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

a { color: var(--primary); }

h1, h2 { margin: 0 0 .5rem; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.muted { color: var(--muted); }

.container { max-width: 640px; margin: 0 auto; padding: 1rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  padding-top: calc(.75rem + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar form { margin: 0; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }

.running-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .5rem 1rem;
  background: var(--primary);
  color: #fff;
}
.running-banner a { color: #fff; }
.running-banner form { margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card.narrow { max-width: 380px; margin: 3rem auto; }
.card.inactive { opacity: .6; }
.card-head { display: flex; justify-content: space-between; align-items: center; }

.page-title { margin-bottom: 1rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn.small { min-height: 34px; padding: .25rem .75rem; font-size: .875rem; }
.btn.block { width: 100%; }
.btn.huge { width: 100%; min-height: 72px; font-size: 1.5rem; margin-bottom: 1rem; }
.btn.icon { flex: 0 0 44px; width: 44px; padding: 0; font-size: 1.5rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.holiday { background: var(--holiday); border-color: var(--holiday); color: #fff; }
.btn.vacation { background: var(--vacation); border-color: var(--vacation); color: #fff; }
.btn.sick { background: var(--sick); border-color: var(--sick); color: #fff; }
.btn.event { background: var(--event); border-color: var(--event); color: #fff; }
.btn.link, button.link { background: none; border: none; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }

.button-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.button-row form { margin: 0; }
.button-row form:only-child { grid-column: 1 / -1; }
.button-row .btn { width: 100%; }
.day-types { container-type: inline-size; }
@container (min-width: 480px) {
  .button-row { grid-template-columns: repeat(4, 1fr); }
}

/* Forms */
input[type="password"], input[type="time"], input[type="date"], input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}
.stack { display: grid; gap: 1rem; }
.stack label { display: grid; gap: .25rem; font-weight: 600; }
.checkbox { display: flex !important; gap: .5rem; align-items: center; font-weight: 400 !important; }

.time-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: .5rem; align-items: end; }
.time-form label { display: grid; gap: .25rem; min-width: 0; font-size: .875rem; color: var(--muted); }
/* iOS Safari gives time inputs an intrinsic min width that ignores the grid column. */
.time-form input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  padding: .5rem .4rem;
  text-align: center;
}
.time-form input[type="time"]::-webkit-date-and-time-value { text-align: center; margin: 0; }

/* Segmented control */
.plain-fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
.plain-fieldset legend { padding: 0; margin-bottom: .5rem; font-weight: 600; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: 44px; font-weight: 600; border-left: 1px solid var(--border); }
.segmented label:first-of-type span { border-left: none; }
.segmented input:checked + span { background: var(--primary); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -4px; }

/* Flash */
.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.flash-success { background: rgba(26, 127, 55, .12); color: var(--met); }
.flash-error { background: rgba(209, 36, 47, .12); color: var(--danger); }
.flash-info { background: rgba(31, 111, 235, .12); color: var(--primary); }

/* Date navigation */
.date-nav { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; margin-bottom: 1rem; }
.date-title { flex: 1; min-width: 0; text-align: center; }
.date-title h1 { margin-bottom: .25rem; }
.date-title p { margin: 0 0 .25rem; }
.day-title { margin: 0 0 .5rem; text-align: center; font-size: clamp(1rem, 4.6vw, 1.35rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date-picker { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; align-items: center; margin: 0; }
.date-picker input { flex: 1 1 140px; max-width: 170px; min-width: 0; min-height: 34px; padding: .25rem .5rem; }

/* Progress */
.progress-figures { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.diff { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.diff-under { color: var(--under); }
.diff-met, .diff-over { color: var(--met); }
.progress { height: 14px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress .bar { height: 100%; border-radius: 999px; transition: width .4s ease; }
.progress-under .bar { background: var(--under); }
.progress-met .bar { background: var(--met); }
.progress-over .bar {
  background: repeating-linear-gradient(45deg, var(--over), var(--over) 8px, #2da44e 8px, #2da44e 16px);
}

/* Badges */
.badge { font-size: .75rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px; background: var(--border); }
.badge-holiday { background: var(--holiday); color: #fff; }
.badge-vacation { background: var(--vacation); color: #fff; }
.badge-sick { background: var(--sick); color: #fff; }
.badge-event { background: var(--event); color: #fff; }

/* Entries */
.entries { list-style: none; margin: 0; padding: 0; }
.entry { padding: .5rem 0; border-top: 1px solid var(--border); }
.entry:first-child { border-top: none; }
.entry-row { display: flex; align-items: center; gap: .5rem; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.entry-row .range { flex: 1; white-space: nowrap; }
.entry-row .dur { white-space: nowrap; font-weight: 600; min-width: 3.5em; text-align: right; }
.entry-row form { margin: 0; }
.entry.is-running .range { color: var(--primary); font-weight: 600; }
.entry-edit { margin-top: .5rem; }
[hidden] { display: none !important; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn[aria-expanded="true"] { color: var(--primary); border-color: var(--primary); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.logout { border: none; width: 36px; height: 36px; }

/* Week */
.week-list { list-style: none; margin: 0; padding: 0; }
.week-list li { border-top: 1px solid var(--border); }
.week-list li:first-child { border-top: none; }
.week-list a {
  display: flex;
  gap: .5rem;
  align-items: center;
  padding: .85rem 0;
  color: var(--text);
  text-decoration: none;
}
.week-list .wd { flex: 1; font-weight: 600; }
.week-list .dur { font-variant-numeric: tabular-nums; font-weight: 600; }
.week-list .is-today .wd { color: var(--primary); }
.week-list .month-diff { min-width: 5.5em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 0; }
.stats dt { color: var(--muted); font-size: .875rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 700; }
.stats .small-link { font-size: .875rem; font-weight: 600; }

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.nav-icon { flex: 0 0 64px; }

@media (min-width: 720px) {
  h1 { font-size: 1.5rem; }
  .container { padding: 2rem 1rem; }
}
