:root {
  --bg: #f5f3eb;
  --card: #ffffff;
  --text: #1d2f25;
  --muted: #66705f;
  --line: #dcdccf;
  --accent: #243e31;
  --accent-text: #f5f3eb;
  --accent-soft: #e7e9dd;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141814;
    --card: #1e231e;
    --text: #e8ece4;
    --muted: #9aa494;
    --line: #333a32;
    --accent: #dbe4c2;
    --accent-text: #1d2f25;
    --accent-soft: #2a3a2f;
    --danger: #ff8a80;
    --danger-soft: #3a2220;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: .95rem;
}

.center-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border: 1px solid var(--line);
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.row.split { display: grid; grid-template-columns: 1fr 1fr; }
#edit-title:focus { outline: none; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand.small { gap: 8px; font-size: .95rem; }
.logo { display: block; height: auto; }
.brand.small .logo { width: 68px; }
.brand-login { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0 8px; }
.brand-login .logo { width: 172px; }
/* Donker logo leesbaar houden in donkere modus */
@media (prefers-color-scheme: dark) {
  .logo { background: #f5f3eb; border-radius: 8px; padding: 4px 6px; }
}

.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-weight: 600; font-size: .9rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  width: 100%;
  min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { resize: vertical; min-height: 64px; }
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 8px; min-height: 0; font-weight: 500; }
.btn.link.center { align-self: center; text-decoration: underline; text-underline-offset: 3px; }
.notice { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; font-size: .95rem; }

/* Eerdere versies in het aanpasvenster */
.history { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.history summary { cursor: pointer; font-weight: 600; font-size: .92rem; }
.history ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { font-size: .88rem; }
.history time { display: block; color: var(--muted); font-size: .8rem; }

/* App op beginscherm */
.install-link { display: inline-flex; align-items: center; gap: 6px; }
.install-link.block { display: flex; margin: 20px auto 0; }
.install-link svg, .install-tip > svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex: none; }
.install-tip {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 8px 10px 14px; margin-bottom: 14px; background: var(--accent-soft);
}
.install-tip p { font-size: .92rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.tip-close { font: inherit; font-size: 1.4rem; line-height: 1; border: 0; background: none; color: var(--muted); padding: 4px 8px; cursor: pointer; }
.install-steps h3 { font-size: 1rem; margin: 4px 0 6px; }
.install-steps ol { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.inline-icon { width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .6; cursor: default; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chips input[type=date] { flex: 1; min-width: 150px; width: auto; }
.chip {
  font: inherit;
  font-size: .95rem;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }

.times { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.times input { text-align: center; }
.hint { font-size: .9rem; color: var(--muted); }

.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.stepper input { text-align: center; font-size: 1.3rem; font-weight: 600; }
.step {
  font: inherit;
  font-size: 1.6rem;
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}

.machine-row { display: grid; grid-template-columns: 1fr 168px; gap: 10px; align-items: center; }
.machine-row .stepper { grid-template-columns: 44px 1fr 44px; gap: 6px; }
.machine-row .stepper input { font-size: 1.1rem; min-height: 44px; padding: 8px; }
.machine-row .step { font-size: 1.3rem; }
.machine-row .machine-note { grid-column: 1 / -1; min-height: 44px; padding: 10px 12px; font-size: .95rem; }

/* App-layout */
.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
/* Zelfde breedte als de inhoud, logo in het midden */
.topbar-inner {
  max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.topbar-inner .greet { font-size: .95rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-inner .logo { width: 76px; }
.topbar-inner #logout { justify-self: end; }
.tab {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  /* Op een breed scherm even breed als de inhoud */
  padding-left: max(0px, calc((100vw - 560px) / 2));
  padding-right: max(0px, calc((100vw - 560px) / 2));
}
.tabbar button {
  font: inherit; font-size: .85rem; font-weight: 600;
  background: none; border: 0; color: var(--muted);
  padding: 10px 0 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; }
.tabbar button.active { color: var(--accent); }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 4px; gap: 4px; margin-bottom: 14px;
}
.segmented button {
  font: inherit; font-size: .9rem; font-weight: 600;
  border: 0; background: none; color: var(--muted);
  border-radius: 9px; padding: 9px 4px; cursor: pointer;
}
.segmented button.active { background: var(--accent); color: var(--accent-text); }

.filter-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-bottom: 14px; }
.filter-row .filter { min-width: 0; }
.segmented.small { grid-template-columns: 1fr 1fr; margin-bottom: 0; }
.segmented.small button { padding: 9px 10px; white-space: nowrap; }
@media (max-width: 380px) {
  .filter-row { grid-template-columns: 1fr; }
}
.totals { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 14px; }
.total { display: flex; flex-direction: column; }
.total .num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.total .lbl { font-size: .85rem; color: var(--muted); }

.day h3 {
  font-size: .9rem; margin: 6px 4px 8px; color: var(--muted);
  display: flex; justify-content: space-between; font-weight: 600;
}
.day .card { padding: 0; overflow: hidden; }
.entry {
  display: flex; gap: 12px; align-items: center; width: 100%;
  font: inherit; color: inherit; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 12px 16px; cursor: pointer;
}
.entry:last-child { border-bottom: 0; }
.entry.locked { cursor: help; }
.entry.locked .main, .entry.locked .hrs { opacity: .7; }
.entry .lock svg { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; display: block; }
.entry .main { flex: 1; min-width: 0; }
.entry .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .sub { font-size: .88rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .hrs { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; font-size: .75rem; font-weight: 700;
  background: var(--accent-soft); color: var(--text);
  border-radius: 6px; padding: 1px 6px; margin-right: 4px;
}
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

dialog {
  border: 0; border-radius: var(--radius); padding: 20px;
  width: min(520px, calc(100vw - 32px));
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 600;
  max-width: calc(100vw - 32px); z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}

.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
