:root {
  --bg: #f4f7fb; --surface: #fff; --surface2: #f8fafc; --border: #e3e9f2;
  --text: #0f172a; --muted: #64748b; --primary: #2563eb; --primary-h: #1d4ed8; --primary-soft: #e8f0ff;
  --danger: #dc2626; --danger-soft: #fee2e2; --ok: #16a34a; --ok-soft: #dcfce7;
  --side: #0f1b33; --side-text: #cbd5e1; --shadow: 0 6px 24px rgba(15,23,42,.08);
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #121c30; --surface2: #172338; --border: #24324d;
  --text: #e8eefb; --muted: #94a3b8; --primary: #3b82f6; --primary-h: #60a5fa; --primary-soft: #14284d;
  --danger: #f87171; --danger-soft: #3b1620; --ok: #4ade80; --ok-soft: #12301f;
  --side: #08101f; --side-text: #94a3b8; --shadow: 0 6px 24px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; }
.muted { color: var(--muted); margin: 0; }
.grow { flex: 1; min-width: 0; } .grow2 { flex: 2; }
i[data-i] { display: inline-flex; width: 20px; height: 20px; flex: none; }
i[data-i] svg { width: 100%; height: 100%; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 24px 16px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 20px; margin: 0 8px 28px; }
.logo { width: 34px; height: 34px; color: #3b82f6; flex: none; } .logo.big { width: 44px; height: 44px; }
.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-radius: 10px; background: none; color: inherit; cursor: pointer; text-align: left; font-weight: 500; }
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: #2b4a8c; color: #fff; }
.theme-switch { display: flex; align-items: center; gap: 8px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.theme-switch i { width: 18px; height: 18px; }
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.slider { position: absolute; inset: 0; background: #3b82f6; border-radius: 99px; transition: .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 23px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: #475569; } .switch input:checked + .slider::after { left: 3px; }
.switch input:focus-visible + .slider { outline: 2px solid #fff; outline-offset: 2px; }

.main { padding: 28px 32px 60px; min-width: 0; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.page-head h1 { font-size: 28px; letter-spacing: -.02em; }
.banner { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); border-radius: 12px; padding: 12px 16px; margin-bottom: 18px; font-weight: 500; }
.banner.warn { background: #fef3c7; color: #92400e; border-color: #f59e0b; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; transition: .15s; min-height: 44px; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; } .btn.primary:hover { background: var(--primary-h); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; } :root[data-theme="dark"] .btn.danger { color: #1a0b0b; }
.btn.ghost { background: transparent; }
.btn.lg { padding: 12px 24px; min-height: 50px; font-size: 16px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: none; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface2); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.stat-ic { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.stat-ic i { width: 24px; height: 24px; }
.stat.blue .stat-ic { background: #2563eb; } .stat.green .stat-ic { background: #16a34a; } .stat.purple .stat-ic { background: #7c3aed; }
.stat.blue { background: color-mix(in srgb, #2563eb 8%, var(--surface)); }
.stat.green { background: color-mix(in srgb, #16a34a 8%, var(--surface)); }
.stat.purple { background: color-mix(in srgb, #7c3aed 8%, var(--surface)); }
.stat-l { font-size: 13px; color: var(--muted); } .stat-v { font-size: 28px; font-weight: 700; line-height: 1.2; } .stat-v.sm { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat-v.sm > #statLast { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.2); } .dot.off { background: var(--danger); }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.search { flex: 1 1 320px; position: relative; }
.search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; height: 52px; padding: 0 16px 0 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; }
.field-sm { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.field-sm select { height: 52px; min-width: 150px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 15px; }
.search input:focus, select:focus, input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.toolbar .btn { height: 52px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 20px; } .card h3 { margin-bottom: 14px; font-size: 17px; }
.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface2); }
td.title { font-weight: 600; min-width: 160px; } td.isbn { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.note { color: var(--muted); font-size: 13px; max-width: 260px; } .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td.date { white-space: nowrap; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; }
.act { width: 40px; height: 40px; border-radius: 10px; border: 0; display: grid; place-items: center; cursor: pointer; background: var(--primary-soft); color: var(--primary); }
.act.del { background: var(--danger-soft); color: var(--danger); } .act:hover { filter: brightness(.95); }
.count { margin-top: 10px; font-size: 13px; }

.cover { width: 56px; height: 80px; border-radius: 6px; background: var(--surface2); border: 1px solid var(--border); overflow: hidden; display: grid; place-items: center; color: var(--muted); flex: none; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover i { width: 26px; height: 26px; }
.cover.xl { width: 150px; height: 220px; }
.letter { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.color { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); flex: none; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 90px 1fr 32px; gap: 10px; align-items: center; font-size: 14px; }
.bar-track { height: 12px; background: var(--surface2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.latest { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
.latest .item { cursor: pointer; text-align: center; font-size: 13px; }
.latest .cover { width: 100%; height: 190px; margin-bottom: 8px; }
.latest b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(8,15,30,.6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; overflow-y: auto; }
.dialog { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.35); max-height: calc(100vh - 32px); overflow-y: auto; }
.dialog.wide { max-width: 900px; } .dialog.narrow { max-width: 460px; }
.dlg-head { display: flex; gap: 14px; align-items: flex-start; padding: 22px 24px 8px; }
.dlg-head h2 { font-size: 20px; }
.dlg-ic { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; flex: none; }
.dlg-ic.danger { background: var(--danger); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 22px; border-top: 1px solid var(--border); margin-top: 8px; }
.pad-x { padding: 4px 24px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 24px 4px; }
.mode { display: flex; gap: 12px; align-items: center; text-align: left; padding: 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; }
.mode small { display: block; color: var(--muted); } .mode b { display: block; }
.mode.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); }
.mode i { width: 28px; height: 28px; color: var(--primary); }
#form { padding: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 230px; gap: 20px; padding: 16px 24px 0; }
.row { display: flex; gap: 14px; } .row > * { min-width: 0; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.field input, .field select, .field textarea, .isbn-row input { padding: 11px 12px; min-height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 400; font-size: 15px; width: 100%; }
.field textarea { resize: vertical; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; font-size: 14px; font-weight: 500; }
.isbn-tools { margin-bottom: 14px; }
.isbn-row { display: flex; gap: 8px; flex-wrap: wrap; } .isbn-row input { flex: 1 1 200px; width: auto; }
.info { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-top: 10px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-size: 13px; }
.scanner { margin-top: 12px; border: 2px dashed var(--border); border-radius: 12px; padding: 10px; text-align: center; }
#reader { width: 100%; min-height: 60px; overflow: hidden; border-radius: 8px; }
.preview { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; align-self: start; box-shadow: none; text-align: center; }
.preview h4 { align-self: flex-start; }
.pv-title { font-weight: 700; } .pv-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: 13px; color: var(--muted); }
.view-body { display: flex; gap: 24px; padding: 16px 24px; }
.details { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-content: start; min-width: 0; }
.details dt { color: var(--muted); font-size: 13px; } .details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 10px; z-index: 100; width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: slide .25s ease; border-left: 4px solid var(--ok); }
.toast.edit { border-left-color: var(--primary); } .toast.error { border-left-color: var(--danger); background: var(--danger-soft); }
.toast i { color: var(--ok); } .toast.edit i { color: var(--primary); } .toast.error i { color: var(--danger); }
.toast b { display: block; } .toast span { font-size: 13px; color: var(--muted); }
.toast button { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; }
@keyframes slide { from { opacity: 0; transform: translateX(30px); } }

.bottom-nav { display: none; }

@media (max-width: 1000px) {
  .stats { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 16px 96px; }
  .page-head { flex-wrap: wrap; } .page-head h1 { font-size: 22px; } .page-head .muted { font-size: 13px; }
  .page-head .btn { width: 100%; }
  .logo.big { display: none; }
  .toolbar > * { flex: 1 1 100%; } .field-sm select { width: 100%; }
  .bottom-nav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 40; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav .nav-item { flex-direction: column; gap: 2px; font-size: 11px; padding: 8px 4px; align-items: center; color: var(--muted); text-align: center; }
  .bottom-nav .nav-item.active { background: var(--primary-soft); color: var(--primary); }
  .form-grid { grid-template-columns: 1fr; } .preview { order: -1; flex-direction: row; flex-wrap: wrap; text-align: left; }
  .preview .cover.xl { width: 70px; height: 100px; } .preview h4 { display: none; }
  .row { flex-direction: column; gap: 0; }
  .modes { grid-template-columns: 1fr; }
  .view-body { flex-direction: column; align-items: center; }
  .toasts { top: auto; bottom: 84px; right: 16px; }

  /* tabel wordt kaartenlijst: nog steeds één rij (kaart) per boek */
  table, tbody { display: block; } thead { display: none; }
  tbody tr { display: grid; grid-template-columns: 70px 1fr; gap: 4px 14px; padding: 14px; border-bottom: 1px solid var(--border); }
  td { display: block; padding: 0; border: 0; }
  td.cv { grid-row: span 6; } td.title, td.isbn, td.c-letter, td.c-color, td.note, td.date { grid-column: 2; max-width: none; min-width: 0; }
  td.act-cell { grid-column: 1 / -1; margin-top: 8px; } .actions { justify-content: flex-start; }
  .act { width: 48px; height: 44px; }
  .cover { width: 70px; height: 100px; }
}

.login { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 36px 28px; max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.login-card .btn { width: 100%; }
.user-box { display: flex; flex-direction: column; gap: 8px; padding: 12px 8px; font-size: 13px; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.sm { min-height: 36px; padding: 6px 12px; color: var(--side-text); border-color: rgba(255,255,255,.2); }
@media (max-width: 820px) { .bottom-nav { grid-template-columns: repeat(5, 1fr); } }
.login-form { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 4px; }
.login-form .field { margin-bottom: 8px; }
.login-ok { color: var(--ok); background: var(--ok-soft); padding: 12px 14px; border-radius: 10px; font-weight: 500; margin: 0; }

.color-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.color-form input[type=color] { width: 52px; height: 46px; padding: 2px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.color-form input:not([type=color]) { flex: 1 1 200px; min-height: 46px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.color-list { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.color-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface2); }
.color-item .swatch { width: 28px; height: 28px; }
.color-item .ci-name { font-weight: 600; } .color-item .ci-meta { font-size: 12px; color: var(--muted); }
