/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #e8e0d4;
  --text-muted: #888;
  --accent: #c8a96e;
  --accent-hover: #dbbf88;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --success: #27ae60;
  --link: #c8a96e;
  --badge-bg: #2a2a2a;
  --radius: 4px;
  --font: 'Georgia', 'Times New Roman', serif;
  --font-ui: system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Header & nav ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.nav-brand {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-decoration: none;
}
.nav-brand:hover { color: var(--accent-hover); text-decoration: none; }

.nav-links { display: flex; gap: 1.5rem; flex: 1; }
.nav-links a { font-family: var(--font-ui); font-size: 0.9rem; color: var(--text-muted); }
.nav-links a:hover { color: var(--text); text-decoration: none; }

.search-form { display: flex; gap: 0.4rem; margin-left: auto; }
.search-form input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  width: 220px;
  font-family: var(--font-ui);
}
.search-form input:focus { outline: none; border-color: var(--accent); }
.search-form button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
}

/* ── Main content ── */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Flash ── */
.flash {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding: 0.7rem 1rem;
  margin-bottom: 1.2rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.6rem; font-weight: normal; letter-spacing: 0.02em; }
.actions { display: flex; gap: 0.6rem; align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #000; text-decoration: none; }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); text-decoration: none; color: #fff; }
.btn-link { background: none; border: none; color: var(--link); cursor: pointer; font: inherit; padding: 0; }
.danger-link { color: var(--danger); }
.danger-link:hover { color: var(--danger-hover); }
.small-link { font-size: 0.8rem; font-family: var(--font-ui); }

/* ── Count badge ── */
.count { font-size: 0.85rem; color: var(--text-muted); font-family: var(--font-ui); font-weight: normal; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  background: var(--badge-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  color: var(--text-muted);
  text-decoration: none;
}
.badge:hover { color: var(--text); text-decoration: none; border-color: var(--accent); }
.badge--large { padding: 0.25rem 0.75rem; font-size: 0.85rem; }
.badge--learning { background: #1a2a1a; border-color: var(--success); color: var(--success); }
.badge--commissioned { background: #2a1a2a; border-color: #9b59b6; color: #be90d4; }

/* ── Filter panel ── */
details#filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
details#filter-panel summary {
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
details#filter-panel summary:hover { color: var(--text); }
details#filter-panel summary .badge { background: var(--accent); border-color: var(--accent); color: #000; }
details#filter-panel[open] summary { border-bottom: 1px solid var(--border); }

.filter-form { padding: 1rem; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.8rem 1rem;
}
.filter-group label { display: block; font-size: 0.78rem; font-family: var(--font-ui); color: var(--text-muted); margin-bottom: 0.2rem; }
.filter-group input, .filter-group select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-ui);
}
.filter-group input:focus, .filter-group select:focus { outline: none; border-color: var(--accent); }
.filter-group--inline { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filter-group--inline label { display: inline; white-space: nowrap; }
.filter-group--inline input { width: 90px; }
.filter-group--checks { display: flex; flex-direction: column; gap: 0.3rem; }
.filter-group--checks label { display: flex; align-items: center; gap: 0.4rem; color: var(--text); font-size: 0.85rem; cursor: pointer; }
.filter-actions { margin-top: 1rem; display: flex; gap: 0.6rem; }

/* ── Filter bar (simple inline form) ── */
.filter-bar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-bar input, .filter-bar select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-ui);
}
.filter-bar input:focus, .filter-bar select:focus { outline: none; border-color: var(--accent); }

/* ── Sort bar ── */
.sort-bar {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
  display: flex;
  gap: 0.8rem;
  align-items: center;
}
.sort-bar a { color: var(--text-muted); }
.sort-bar a.active { color: var(--accent); }
.sort-bar a:hover { color: var(--text); text-decoration: none; }

/* ── Data table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.5rem 0.8rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.data-table td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--surface); }
.data-table .center { text-align: center; }
.thumb-cell { width: 56px; text-align: center; padding: 4px; }
.img-indicator { font-size: 0.9rem; }
.row-thumb { max-width: 48px; max-height: 48px; object-fit: cover; border-radius: 2px; display: inline-block; }

/* ── Detail layout ── */
.detail-layout { display: flex; gap: 2rem; flex-wrap: wrap; }
.detail-main { flex: 1; min-width: 0; }

.detail-table { width: 100%; border-collapse: collapse; margin-bottom: 1.2rem; font-family: var(--font-ui); font-size: 0.875rem; }
.detail-table th { width: 160px; text-align: left; padding: 0.45rem 0.8rem 0.45rem 0; color: var(--text-muted); font-weight: 500; vertical-align: top; white-space: nowrap; }
.detail-table td { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }

.artwork-image { margin-bottom: 1.2rem; }
.artwork-image img { border: 1px solid var(--border); border-radius: var(--radius); }

/* ── Prose ── */
.prose { line-height: 1.7; white-space: pre-wrap; color: var(--text); font-size: 0.95rem; }

/* ── Cold reads ── */
.cold-reads-section { margin-top: 2.5rem; }
.section-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { font-size: 1.2rem; font-weight: normal; }

.cold-read-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.cr-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.cr-date { font-family: var(--font-ui); font-size: 0.82rem; color: var(--text-muted); }
.cr-actions { margin-left: auto; display: flex; gap: 0.8rem; align-items: center; }
.cr-section { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.cr-section:last-child { border-bottom: none; }
.cr-section h4 { font-size: 0.78rem; font-family: var(--font-ui); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.4rem; }
.cr-learning { background: #1a1f1a; }

/* ── Artwork context (cold read form) ── */
.artwork-context {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.2rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group--full { grid-column: 1 / -1; }
.form-group label { font-size: 0.82rem; font-family: var(--font-ui); color: var(--text-muted); }
.form-group small { font-size: 0.78rem; font-family: var(--font-ui); color: var(--text-muted); margin-top: 0.15rem; }
.required { color: var(--accent); }

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font-ui);
  width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea { resize: vertical; }

.form-fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1rem; grid-column: 1 / -1; }
.form-fieldset legend { font-size: 0.8rem; font-family: var(--font-ui); color: var(--text-muted); padding: 0 0.3rem; }
.inline-fields { display: flex; gap: 1rem; flex-wrap: wrap; }
.inline-fields label { font-size: 0.82rem; font-family: var(--font-ui); color: var(--text-muted); display: flex; flex-direction: column; gap: 0.3rem; }
.inline-fields input { width: 110px; }

.checkbox-list { display: flex; flex-direction: column; gap: 0.25rem; max-height: 200px; overflow-y: auto; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem; }
.checkbox-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-family: var(--font-ui); cursor: pointer; padding: 0.2rem 0.3rem; border-radius: 2px; }
.checkbox-item:hover { background: var(--surface); }
.checkbox-item input { width: auto; margin: 0; }

.radio-group { display: flex; gap: 1.5rem; }
.radio-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; font-family: var(--font-ui); cursor: pointer; }

.form-actions { display: flex; gap: 0.6rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }

/* ── Error display ── */
.error-list { margin-bottom: 1rem; }
.error { color: #e74c3c; font-family: var(--font-ui); font-size: 0.875rem; padding: 0.3rem 0; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Tag list ── */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }

/* ── Tag input widget ── */
.tag-input-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  padding: 0.35rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  cursor: text;
  min-height: 2.5rem;
}
.tag-input-wrapper:focus-within { border-color: var(--accent); }
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.1rem 0.5rem;
  font-size: 0.82rem;
  font-family: var(--font-ui);
  color: var(--text);
}
.tag-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-size: 1rem;
  font-family: var(--font-ui);
}
.tag-remove:hover { color: var(--danger-hover); }
#tag-text-input {
  border: none;
  background: none;
  outline: none;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-ui);
  min-width: 140px;
  flex: 1;
  padding: 0.1rem 0;
}
.tag-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  list-style: none;
  padding: 0.25rem 0;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}
.tag-suggestions li {
  padding: 0.35rem 0.8rem;
  font-size: 0.87rem;
  font-family: var(--font-ui);
  color: var(--text);
  cursor: pointer;
}
.tag-suggestions li:hover,
.tag-suggestions li[aria-selected="true"] {
  background: var(--surface2);
  color: var(--accent);
}

/* ── Search ── */
.search-form-large { display: flex; gap: 0.6rem; margin-bottom: 1.5rem; }
.search-form-large input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-ui);
}
.search-form-large input:focus { outline: none; border-color: var(--accent); }
.search-section { margin-bottom: 2rem; }
.search-section h2 { font-size: 1rem; font-family: var(--font-ui); color: var(--text-muted); margin-bottom: 0.6rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.search-snippet { font-size: 0.82rem; color: var(--text-muted); max-width: 500px; }
.search-snippet mark { background: #3a2e00; color: var(--accent); border-radius: 2px; padding: 0 2px; }
.result-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; font-family: var(--font-ui); }

/* ── Misc ── */
.empty { color: var(--text-muted); font-family: var(--font-ui); font-style: italic; padding: 2rem 0; }
.muted { color: var(--text-muted); }

/* ── Gallery ─────────────────────────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 1.5rem;
}

.gallery-item {
  position: relative;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  aspect-ratio: 3 / 4;
  margin: 0;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.gallery-item:hover img { transform: scale(1.04); }

.gallery-tooltip {
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  color: #fff;
  font-size: 0.75rem;
  font-family: var(--font-ui);
  padding: 1.5rem 0.5rem 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  line-height: 1.35;
}

.gallery-item:hover .gallery-tooltip { opacity: 1; }

/* ── Gallery modal (lightbox) ─────────────────────────────────────────── */
#gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gallery-modal[hidden] { display: none; }

#gallery-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.90);
}

#gallery-modal__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 95vh;
  z-index: 1;
}

#modal-img {
  max-width: 82vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: var(--radius);
  display: block;
}

#modal-info {
  margin-top: 0.75rem;
  text-align: center;
  color: var(--fg);
  font-family: var(--font-ui);
}

#modal-title {
  font-weight: 600;
  margin: 0 0 0.35rem;
}

#modal-links { margin: 0; }

#modal-links a {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
}
#modal-links a:hover { text-decoration: underline; }

#modal-close {
  position: absolute;
  top: -2.4rem;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#modal-close:hover { opacity: 1; }

#modal-prev, #modal-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  opacity: 0.7;
  transition: opacity 0.15s;
  z-index: 1001;
}
#modal-prev:hover, #modal-next:hover { opacity: 1; }
#modal-prev { left: 1rem; }
#modal-next { right: 1rem; }

/* ── Rating buttons & badges ── */
.rating-buttons, .study-button { display: inline-flex; gap: 0.35rem; align-items: center; }
.rating-btn { background: var(--surface2); color: var(--text-muted); border-color: var(--border); font-size: 0.8rem; padding: 0.3rem 0.65rem; cursor: pointer; border-radius: var(--radius); border-width: 1px; border-style: solid; }
.rating-btn:hover { color: var(--text); border-color: var(--accent); }
.rating-btn--active { background: var(--surface); border-color: var(--accent); color: var(--accent); }
.rating-badge { display: inline-block; min-width: 1.4em; text-align: center; font-size: 0.85rem; }
.filter-check { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.875rem; }

/* ── Image browse ── */
.input-with-btn { display: flex; gap: 0.5rem; align-items: center; }
.input-with-btn input { flex: 1; }
.file-browser-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 1000; align-items: center; justify-content: center; }
.file-browser-modal.open { display: flex; }
.file-browser-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: min(640px, 95vw); max-height: 80vh; display: flex; flex-direction: column; }
.file-browser-header { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.5rem; }
.file-browser-header input { flex: 1; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.35rem 0.6rem; font-size: 0.9rem; }
.file-browser-list { overflow-y: auto; flex: 1; }
.file-browser-list button { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--border); padding: 0.5rem 1rem; color: var(--text); font-family: var(--font-ui); font-size: 0.85rem; cursor: pointer; }
.file-browser-list button:hover { background: var(--surface2); color: var(--accent); }
.file-browser-empty { padding: 1.5rem 1rem; text-align: center; color: var(--text-muted); font-family: var(--font-ui); font-size: 0.875rem; }
.file-browser-footer { padding: 0.6rem 1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

/* ── Clipboard paste (artworks list) ── */
button.paste-btn { background: none; border: 0; padding: 0 0.15rem; margin: 0; cursor: pointer; font: inherit; color: inherit; line-height: 1; vertical-align: baseline; }
button.paste-btn:hover { color: var(--accent); }
button.paste-btn[disabled] { cursor: wait; opacity: 0.6; }
button.paste-btn.paste-btn--error { color: #d44; }

.paste-spinner { display: inline-block; width: 0.9em; height: 0.9em; border: 2px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -0.15em; }
@keyframes spin { to { transform: rotate(360deg); } }

#paste-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
#paste-modal .modal-card { background: var(--surface); border: 1px solid var(--border); padding: 1.5rem; border-radius: var(--radius); max-width: 760px; width: min(95vw, 760px); }
#paste-modal h3 { font-family: var(--font-ui); color: var(--text); margin-bottom: 0.6rem; }
#paste-modal .compare { display: flex; gap: 1rem; margin: 1rem 0; }
#paste-modal .compare figure { margin: 0; flex: 1; text-align: center; display: flex; flex-direction: column; gap: 0.4rem; align-items: center; }
#paste-modal .compare img { max-width: 100%; max-height: 320px; border: 1px solid var(--border); border-radius: 2px; }
#paste-modal figcaption { font-size: 0.78rem; font-family: var(--font-ui); }

#toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.6rem 1.2rem; border-radius: var(--radius); font-family: var(--font-ui); font-size: 0.85rem; opacity: 0; transition: opacity 0.25s; z-index: 1100; pointer-events: none; }
#toast.toast--show { opacity: 1; }

/* ── Auth pages ── */
.auth-card { max-width: 24rem; margin: 3rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.auth-card h1 { margin-bottom: 1rem; font-size: 1.4rem; }
.auth-card p { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.95rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form label { display: flex; flex-direction: column; font-family: var(--font-ui); font-size: 0.85rem; color: var(--text-muted); }
.auth-form input { margin-top: 0.3rem; padding: 0.6rem 0.7rem; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; }
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-form button { padding: 0.7rem 1rem; background: var(--accent); color: var(--bg); border: 0; border-radius: var(--radius); font-weight: bold; cursor: pointer; }
.auth-form button:hover { background: var(--accent-hover); }
.auth-form-inline { display: inline-flex; align-items: end; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.auth-form-inline label { display: flex; flex-direction: column; font-family: var(--font-ui); font-size: 0.85rem; color: var(--text-muted); }
.auth-form-inline input, .auth-form-inline select { margin-top: 0.3rem; padding: 0.5rem 0.6rem; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); }
.auth-form-inline button { padding: 0.55rem 0.9rem; background: var(--accent); color: var(--bg); border: 0; border-radius: var(--radius); cursor: pointer; }
.auth-form-inline button.danger { background: var(--danger); color: var(--text); }
.auth-form-inline button.danger:hover { background: var(--danger-hover); }
.auth-error { background: rgba(192,57,43,0.15); color: var(--danger-hover); border: 1px solid var(--danger); padding: 0.6rem 0.8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.auth-recovery { margin-top: 1.5rem; }
.auth-recovery summary { cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
.link-button { background: transparent !important; color: var(--text-muted) !important; padding: 0 !important; font-size: 0.85rem; text-decoration: underline; cursor: pointer; }
.totp-qr { display: block; margin: 1rem auto; background: white; padding: 8px; border-radius: 4px; max-width: 220px; }
.totp-secret { text-align: center; font-family: var(--font-ui); font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; word-break: break-all; }
.recovery-codes { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; font-family: var(--font-ui); font-size: 1rem; line-height: 1.8; margin: 1rem 0; }
.auth-new-key { border-color: var(--accent); }
.new-key-value { background: var(--surface2); padding: 0.8rem; border-radius: var(--radius); word-break: break-all; font-family: var(--font-ui); font-size: 0.9rem; user-select: all; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 1.5rem; font-family: var(--font-ui); font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); text-align: left; }
.data-table tr.revoked { color: var(--text-muted); }

/* ── Table scroll wrapper — always allow wide tables to scroll horizontally
   inside their own box rather than blowing out the viewport ── */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Responsive: tablet (≤ 900px) ─────────────────────────────────────── */
@media (max-width: 900px) {
  .nav { gap: 1rem; padding: 0 1rem; }
  .search-form input { width: 160px; }
  .detail-table th { width: auto; padding-right: 0.6rem; }
  .form-grid { grid-template-columns: 1fr; gap: 0.9rem; }
  .filter-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .main-content { padding: 1.2rem 1rem; }
  .nav-links { gap: 1rem; }
}

/* ── Responsive: phone (≤ 600px) ──────────────────────────────────────── */
@media (max-width: 600px) {
  html { font-size: 14px; }
  .main-content { padding: 1rem 0.8rem; }

  /* Nav: stacks brand+account on row 1, links wrap on row 2, search row 3 */
  .nav {
    height: auto;
    flex-wrap: wrap;
    padding: 0.5rem 0.8rem;
    gap: 0.5rem 0.8rem;
  }
  .nav-brand { flex: 0 0 auto; }
  .nav-links {
    order: 3;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 0.5rem 0.9rem;
  }
  .nav-links a { font-size: 0.85rem; }
  .search-form {
    order: 4;
    flex: 1 1 100%;
    margin-left: 0;
  }
  .search-form input { width: 100%; min-width: 0; flex: 1; }
  .nav-account { margin-left: auto; font-size: 0.85rem; }
  .nav-account a, .nav-account .link-button { font-size: 0.85rem; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  .page-header h1 { font-size: 1.3rem; }
  .actions { flex-wrap: wrap; }

  /* Data tables: tighter cells on phones (scroll wrapper handles overflow) */
  .data-table { font-size: 0.82rem; }
  .data-table th, .data-table td { padding: 0.4rem 0.5rem; }

  /* Detail tables stack key/value vertically */
  .detail-table, .detail-table tbody, .detail-table tr { display: block; }
  .detail-table th, .detail-table td {
    display: block;
    width: auto;
    padding: 0.2rem 0;
    border: none;
    white-space: normal;
  }
  .detail-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 0.6rem; }
  .detail-table tr { border-bottom: 1px solid var(--border); padding: 0.3rem 0 0.5rem; }
  .detail-table tr:last-child { border-bottom: none; }

  .detail-layout { gap: 1rem; }

  /* Filters and forms */
  .filter-grid { grid-template-columns: 1fr; }
  .filter-actions { flex-wrap: wrap; }
  .filter-bar { gap: 0.4rem; }
  .form-grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .form-actions { flex-wrap: wrap; }
  .inline-fields { gap: 0.6rem; }
  .inline-fields input { width: 100%; }
  .radio-group { flex-wrap: wrap; gap: 0.8rem; }

  /* Search */
  .search-form-large { flex-direction: column; }
  .search-form-large input { font-size: 0.95rem; }

  /* Gallery — denser columns */
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
  .gallery-tooltip { font-size: 0.7rem; padding: 1.2rem 0.4rem 0.4rem; }

  /* Lightbox tweaks for thumb-friendly reach */
  #modal-img { max-width: 92vw; max-height: 72vh; }
  #modal-close {
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #modal-prev, #modal-next {
    font-size: 1.4rem;
    padding: 0.4rem 0.7rem;
  }
  #modal-prev { left: 0.3rem; }
  #modal-next { right: 0.3rem; }

  /* Cold-read cards */
  .cr-header { padding: 0.5rem 0.8rem; gap: 0.4rem; }
  .cr-section { padding: 0.6rem 0.8rem; }
  .cr-actions { margin-left: 0; flex-basis: 100%; }

  /* Paste modal */
  #paste-modal .compare { flex-direction: column; }
  #paste-modal .compare img { max-height: 220px; }

  /* Auth */
  .auth-card { margin: 1.5rem auto; padding: 1.4rem; }
  .auth-form-inline { flex-direction: column; align-items: stretch; }
  .auth-form-inline input, .auth-form-inline select, .auth-form-inline button { width: 100%; }

  /* File browser modal */
  .file-browser-box { width: 95vw; max-height: 85vh; }
}
