/* =========================================================== tokens === */
:root {
  --bg: #f4f5fa;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef0f7;
  --border: #e3e6ef;
  --border-strong: #cfd4e3;
  --text: #171a23;
  --text-soft: #5a6076;
  --text-faint: #878ea3;
  --accent: #5b5bd6;
  --accent-hover: #4a4ac4;
  --accent-soft: #ecedfb;
  --accent-contrast: #ffffff;
  --good: #16794a;
  --good-soft: #e3f4ec;
  --warn: #9a6300;
  --warn-soft: #fdf0d8;
  --danger: #c0344a;
  --danger-soft: #fdeaee;
  --weekend: #c3c8d8;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .06), 0 1px 3px rgba(20, 24, 40, .04);
  --shadow-md: 0 4px 12px rgba(20, 24, 40, .08), 0 1px 3px rgba(20, 24, 40, .05);
  --shadow-lg: 0 18px 50px rgba(20, 24, 40, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 60px;
}

html[data-theme="dark"] {
  --bg: #0e1016;
  --bg-elev: #151823;
  --surface: #161926;
  --surface-2: #1c2030;
  --surface-3: #232839;
  --border: #272c3c;
  --border-strong: #363d52;
  --text: #e9ebf3;
  --text-soft: #a3aabf;
  --text-faint: #7b8299;
  --accent: #8b8cf0;
  --accent-hover: #9d9ef5;
  --accent-soft: #23243f;
  --accent-contrast: #12131f;
  --good: #5fd6a4;
  --good-soft: #14291f;
  --warn: #e6b566;
  --warn-soft: #2b2313;
  --danger: #f38299;
  --danger-soft: #2e1720;
  --weekend: #39405a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }

.muted { color: var(--text-soft); font-size: .85rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sprite { display: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ============================================================ boot ==== */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================== buttons === */
.btn, .iconbtn, .linkbtn, .month-item, .segmented button, .menu button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 550; font-size: .9rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s, color .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 18px; font-size: .97rem; }
.btn-sm { padding: 6px 11px; font-size: .84rem; }

.iconbtn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--text-soft); cursor: pointer; transition: background .15s, color .15s;
}
.iconbtn:hover { background: var(--surface-3); color: var(--text); }
.iconbtn.sm { width: 28px; height: 28px; }
.iconbtn.accent { color: var(--accent); }
.iconbtn.sm svg { width: 15px; height: 15px; }

.linkbtn {
  background: none; border: 0; padding: 0; font: inherit; font-weight: 600;
  color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

/* =========================================================== fields === */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .84rem; font-weight: 600; color: var(--text-soft); }
.field > span em { font-style: normal; font-weight: 400; }

input[type="text"], input[type="date"], input[type="time"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: .93rem;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 68px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
html[data-theme="dark"] input[type="date"], html[data-theme="dark"] input[type="time"] { color-scheme: dark; }

.row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.hint { font-size: .82rem; color: var(--text-faint); margin: -4px 0 14px; }
.form-error, .auth-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: .87rem; font-weight: 500;
}

/* ============================================================ auth ==== */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 430px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 30px; box-shadow: var(--shadow-md);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px;
  background: var(--accent); color: var(--accent-contrast); flex: none;
}
.brand-mark svg { width: 24px; height: 24px; stroke-width: 1.9; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; }
.brand-mark.sm svg { width: 18px; height: 18px; }
.auth-lead { color: var(--text-soft); font-size: .9rem; margin-bottom: 18px; }
.auth-switch { margin-top: 18px; text-align: center; font-size: .88rem; color: var(--text-soft); }
.auth-details { margin-top: 16px; }
.auth-details summary {
  cursor: pointer; font-size: .85rem; color: var(--text-soft);
  padding: 6px 0; list-style: none;
}
.auth-details summary::-webkit-details-marker { display: none; }
.auth-details summary::before { content: "▸ "; }
.auth-details[open] summary::before { content: "▾ "; }
.auth-details > .field { margin-top: 12px; }
.auth-error { margin-top: 18px; }

/* ========================================================== topbar ==== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: .8rem; font-weight: 700; margin-left: 4px; user-select: none;
}
#btn-theme .t-light, #btn-theme .t-dark, #btn-theme .t-system { display: none; }
html[data-theme-pref="light"] #btn-theme .t-light,
html[data-theme-pref="dark"] #btn-theme .t-dark,
html[data-theme-pref="system"] #btn-theme .t-system { display: block; }

/* ========================================================== layout ==== */
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 0; align-items: start; }
.content { padding: 24px 28px 64px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px));
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 10px; background: var(--bg-elev);
  min-width: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 4px; }
.month-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-width: 0; }
.month-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 9px; border: 0; background: transparent;
  font: inherit; font-size: .89rem; color: var(--text-soft); cursor: pointer; text-align: left;
  transition: background .13s, color .13s;
}
.month-item:hover { background: var(--surface-2); color: var(--text); }
.month-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.month-item .val { font-variant-numeric: tabular-nums; font-size: .82rem; }
.month-item.is-empty .val { color: var(--text-faint); }
.month-item { position: relative; }
.month-item.is-now::after {
  content: ""; position: absolute; top: 7px; right: 6px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.sidebar-foot {
  display: flex; align-items: baseline; justify-content: space-between;
  border-top: 1px solid var(--border); padding-top: 12px; font-variant-numeric: tabular-nums;
}

/* ====================================================== month head ==== */
.month-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav h2 { min-width: 190px; text-transform: capitalize; }
.month-actions { display: flex; align-items: center; gap: 8px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 210px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column;
}
.menu button {
  text-align: left; padding: 9px 11px; border: 0; border-radius: 8px;
  background: transparent; font: inherit; font-size: .89rem; color: var(--text); cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }

/* =========================================================== cards ==== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px;
}
.kpi .label { font-size: .79rem; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.65rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .81rem; color: var(--text-faint); }
.kpi .value.pos { color: var(--good); }
.kpi .value.neg { color: var(--danger); }
.kpi .bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.kpi .bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

/* =========================================================== chart ==== */
.chart { padding: 16px 12px 8px; }
.chart svg { width: 100%; height: 190px; display: block; stroke: none; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-label { fill: var(--text-faint); font-size: 10px; }
.chart .day-label { fill: var(--text-faint); font-size: 10px; }
.chart .day-label.wknd { fill: var(--weekend); }
.chart .bar { fill: var(--accent); rx: 3; transition: opacity .12s; }
.chart .bar.wknd { fill: var(--weekend); }
.chart .bar.today { fill: var(--accent); stroke: var(--text); stroke-width: 1.4; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart g:hover .bar { opacity: .72; }
.chart .target-line { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 40; transform: translate(-50%, -100%);
  background: var(--text); color: var(--bg); padding: 5px 9px; border-radius: 7px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow-md);
}
.chart-wrap { position: relative; }

/* ========================================================= entries ==== */
.entries { padding: 6px 0 8px; }
.day-group { border-bottom: 1px solid var(--border); }
.day-group:last-child { border-bottom: 0; }
.day-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 11px 18px 4px; font-size: .82rem;
}
.day-head .date { font-weight: 650; color: var(--text-soft); text-transform: capitalize; }
.day-head .date.wknd { color: var(--weekend); }
.day-head .total { font-variant-numeric: tabular-nums; color: var(--text-faint); }

.entry {
  display: grid; grid-template-columns: 132px 74px minmax(0, 1fr) auto;
  align-items: center; gap: 12px; padding: 9px 18px;
  border-radius: 10px; margin: 0 6px; transition: background .12s;
}
.entry:hover { background: var(--surface-2); }
.entry .times { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .92rem; }
.entry .times .night { color: var(--text-faint); font-size: .75rem; margin-left: 3px; }
.entry .dur {
  font-variant-numeric: tabular-nums; font-weight: 650; font-size: .88rem;
  background: var(--accent-soft); color: var(--accent);
  padding: 3px 8px; border-radius: 7px; text-align: center; justify-self: start;
}
.entry .meta { min-width: 0; display: flex; align-items: center; gap: 8px; }
.entry .chip {
  flex: none; font-size: .76rem; font-weight: 600; padding: 2px 8px; border-radius: 20px;
  background: var(--surface-3); color: var(--text-soft);
}
.entry .desc {
  color: var(--text-soft); font-size: .89rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entry .desc.none { color: var(--text-faint); font-style: italic; }
.entry .pauze { font-size: .78rem; color: var(--text-faint); flex: none; }
.entry .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.entry:hover .acts, .entry:focus-within .acts { opacity: 1; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-soft); }
.empty svg { width: 34px; height: 34px; color: var(--text-faint); margin-bottom: 10px; }
.empty p { margin-bottom: 14px; font-size: .92rem; }

/* ========================================================= dialogs ==== */
.dialog {
  width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border);
  border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(10, 12, 20, .5); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.dialog-body { padding: 20px; max-height: min(65dvh, 620px); overflow-y: auto; }
.dialog-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 18px 18px;
}

.segmented { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.segmented button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; border: 0; border-radius: 8px; background: transparent;
  font: inherit; font-size: .85rem; font-weight: 550; color: var(--text-soft); cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented svg { width: 15px; height: 15px; }

.install-steps {
  margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px;
  font-size: .88rem; color: var(--text-soft);
}
.install-steps strong { color: var(--text); }

.cred-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.cred {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.cred .cred-icon { color: var(--accent); }
.cred .cred-body { flex: 1; min-width: 0; }
.cred .cred-name { font-weight: 600; font-size: .9rem; }
.cred .cred-sub { font-size: .78rem; color: var(--text-faint); }

/* ========================================================== toasts ==== */
.toasts {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%); z-index: 90;
  max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px; padding: 10px 15px;
  background: var(--text); color: var(--bg); border-radius: 11px;
  font-size: .88rem; font-weight: 550; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--good); color: #fff; }
html[data-theme="dark"] .toast.ok { color: #0d1b14; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ====================================================== responsive ==== */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.kpi.earnings .value { color: var(--good); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border);
    padding: 10px 12px; gap: 6px;
  }
  .sidebar-head { padding-bottom: 0; }
  .month-list {
    flex-direction: row; align-items: flex-start; overflow-x: auto;
    overscroll-behavior-x: contain; overflow-y: hidden;
    gap: 6px; padding-bottom: 4px; width: 100%; flex: none;
  }
  .month-item {
    flex-direction: column; align-items: flex-start; justify-content: flex-start;
    gap: 1px; min-width: 76px; padding: 7px 10px;
  }
  .sidebar-foot { display: none; }
  .content { padding: 18px 14px 56px; }
  .month-head { align-items: flex-start; }
  .month-nav h2 { min-width: 0; font-size: 1.1rem; }
  .month-actions { width: 100%; }
  .month-actions .menu-wrap, .month-actions .btn { flex: 1; }
  .entry { grid-template-columns: 1fr auto; row-gap: 4px; padding: 11px 14px; }
  .entry .dur { grid-row: 1; grid-column: 2; }
  .entry .meta { grid-column: 1 / -1; flex-wrap: wrap; }
  .entry .acts { grid-column: 1 / -1; opacity: 1; justify-content: flex-end; }
  .entry .desc { white-space: normal; }
  .row { grid-template-columns: 1fr 1fr; }
  .row .field:last-child { grid-column: 1 / -1; }
  .topbar { padding: 0 12px; }
  .brand-name { display: none; }
}

/* ======================================================= telefoon ===== */
@media (max-width: 860px) {
  /* 16px voorkomt dat iOS inzoomt zodra een veld aandacht krijgt. */
  input[type="text"], input[type="date"], input[type="time"],
  input[type="number"], select, textarea { font-size: 16px; }

  .iconbtn { width: 40px; height: 40px; }
  .iconbtn.sm { width: 34px; height: 34px; }
  .topbar-right { gap: 2px; }

  .content {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
  .entry { padding-top: 12px; padding-bottom: 12px; }
  .entry .acts .iconbtn { width: 36px; height: 36px; }
}

/* Dialogen komen van onderaf omhoog, zoals telefoons gewend zijn. */
@media (max-width: 640px) {
  .dialog {
    width: 100%; max-width: 100%; max-height: 92dvh;
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; margin: 0;
    border-radius: 20px 20px 0 0; border-bottom: 0;
  }
  .dialog[open] { animation: sheet-up .22s ease-out; }
  @keyframes sheet-up { from { transform: translateY(100%); } }
  .dialog-head { padding: 16px 18px; }
  .dialog-head::before {
    content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 38px; height: 4px; border-radius: 3px; background: var(--border-strong);
  }
  .dialog-head { position: relative; padding-top: 20px; }
  .dialog-body { padding: 18px; max-height: none; }
  .dialog-foot {
    padding: 14px 18px calc(16px + env(safe-area-inset-bottom, 0px));
    border-radius: 0; flex-wrap: wrap;
  }
  .dialog-foot .btn { flex: 1; }
  .dialog-foot #entry-delete { flex: 0 0 auto; }
  .row { grid-template-columns: 1fr 1fr; }
}

/* Als de app vanaf het beginscherm start, gedraagt hij zich als een app. */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
  .month-list { scrollbar-width: none; }
  .month-list::-webkit-scrollbar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
