:root {
  --rowH: 26px;
  --collH: 20px;
  --bg: #111827;
  --bg2: #1f2937;
  --bg3: #273548;
  --border: #374151;
  --divider: #4b5563;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --blue: #3b82f6;
  --headH: 74px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-box { width: 100%; max-width: 320px; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.login-box label { text-align: center; font-size: 14px; font-weight: 500; }
.login-box input {
  background: var(--bg2); border: 1px solid #4b5563; color: var(--text);
  border-radius: 10px; padding: 12px 16px; text-align: center; font-size: 18px; outline: none;
}
.login-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(59,130,246,.4); }
.login-error { color: #f87171; font-size: 13px; text-align: center; min-height: 16px; }
.login-box button {
  background: #2563eb; color: #fff; font-weight: 600; border: none;
  padding: 12px; border-radius: 10px; font-size: 15px; cursor: pointer;
}
.login-box button:disabled { opacity: .4; cursor: not-allowed; }
.login-box button:hover:not(:disabled) { background: #1d4ed8; }

/* ---------- App-frame ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.header {
  display: flex; align-items: center; height: 46px; padding: 0 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: relative; flex-shrink: 0;
}
.header-left { display: flex; gap: 6px; align-items: center; z-index: 2; }
.header-title {
  position: absolute; left: 0; right: 0; text-align: center;
  font-weight: 700; font-size: 17px; pointer-events: none;
}
.header-right { margin-left: auto; z-index: 2; }
.home-circle {
  width: 32px; height: 32px; background: #000; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.hbtn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 10px; font-size: 12.5px; cursor: pointer;
}
.hbtn:hover { background: #33445c; }
.sync { font-size: 13px; color: #4ade80; padding: 0 4px; min-width: 18px; text-align: center; }
.sync.saving { color: #facc15; }
.sync.error { color: #f87171; cursor: pointer; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
  flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin;
}
.weeknav { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tbtn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 4px 9px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.tbtn:hover { background: #33445c; }
.tbtn.active { background: #2563eb; border-color: #2563eb; }
.now-btn { font-weight: 700; color: #93c5fd; }
.datepick {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 3px 5px; font-size: 12px; width: 34px; cursor: pointer;
}
.weeklabel { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 0 4px; }

.chips { display: flex; gap: 5px; align-items: center; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 2px solid transparent; border-radius: 14px; padding: 3px 10px;
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex-shrink: 0;
  color: #111; line-height: 1.35;
}
.chip.dark-text { color: #111; }
.chip.light-text { color: #fff; }
.chip.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.chip .key { opacity: .55; font-weight: 400; margin-right: 3px; font-size: 10px; }
.eraser { background: #4b5563; color: #fff; }
.toolbar-right { display: flex; gap: 6px; align-items: center; flex-shrink: 0; margin-left: auto; }

/* ---------- Statistieken ---------- */
.stats-panel {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 8px 12px; flex-shrink: 0; max-height: 40vh; overflow-y: auto;
}
.stats-table { border-collapse: collapse; font-size: 12.5px; min-width: 420px; }
.stats-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 14px 3px 0; }
.stats-table td { padding: 3px 14px 3px 0; }
.stats-row { cursor: pointer; }
.stats-row:hover td { background: rgba(255,255,255,.04); }
.stats-row.hl td { background: rgba(59,130,246,.18); }
.stats-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.stats-note { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Mobile daynav ---------- */
.mobile-nav {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 5px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#mobDayLabel { font-size: 13px; font-weight: 600; min-width: 170px; text-align: center; }

/* ---------- Bord ---------- */
.board-scroll { flex: 1; overflow: auto; overscroll-behavior: none; }
.board-inner { display: flex; min-width: min-content; }

.time-gutter {
  position: sticky; left: 0; z-index: 30; width: 40px; flex-shrink: 0;
  background: var(--bg); border-right: 1px solid var(--border);
}
.time-gutter .gutter-head {
  position: sticky; top: 0; height: var(--headH); background: var(--bg); z-index: 2;
  border-bottom: 1px solid var(--border);
}
.gutter-body { position: relative; }
.gutter-slot { position: absolute; right: 4px; font-size: 9.5px; color: var(--muted); transform: translateY(-55%); }
.gutter-coll { position: absolute; left: 0; right: 0; text-align: center; font-size: 8.5px; color: var(--muted); display: flex; align-items: center; justify-content: center; }

.day { flex: 1 1 0; min-width: 240px; display: flex; flex-direction: column; position: relative; }
.day + .day { border-left: 1px solid var(--divider); }

.day-head {
  position: sticky; top: 0; z-index: 20; height: var(--headH);
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 3px 4px 0;
}
.day.today .day-head { background: #1e3a5f; }
.dh-line1 { display: flex; align-items: center; justify-content: center; gap: 6px; }
.dh-name { font-weight: 700; font-size: 13px; }
.day.today .dh-name { color: #93c5fd; }
.dh-date { font-size: 11px; color: var(--muted); }
.dh-line2 { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 1px; }
.dh-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 1px 4px; border-radius: 5px; }
.dh-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.dh-btn.locked { color: #fbbf24; }
.match-badge { font-size: 10.5px; padding: 1px 7px; border-radius: 9px; background: var(--bg3); color: var(--muted); }
.match-badge.good { background: #14532d; color: #4ade80; }
.match-badge.mid { background: #713f12; color: #fbbf24; }
.match-badge.bad { background: #7f1d1d; color: #fca5a5; }
.dh-cols { display: flex; margin-top: auto; }
.dh-col { flex: 1; text-align: center; font-size: 10px; color: var(--muted); padding: 2px 0; border-top: 1px solid var(--border); }
.dh-col + .dh-col { border-left: 1px solid var(--border); }

.day-body { display: flex; position: relative; }
.col { flex: 1; position: relative; min-width: 0; }
.col + .col { border-left: 1px solid var(--border); }

.col-coll {
  position: relative; height: var(--collH); background: rgba(0,0,0,.35);
  border-bottom: 1px solid var(--divider); overflow: hidden; cursor: pointer;
}
.col-coll .mini { position: absolute; left: 0; right: 0; }

.col-grid { position: relative; }
.grid-lines {
  position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom,
      transparent 0, transparent calc(var(--rowH) * 2 - 1px),
      rgba(255,255,255,.13) calc(var(--rowH) * 2 - 1px), rgba(255,255,255,.13) calc(var(--rowH) * 2)),
    repeating-linear-gradient(to bottom,
      transparent 0, transparent calc(var(--rowH) - 1px),
      rgba(255,255,255,.05) calc(var(--rowH) - 1px), rgba(255,255,255,.05) var(--rowH));
}

.block {
  position: absolute; left: 1px; right: 1px; border-radius: 4px;
  font-size: 10.5px; font-weight: 600; overflow: hidden; padding: 1px 4px;
  line-height: 1.25; cursor: pointer; user-select: none; -webkit-user-select: none;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.block.note-block { display: block; text-align: left; }
.block.light-text { color: #fff; }
.block.dark-text { color: #111827; }
.block.note-block { background: #33415580; border: 1px solid #64748b; color: #e2e8f0; font-weight: 400; white-space: pre-wrap; }
.block.deleted-cat { opacity: .8; }
.block .dev-triangle {
  position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-left: 8px solid transparent; border-top: 8px solid #fb923c;
}
.board-inner.hl-mode .block:not(.hl):not(.note-block) { opacity: .12; }

.ghost {
  position: absolute; left: 1px; right: 1px; border-radius: 4px;
  background: rgba(59,130,246,.35); border: 1.5px dashed #60a5fa; pointer-events: none; z-index: 5;
}

.now-line {
  position: absolute; left: 0; right: 0; height: 0; z-index: 6; pointer-events: none;
  border-top: 2px solid var(--blue);
}
.now-line::before {
  content: ""; position: absolute; left: -1px; top: -5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--blue);
}

/* ---------- Modal & popover ---------- */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 14px;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
}
.modal-box h2 { font-size: 15px; margin-bottom: 12px; }
.modal-box h3 { font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.modal-close { float: right; background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-close:hover { color: #fff; }

.pinned-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.pinned-cell { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.pinned-swatch { width: 100%; aspect-ratio: 1; border-radius: 6px; border: 1px solid rgba(255,255,255,.25); cursor: pointer; }
.pinned-hex {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  font-size: 8.5px; border-radius: 4px; padding: 2px 1px; text-align: center;
}

.cat-row { display: flex; align-items: center; gap: 7px; padding: 4px 0; }
.cat-dot { width: 24px; height: 24px; border-radius: 7px; border: 1px solid rgba(255,255,255,.3); cursor: pointer; flex-shrink: 0; }
.cat-name {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 8px; font-size: 13px; min-width: 0;
}
.cat-hex {
  width: 76px; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 6px; font-size: 12px; font-family: monospace; flex-shrink: 0;
}
.cat-del { background: none; border: none; color: #f87171; font-size: 15px; cursor: pointer; padding: 3px 6px; flex-shrink: 0; }
.cat-del:hover { background: rgba(248,113,113,.15); border-radius: 5px; }
.cat-move { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 3px; flex-shrink: 0; }
.cat-move:hover { color: #fff; }
.cat-move:disabled { opacity: .25; cursor: default; }
.cat-add { display: flex; gap: 7px; margin-top: 10px; }
.btn-primary {
  background: #2563eb; border: none; color: #fff; border-radius: 7px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.btn-danger { background: #7f1d1d; border: none; color: #fecaca; border-radius: 7px; padding: 6px 12px; font-size: 13px; cursor: pointer; }

.popover {
  position: fixed; z-index: 70; background: var(--bg2); border: 1px solid var(--divider);
  border-radius: 10px; padding: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.55);
  width: 230px; max-height: 60vh; overflow-y: auto;
}
.pop-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.pop-item {
  display: flex; align-items: center; gap: 7px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); font-size: 12.5px;
  padding: 5px 7px; border-radius: 6px; cursor: pointer;
}
.pop-item:hover { background: rgba(255,255,255,.07); }
.pop-item .stats-dot { margin-right: 0; }
.pop-sep { border-top: 1px solid var(--border); margin: 5px 0; }
.pop-textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px; font-size: 13px; font-family: inherit; resize: vertical; min-height: 56px;
}
.pop-range { display: flex; gap: 5px; align-items: center; margin: 7px 0; font-size: 12px; color: var(--muted); }
.pop-range select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 5px; padding: 3px; font-size: 12px;
}
.pop-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 7px; }

.settings-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; }
.settings-row input[type=range] { flex: 1; }
.copy-days { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 10px 0; }
.copy-days label { display: flex; gap: 7px; align-items: center; font-size: 13px; padding: 4px; }

/* ---------- Mobiel ---------- */
@media (max-width: 900px) {
  .day { min-width: 0; }
  .header-title { font-size: 15px; }
  .weeklabel { display: none; }
}
