:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #16202c; --mute: #5b6878; --line: #dde3ea;
  --brand: #1f3a5f; --brand-ink: #ffffff; --accent: #2f6fd0; --danger: #b3261e;
  --today: #fff4cc; --we: #eef1f5; --heat: 201, 86, 60; --on-accent: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161d; --card: #1a222c; --ink: #e8edf3; --mute: #9aa8b8; --line: #2c3846;
    --brand: #16283f; --accent: #6ea4f2; --danger: #f28b82; --today: #4a3f12; --we: #151c25; --on-accent: #0e1620;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Pincode */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.pinbox { width: min(340px, 100%); text-align: center; }
.pinbox h1 { margin: 0 0 4px; font-size: 1.6rem; }
.pinmsg { margin: 0 0 16px; color: var(--mute); min-height: 2.7em; }
.pinmsg.bad { color: var(--danger); font-weight: 600; }
.pindots { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; min-height: 16px; }
.pindots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--mute); }
.pindots span.on { background: var(--ink); border-color: var(--ink); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { height: 64px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 1.5rem; font-weight: 600; }
.key:active { transform: scale(.97); }
.key.soft { background: transparent; }
.key.ok { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.key.ok:disabled { opacity: .4; cursor: default; }
.link { background: none; border: 0; color: var(--accent); padding: 12px; text-decoration: underline; }

/* Kop */
.bar { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink); padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
.bar1, .bar2 { display: flex; align-items: center; gap: 8px; }
.bar2 { margin-top: 8px; }
.brand { font-size: 1.05rem; white-space: nowrap; }
.tabs { display: flex; flex: 1; justify-content: center; gap: 2px; background: rgba(255, 255, 255, .14); border-radius: 10px; padding: 3px; }
.tabs button { flex: 1; max-width: 110px; min-height: 44px; border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: .9rem; white-space: nowrap; padding: 0 4px; }
.tabs button[aria-pressed="true"] { background: #fff; color: #1f3a5f; font-weight: 700; }
.icon { min-width: 44px; min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: inherit; font-size: 1.4rem; line-height: 1; }
.icon:disabled { opacity: .3; cursor: default; }
.bar .icon { background: rgba(255, 255, 255, .14); }
.pill { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); white-space: nowrap; }
.pill.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; }
.pill.danger, .icon.danger { color: var(--danger); }
.bar .pill { border-color: transparent; }
#label { flex: 1; margin: 0; font-size: 1rem; font-weight: 600; text-align: center; min-width: 0; }

main { padding: 10px; max-width: 1500px; margin: 0 auto; }
.hint { color: var(--mute); margin: 8px 0; }

/* Week en 2 weken */
.grid { display: grid; grid-template-columns: minmax(62px, 1.25fr) repeat(var(--n), minmax(0, 1fr)); gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.two { display: grid; gap: 12px; }
@media (min-width: 1100px) { .two { grid-template-columns: 1fr 1fr; } }
.c { min-width: 0; min-height: 44px; border-radius: 6px; }
.corner, .rowh { display: flex; align-items: center; padding: 0 4px; font-size: .85rem; color: var(--mute); overflow: hidden; }
.rowh { color: var(--ink); font-weight: 500; line-height: 1.15; overflow-wrap: anywhere; }
.rowh.me { font-weight: 800; box-shadow: inset 3px 0 0 var(--accent); padding-left: 7px; }
.dayh { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.dayh .dn { font-size: .78rem; color: var(--mute); text-transform: uppercase; }
.dayh .dd { font-size: 1.1rem; font-weight: 700; }
.dayh.today { background: var(--accent); }
.dayh.today .dn, .dayh.today .dd { color: var(--on-accent); }
.we { background: var(--we); }
.evc { border: 0; background: transparent; display: flex; flex-direction: column; gap: 2px; padding: 2px; align-items: stretch; justify-content: center; overflow: hidden; }
.evc.we { background: var(--we); }
.chip { display: block; font-size: .7rem; line-height: 1.25; padding: 1px 4px; border-radius: 4px; background: var(--brand); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.more { font-size: .7rem; color: var(--mute); }
.av { display: flex; gap: 1px; }
.av.today { background: var(--today); }
.av.today .half.empty { background: transparent; }
.half { flex: 1; min-width: 0; border: 0; border-radius: 5px; font-size: 1.05rem; padding: 0; overflow: hidden; }
.half.empty { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--line) 5px 6px); }
.av.we .half.empty { background: transparent; }

/* Maand */
.month { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.mh { text-align: center; font-size: .78rem; color: var(--mute); text-transform: uppercase; padding: 4px 0; }
.mc { min-height: 84px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); padding: 3px; display: flex; flex-direction: column; gap: 2px; align-items: stretch; text-align: left; overflow: hidden; }
.mc.we { background: var(--we); }
.mc.out { background: var(--bg); }
.mc.out .mnum { color: var(--mute); font-weight: 500; }
.mc.out .chip, .mc.out .dots { opacity: .6; }
.mc.today { border: 2px solid var(--accent); }
.mnum { font-weight: 700; font-size: .95rem; }
.mc.today .mnum { color: var(--accent); }
.dots { margin-top: auto; display: flex; flex-wrap: wrap; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dot.me { outline: 1.5px solid var(--ink); }
@media (min-width: 700px) { .mc { min-height: 110px; padding: 6px; } .dot { width: 11px; height: 11px; } .chip { font-size: .8rem; } }

/* Jaar */
.year { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .year { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .year { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mini { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.minit { width: 100%; min-height: 44px; border: 0; background: transparent; font-weight: 700; text-transform: capitalize; color: var(--accent); }
.minig { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; }
.minih { text-align: center; font-size: .68rem; color: var(--mute); text-transform: uppercase; }
.yd { aspect-ratio: 1; min-height: 22px; border: 0; border-radius: 4px; background: transparent; font-size: .74rem; padding: 0; position: relative; }
.yd.we { color: var(--mute); }
.yd.h1, i.h1 { background: rgba(var(--heat), .25); }
.yd.h2, i.h2 { background: rgba(var(--heat), .55); }
.yd.h3, i.h3 { background: rgb(168, 60, 38); color: #fff; }
.yd.ev::after, i.evdot::after { content: ""; position: absolute; left: 50%; bottom: 1px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--accent); }
.yd.today { box-shadow: inset 0 0 0 2px var(--ink); font-weight: 800; }

/* Afspraken */
.agenda { margin-top: 14px; }
.agenda h3, #sheetbody h4 { margin: 14px 0 6px; font-size: .95rem; }
.evrow { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 2px 10px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; }
.evwhen { color: var(--mute); font-size: .88rem; }
.evtitle { font-weight: 600; overflow-wrap: anywhere; }
.evnote { grid-column: 1 / -1; color: var(--mute); font-size: .88rem; overflow-wrap: anywhere; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 4px 12px calc(20px + env(safe-area-inset-bottom)); max-width: 1500px; margin: 0 auto; font-size: .88rem; color: var(--mute); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg i { position: relative; display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 5px; font-style: normal; font-size: .85rem; }

/* Venster */
dialog { border: 0; padding: 0; background: var(--card); color: var(--ink); width: min(560px, 100%); max-width: 100%; max-height: 92dvh; border-radius: 16px; overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
@media (max-width: 600px) { dialog { margin: auto 0 0; border-radius: 16px 16px 0 0; } }
.sheethead { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.sheethead h3 { margin: 0; font-size: 1.05rem; }
.sheethead h3::first-letter { text-transform: uppercase; }
#sheetbody { padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: .85rem; color: var(--mute); margin-bottom: 3px; }
input[type="text"], input[type="date"], input[type="time"], select, textarea { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input[type="color"] { width: 44px; min-width: 44px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check.sm { font-size: .82rem; gap: 4px; white-space: nowrap; }
.stbtns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stbtn { min-height: 52px; border: 0; border-radius: 12px; font-weight: 600; font-size: 1rem; padding: 4px 8px; overflow-wrap: anywhere; }
.stbtn.clear, .stbtn.plain { background: var(--bg); border: 1px solid var(--line); }
.stbtn.sel { border: 2px solid var(--accent); }
.actions, .menu { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.menu { flex-direction: column; align-items: stretch; }
.menu .pill { min-height: 48px; text-align: left; }
.daylist { display: grid; gap: 4px; }
.dayrow { display: grid; grid-template-columns: minmax(70px, 1fr) 1.3fr 1.3fr; gap: 4px; align-items: center; }
.dayrow.me .dayname { font-weight: 800; }
.dayname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daybtn { min-height: 46px; border: 0; border-radius: 8px; padding: 2px 6px; text-align: left; font-size: .9rem; line-height: 1.15; overflow: hidden; }
.daybtn small { display: block; font-size: .68rem; opacity: .75; }
.daybtn.empty { background: var(--bg); border: 1px dashed var(--line); color: var(--mute); }
.arow { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.arow input[type="text"] { flex: 1; min-width: 0; }
.arow input.emo { flex: 0 0 52px; text-align: center; padding: 8px 2px; }
@media (max-width: 480px) { .arow.st { flex-wrap: wrap; } .arow.st input[type="text"]:not(.emo) { flex: 1 1 40%; } }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 99; max-width: 92vw; background: var(--ink); color: var(--card); font-weight: 600; padding: 12px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }

@media (max-width: 480px) {
  .brand { display: none; }
  #addev { padding: 0 10px; }
  .bar2 { flex-wrap: wrap; }
  #label { order: -1; flex: 0 0 100%; font-size: .95rem; margin-bottom: 6px; }
  #today { flex: 1; }
  main { padding: 6px; }
  .rowh, .corner { font-size: .8rem; }
}
@media print {
  .bar { position: static; background: none; color: #000; }
  .tabs, .icon, .pill, #toast { display: none !important; }
  body { background: #fff; }
}
