/* Curio-Cabinet component styles. Semantic tokens only (tokens.css). */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* the hidden attribute must win over component display rules */
[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  line-height: var(--leading-tight);
  font-weight: 640;
  margin: 0 0 var(--space-3);
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.94em;
}

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Shell ------------------------------------------------------------------ */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--header-h);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.site-title {
  font-weight: 650;
  color: var(--text);
  font-size: var(--text-base);
  letter-spacing: -0.01em;
}
.site-title:hover { text-decoration: none; color: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-sm);
}

.site-footer {
  margin-top: auto;
  padding: var(--space-5) var(--space-4);
  text-align: center;
  font-size: var(--text-xs);
}
.quiet { color: var(--text-faint); }

.page {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}
.page-narrow { max-width: 560px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.page-head h1 { margin: 0; }

.muted { color: var(--text-muted); }
.empty-dash { color: var(--text-faint); }

/* Buttons ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 14px;
  min-height: 36px;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-raised); text-decoration: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: color-mix(in oklab, var(--accent) 88%, black); }

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 45%, var(--border));
  background: transparent;
}
.btn-danger:hover { background: color-mix(in oklab, var(--danger) 8%, transparent); }

.btn-sm { min-height: 28px; padding: 3px 9px; font-size: var(--text-xs); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  padding: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--text); background: var(--accent-soft); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--accent);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.inline-form { display: inline; }

/* Chips ---------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--surface);
}
.chip-sm { padding: 1px 7px; margin-right: 4px; }

/* Flashes ---------------------------------------------------------------------- */

.flashes { max-width: 1400px; margin: var(--space-3) auto 0; padding: 0 var(--space-4); }
.flash {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}
.flash-error { border-left-color: var(--danger); }

/* Forms ---------------------------------------------------------------------- */

.form-field { margin-bottom: var(--space-4); }
.form-field label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 570;
  margin-bottom: var(--space-1);
}
.req { color: var(--danger); }

input, textarea, select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: max(16px, var(--text-base)); /* prevents iOS focus zoom */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: transparent;
}
input[type="file"] { border: none; padding: 0; background: none; }

.input-unit { display: flex; align-items: center; gap: var(--space-2); }
.input-unit input { flex: 1; }
.unit-suffix { color: var(--text-muted); font-size: var(--text-sm); font-family: var(--font-mono); }

.hint { font-size: var(--text-xs); color: var(--text-faint); margin: var(--space-1) 0 0; }
.hint-inline { font-weight: 400; color: var(--text-faint); }
.field-error { color: var(--danger); font-size: var(--text-sm); margin: var(--space-1) 0 0; }
.has-error input, .has-error textarea, .has-error select { border-color: var(--danger); }

.form-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-4) var(--space-4) var(--space-2);
  margin: 0 0 var(--space-4);
}
.form-group legend, .form-group h2 {
  font-size: var(--text-sm);
  font-weight: 640;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0 var(--space-2);
}
.form-group h2 { padding: 0; margin-bottom: var(--space-3); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  column-gap: var(--space-4);
}

.form-actions {
  display: flex;
  gap: var(--space-3);
  position: sticky;
  bottom: 0;
  padding: var(--space-3) 0;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}

/* Auth ---------------------------------------------------------------------- */

.auth-card {
  margin: var(--space-7) auto 0;
  max-width: 360px;
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.totp-input {
  font-family: var(--font-mono);
  font-size: var(--text-xl) !important;
  letter-spacing: 0.4em;
  text-align: center;
}
.totp-qr { max-width: 220px; margin: var(--space-3) 0; }
.totp-qr svg { width: 100%; height: auto; background: white; border-radius: var(--radius-sm); padding: var(--space-2); }

/* Admin ---------------------------------------------------------------------- */

.admin-recent { list-style: none; padding: 0; margin: 0; }
.admin-recent li { border-bottom: 1px solid var(--border); }
.admin-recent a {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-1);
  color: var(--text);
}
.admin-recent a:hover { background: var(--accent-soft); text-decoration: none; }

/* dashboard "To finish" list: item link + chips for what's missing */
.admin-todo li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.admin-todo a { flex: 1; min-width: 200px; }
.todo-count {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: 2px;
}
.todo-missing { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.cfg-days { width: 64px; }
.field-hint { font-size: var(--text-sm); color: var(--text-faint); margin: var(--space-1) 0 0; }
.field-hint code { font-family: var(--font-mono); }

/* Dashboard "To do" — collapsible categories with inline actions */
.todo-cat {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  margin: var(--space-3) 0;
  background: var(--surface);
}
.todo-cat > summary {
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-lg);
  font-weight: 600;
  list-style-position: inside;
}
.todo-cat[open] > summary { border-bottom: 1px solid var(--border); }
.todo-group { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }
.todo-group:first-of-type { border-top: none; }
.todo-group-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2);
}
.todo-group-head h3 { font-size: var(--text-base); margin: 0; }
.todo-done-controls { display: flex; gap: var(--space-2); align-items: center; }
.todo-list { list-style: none; padding: 0; margin: 0; }
.todo-list li {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: 4px 0; border-bottom: 1px solid var(--border);
}
.todo-list li:last-child { border-bottom: none; }
.todo-fill-row input, .todo-fill-row select { max-width: 180px; }

/* Admin overview home */
.overview-cards { display: flex; flex-wrap: wrap; gap: var(--space-3); margin: var(--space-4) 0; }
.ov-card {
  flex: 1; min-width: 160px;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
}
.ov-card:hover { background: var(--accent-soft); text-decoration: none; }
.ov-num { font-size: var(--text-2xl); font-weight: 650; line-height: 1; }
.ov-label { font-size: var(--text-sm); color: var(--text-faint); }
.ov-alert { border-color: var(--danger); }
.ov-alert .ov-num { color: var(--danger); }
.overview-links { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-6); }
.ov-recent { margin-top: var(--space-4); }

/* To-Do + Customize view switcher reuses the existing .view-switch / .seg
   segmented control (defined below); just give it breathing room here. */
.view-switch { margin: var(--space-3) 0; }

/* To-Do status chips */
.st-overdue { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 45%, transparent); }
.st-soon { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 45%, transparent); }
.st-ok { color: var(--text-faint); border-color: var(--border); }

/* Gantt / timeline */
.gantt-lane { margin: var(--space-4) 0; }
.gantt-axis {
  display: flex; justify-content: space-between;
  font-size: var(--text-sm); color: var(--text-faint);
  font-family: var(--font-mono); margin-bottom: 2px;
}
.gantt-row { display: flex; align-items: center; gap: var(--space-3); padding: 3px 0; }
.gantt-label { flex: 0 0 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-track { flex: 1; min-width: 0; }
.gantt-today { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 2 2; }
.gbar.st-overdue { fill: var(--danger); }
.gbar.st-soon { fill: var(--accent); }
.gbar.st-ok { fill: color-mix(in oklab, var(--accent) 45%, var(--surface-raised)); }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: var(--space-3) 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.cal-wd { background: var(--surface-raised); text-align: center; font-size: var(--text-sm); font-weight: 600; padding: 4px; }
.cal-cell { background: var(--surface); min-height: 76px; padding: 3px; display: flex; flex-direction: column; gap: 2px; }
.cal-out { background: var(--bg); }
.cal-out .cal-day { color: var(--text-faint); }
.cal-today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day { font-size: var(--text-sm); color: var(--text-faint); }
.cal-ev {
  font-size: var(--text-sm); border-radius: 3px; padding: 1px 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--accent-soft); color: var(--text);
  border-left: 3px solid var(--accent);
}
.cal-ev.st-overdue { border-left-color: var(--danger); }

/* Due-soon buckets */
.bucket-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); }
.bucket { border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: var(--space-3); background: var(--surface); }
.bucket h3 { font-size: var(--text-base); margin: 0 0 var(--space-2); }
.bucket-overdue { border-top: 3px solid var(--danger); }
.bucket-week { border-top: 3px solid var(--accent); }
.private-badge {
  font-size: 0.7em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 0 4px;
  vertical-align: 1px;
}
.todo-chip {
  font-size: var(--text-sm);
  color: var(--danger);
  border: 1px solid color-mix(in oklab, var(--danger) 40%, transparent);
  border-radius: 999px;
  padding: 0 8px;
  white-space: nowrap;
}

.admin-gallery {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: 0;
}
.admin-gallery li {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: var(--surface);
}
.admin-gallery img { display: block; border-radius: var(--radius-sm); margin-bottom: var(--space-2); }
.gallery-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.upload-zone {
  display: block;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: var(--space-3);
}
.upload-zone:hover { border-color: var(--accent); color: var(--text); }

.danger-zone { margin-top: var(--space-6); }

/* Detail ---------------------------------------------------------------------- */

.detail { display: grid; gap: var(--space-5); }
@media (min-width: 768px) {
  .detail { grid-template-columns: minmax(0, 55%) minmax(0, 1fr); align-items: start; }
  .detail-gallery { position: sticky; top: calc(var(--header-h) + var(--space-4)); }
}
.detail-gallery img {
  width: 100%;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  background: var(--surface);
}
.no-image {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.spec-group { margin-top: var(--space-5); }
.spec-list { margin: 0; }
.spec-row {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.spec-row dt { color: var(--text-muted); font-size: var(--text-sm); }
.spec-row dd { margin: 0; font-size: var(--text-sm); }

/* Empty states ----------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--text-muted);
}
.empty-state .btn { margin-top: var(--space-3); }
.empty-head { font-weight: 600; color: var(--text); margin: var(--space-2) 0 0; }

/* Browse layout -------------------------------------------------------------- */

.browse {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4);
}

.browse-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}

.filters-btn { gap: 6px; }
.filter-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: var(--text-xs);
  font-weight: 600;
}

.search-form { position: relative; flex: 1 1 200px; min-width: 160px; }
.search-form .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none;
}
.search-form input[type="search"] { max-width: 360px; padding-left: 32px; }

.view-switch {
  display: inline-flex;
  flex-wrap: wrap;              /* longer tab sets (Customize) wrap on mobile */
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg {
  padding: 7px 12px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.seg:last-child { border-right: none; }
.seg:hover { background: var(--surface-raised); text-decoration: none; }
.seg.is-active { background: var(--accent); color: var(--accent-contrast); }

/* Toolbar dropdown (Fields / Columns) */
.dd { position: relative; }
.dd > summary {
  list-style: none;
  cursor: pointer;
  gap: 6px;
}
.dd > summary::-webkit-details-marker { display: none; }
.dd-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 230px;
  max-height: 60vh;
  overflow-y: auto;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
}
.dd-hint { font-size: var(--text-xs); color: var(--text-muted); margin: 0 0 var(--space-2); }
.dd-opt { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: var(--text-sm); }
.dd-opt input { width: auto; }

/* Filter chips above results */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}
.chip.removable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in oklab, var(--accent) 35%, var(--border));
  color: var(--text);
  font-size: var(--text-sm);
}
.chip.removable:hover { text-decoration: none; background: color-mix(in oklab, var(--accent) 16%, var(--surface)); }
.chip .chip-label { color: var(--text-muted); }
.chip .chip-x { color: var(--text-faint); font-size: 0.85em; }
.chip.removable:hover .chip-x { color: var(--danger); }
.chip-clear { font-size: var(--text-sm); color: var(--text-muted); margin-left: var(--space-1); }

.results-head { margin-bottom: var(--space-3); }
.result-count { font-size: var(--text-sm); color: var(--text-muted); }
.results.htmx-request { opacity: 0.55; transition: opacity var(--dur) var(--ease) 150ms; }

/* Card meta line */
.card-sep { color: var(--border-strong); margin: 0 4px; }

/* Cards ---------------------------------------------------------------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
  gap: var(--space-4);
}
@media (max-width: 560px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  color: var(--text);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-2);
  border-color: color-mix(in oklab, var(--accent) 40%, var(--border));
}
.card-media { aspect-ratio: 4 / 3; background: var(--surface-raised); }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-noimg { display: block; width: 100%; height: 100%;
  background: repeating-linear-gradient(45deg, var(--surface-raised), var(--surface-raised) 10px, var(--surface) 10px, var(--surface) 20px); }
.card-body { padding: var(--space-3); display: flex; flex-direction: column; gap: 2px; }
.card-title { font-weight: 570; font-size: var(--text-sm); line-height: 1.3; }
.card-meta { font-size: var(--text-xs); color: var(--text-muted); }

.card-check {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: color-mix(in oklab, var(--text) 30%, transparent);
  display: none;
  z-index: 2;
}
body.selecting .card-check { display: block; }
.card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card.is-selected .card-check {
  background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'%3E%3Cpath d='M6.5 11L3 7.5l1-1 2.5 2.5L12 3.5l1 1z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

/* Table ---------------------------------------------------------------------- */

.table-scroll {
  overflow: auto;
  max-height: calc(100dvh - var(--header-h) - 120px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}
.data-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: var(--text-sm);
}
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: color-mix(in oklab, var(--surface) 96%, transparent);
  backdrop-filter: blur(6px);
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td, .data-table tbody tr:hover .col-sticky { background: var(--accent-soft); }
.data-table thead a { color: inherit; }
.sort-caret { color: var(--accent); }

.col-sticky {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  max-width: 160px;
}
thead .col-sticky { z-index: 4; }
.col-sticky a { display: flex; align-items: center; gap: var(--space-2); color: var(--text); }
.col-sticky img { border-radius: var(--radius-sm); object-fit: cover; }
.cell-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.preset-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.preset-tab {
  padding: 4px 12px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}
.preset-tab:hover { background: var(--surface-raised); text-decoration: none; color: var(--text); }
.preset-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 560;
}

/* Filter panel (accordion facets) ------------------------------------------- */

.facet { border-bottom: 1px solid var(--border); }
.facet > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 2px;
  font-weight: 550;
  font-size: var(--text-sm);
}
.facet > summary::-webkit-details-marker { display: none; }
.facet-name { flex: 1; }
.facet-name .facet-unit { color: var(--text-faint); font-weight: 400; font-family: var(--font-mono); font-size: 0.9em; }
.facet-count {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: 999px;
  background: var(--accent); color: var(--accent-contrast);
  font-size: var(--text-xs); font-weight: 600;
}
.facet-count:empty { display: none; }
.facet-chevron { color: var(--text-faint); transition: transform var(--dur-fast) var(--ease); }
.facet[open] > summary .facet-chevron { transform: rotate(180deg); }

.facet-body { padding: 0 2px var(--space-3); }
.facet-search { margin-bottom: var(--space-2); }
.facet-opts { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; overscroll-behavior: contain; }
.facet-opt {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 5px 6px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 400; cursor: pointer;
}
.facet-opt:hover { background: var(--accent-soft); }
.facet-opt input { width: auto; }
.facet-range { display: flex; align-items: center; gap: var(--space-2); }
.facet-range input { width: 100%; }
.range-dash { color: var(--text-faint); }

/* Analytics (breakdown chart + distribution histogram) ---------------------- */

.analyze-modes {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.analyze-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.analyze-controls label { font-size: var(--text-sm); color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.analyze-controls select { min-width: 180px; }

/* Horizontal breakdown bar chart */
.hchart { display: flex; flex-direction: column; gap: var(--space-2); }
.hbar-row {
  display: grid;
  grid-template-columns: minmax(90px, 26%) 1fr auto;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.hbar-track { background: var(--surface-raised); border-radius: var(--radius-sm); height: 22px; overflow: hidden; }
.hbar {
  display: block;
  height: 100%;
  width: var(--bar, 0%);
  min-width: 2px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  transition: width var(--dur) var(--ease);
}
.hbar-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar-sub { color: var(--text-faint); font-size: var(--text-xs); }

/* Vertical distribution histogram */
.histo {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 200px;
  padding-top: var(--space-4);
}
.histo-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.histo-count { font-size: var(--text-xs); color: var(--text-faint); font-variant-numeric: tabular-nums; }
.histo-bar {
  width: 100%;
  height: var(--bar, 0%);
  min-height: 2px;
  background: var(--accent);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: height var(--dur) var(--ease);
}
.histo-axis {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.histo-axis .histo-unit { color: var(--text-faint); }

/* Mobile bar + sheet + tray -------------------------------------------------- */

.mobile-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 25;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
@media (min-width: 768px) { .mobile-bar { display: none; } }
.mobile-bar-btn {
  flex: 1;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 550;
  border-radius: var(--radius-sm);
  position: relative;
}
/* Filter slide-over: right panel on desktop, bottom sheet on mobile -------- */

.filters-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: var(--backdrop);
  display: flex;
  justify-content: flex-end;   /* panel on the right (desktop) */
}
.filters-panel {
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: 100%;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  animation: slideInRight var(--dur) var(--ease);
}
@keyframes slideInRight { from { transform: translateX(20px); opacity: 0.6; } }
.filters-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.filters-head strong { font-size: var(--text-lg); }
.filters-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--space-4); }
.filters-foot {
  display: flex; gap: var(--space-3);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.filters-foot .btn { flex: 1; }

@media (max-width: 767px) {
  .filters-backdrop { align-items: flex-end; justify-content: stretch; }
  .filters-panel {
    width: 100%;
    height: auto;
    max-height: 88dvh;
    border-left: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: slideUp var(--dur) var(--ease);
  }
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0.6; } }
body.panel-open { overflow: hidden; }

.selection-tray {
  position: fixed;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;              /* above the mobile bar (25), below the filter sheet (40) */
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: calc(100vw - 2 * var(--space-3));
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  /* inverted pill: reads as a solid, floating snackbar in both themes,
     instead of a white-on-near-white card that fades into the page */
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
  border-radius: 999px;
  box-shadow: 0 6px 24px oklch(0 0 0 / 0.28), 0 2px 6px oklch(0 0 0 / 0.2);
}
/* lift clear of the mobile bottom bar so they don't overlap */
@media (max-width: 767px) {
  .selection-tray { bottom: calc(64px + env(safe-area-inset-bottom)); }
}
.tray-count { font-size: var(--text-sm); font-weight: 600; white-space: nowrap; }
/* buttons sit on the inverted pill, so re-derive their colors from --bg */
.selection-tray .btn {
  background: transparent;
  border-color: color-mix(in oklab, var(--bg) 45%, transparent);
  color: var(--bg);
}
.selection-tray .btn:hover {
  background: color-mix(in oklab, var(--bg) 16%, transparent);
}
.selection-tray [data-share-open] {   /* primary action stays the accent */
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.selection-tray [data-share-open]:hover {
  background: color-mix(in oklab, var(--accent) 88%, white);
}

.share-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  max-width: 440px;
  width: calc(100vw - 2 * var(--space-4));
  background: var(--surface);
  color: var(--text);
}
.share-dialog::backdrop { background: var(--backdrop); }
.share-dialog input { margin: var(--space-3) 0; }

.list-head { margin-bottom: var(--space-4); }
.list-cta { margin-top: var(--space-6); text-align: center; }

/* CSV import ---------------------------------------------------------------- */

.import-report {
  margin: var(--space-5) 0;
  padding: var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.import-errors {
  margin: var(--space-3) 0;
  padding: var(--space-3);
  max-height: 40vh;
  overflow-y: auto;
  list-style: none;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--danger);
  background: color-mix(in oklab, var(--danger) 6%, var(--surface));
  border-radius: var(--radius-sm);
}
.import-errors li { margin: 2px 0; }
.import-confirm { display: flex; gap: var(--space-3); margin-top: var(--space-4); }
.import-upload { max-width: 440px; }

/* keep content clear of the fixed mobile bar */
@media (max-width: 767px) {
  .browse-main { padding-bottom: 72px; }
}

/* Mobile: clear the fixed bottom bar so the footer (Admin link) isn't hidden */
@media (max-width: 767px) {
  body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* Share dialog fields */
.share-name { display: block; font-size: var(--text-sm); font-weight: 550; margin-top: var(--space-3); }
.share-dialog input[type="text"] { margin: var(--space-1) 0 0; }

/* Customize (live config editor) -------------------------------------------- */
.color-row { display: flex; align-items: center; gap: var(--space-2); }
.color-row input[type="color"] {
  width: 44px; height: 38px; flex: none; padding: 2px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.color-hex { max-width: 130px; text-transform: lowercase; }
.color-presets { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.color-chip { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1px solid var(--border-strong); cursor: pointer; }

.cfg-fields { display: flex; flex-direction: column; gap: var(--space-3); }
.cfg-field { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); background: var(--surface); }
.cfg-field-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2); }
.cfg-label { max-width: 260px; font-weight: 600; }
.cfg-key { color: var(--text-faint); font-size: var(--text-xs); }
.cfg-toggles { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-4); align-items: center; font-size: var(--text-sm); }
.cfg-toggles .chk, .cfg-toggles .sel { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.cfg-toggles select { width: auto; min-width: 0; padding: 4px 8px; font-size: var(--text-sm); }
.cfg-values { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); font-size: var(--text-sm); }
.cfg-values input { max-width: 340px; }

input[type="checkbox"], input[type="radio"] { width: auto; }

.cfg-presets { list-style: none; padding: 0; margin: 0 0 var(--space-3); }
.cfg-presets li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); }
.cfg-add { margin-top: var(--space-2); }
.cfg-add > summary { display: inline-flex; list-style: none; cursor: pointer; }
.cfg-add > summary::-webkit-details-marker { display: none; }
.cfg-add form { margin-top: var(--space-4); }
.cfg-cols { grid-column: 1 / -1; }
.cfg-colgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; margin-top: var(--space-1); }
.cfg-colgrid .chk { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: 400; }
