:root {
  --bg: #0e0f11;
  --surface: #151719;
  --surface-2: #1c1f22;
  --surface-3: #23272b;
  --border: #2a2e33;
  --text: #e4e6eb;
  --text-dim: #8e949d;
  --accent: #e36c5a;
  --accent-dim: #7a372c;
  --danger: #d55;
  --ok: #6fc26f;
  --rail-w: 200px;
  --rail-w-narrow: 64px;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  height: 100vh;
  overflow: hidden;
}
body.no-rail { justify-content: center; align-items: center; }

a { color: var(--text); text-decoration: none; }
a:hover { color: #fff; }

hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--text-dim); }

/* ─────── Left rail ─────── */

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0 12px;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail .brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 16px 12px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.06em;
}
.rail .brand-glyph { display: inline-block; }

.rail-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.rail-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-weight: 500;
  transition: background-color 120ms, color 120ms;
}
.rail-list a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.rail-list a.active {
  background: var(--surface-3);
  color: var(--text);
}
.rail-list a svg {
  flex-shrink: 0;
}

.rail-active {
  padding: 6px 20px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-version {
  padding: 2px 20px 6px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.5;
}
.rail-user {
  padding: 8px 12px 0;
  margin: 8px 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rail-user-name {
  color: var(--text-dim);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-logout-form { margin: 0; }
.rail-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
}
.rail-logout:hover { color: var(--text); background: var(--surface-2); }

/* ─────── Main ─────── */

.main {
  flex: 1;
  min-width: 0;
  padding: 32px;
  max-width: calc(100% - var(--rail-w));
  overflow-y: auto;
  height: 100vh;
}
body.no-rail .main {
  padding: 32px;
  max-width: 480px;
  width: 100%;
}

.page-header { margin: 0 0 24px; }
.page-header h1 { margin: 0; font-weight: 600; font-size: 22px; }

.empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--text-dim);
}

/* ─────── Cards / Forms ─────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
}
.card-narrow { max-width: 420px; }
.card h1 { margin: 0 0 12px; font-weight: 600; font-size: 22px; }
.card > p { margin-top: 0; color: var(--text-dim); }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
}
.form label span { font-weight: 500; color: var(--text); }
.form label small { font-size: 12px; }
.form input[type=text],
.form input[type=password] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  transition: border-color 120ms;
}
.form input[type=text]:focus,
.form input[type=password]:focus {
  outline: none;
  border-color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-dim); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #c85a48; border-color: #c85a48; }

.alert {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 13px;
}
.alert.error { background: rgba(221, 85, 85, 0.1); border-color: var(--danger); color: #ffb9b9; }
.alert.ok    { background: rgba(111, 194, 111, 0.1); border-color: var(--ok); color: #bde5bd; }

/* ─────── Library ─────── */

body:has(.library) .main,
body:has(.liked-page) .main { padding: 0; overflow: hidden; }
.liked-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.library {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  margin: 0;
  height: 100vh;
}
.folder-pane-overlay { display: none; }
.folder-pane {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 0 0 16px;
  overflow-y: auto;
  height: 100%;
}
.folder-pane-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.expand-depth-ctrl { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.expand-depth-ctrl .btn { font-size: 13px; padding: 1px 7px; line-height: 1.4; }
.depth-label { font-size: 11px; min-width: 26px; text-align: center; color: var(--text-dim); user-select: none; }
.recursive-toggle { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.recursive-toggle input { margin: 0; }
.tree-search-input {
  width: 100%;
  box-sizing: border-box;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 120ms;
}
.tree-search-input:focus { border-color: var(--accent); }
.tree-search-input::placeholder { color: var(--text-dim); }

.folder-tree { padding: 0 8px; font-size: 13px; }
.tree-node { }
.tree-node.selected-subtree {
  outline: 2px solid var(--accent);
  border-radius: 6px;
}
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  padding-left: calc(6px + var(--d, 0) * 12px);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
}
.tree-row:hover { background: var(--surface-2); color: var(--text); }
.tree-row.active { background: var(--surface-3); color: var(--text); }
.tree-caret {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 11px;
  border-radius: 4px;
  user-select: none;
  transition: background 120ms, color 120ms;
}
.tree-caret:not(:empty) { cursor: pointer; }
.tree-caret:not(:empty):hover { background: var(--surface-3); color: var(--text); }
.tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { color: var(--text-dim); font-size: 11px; }
.ctx-menu {
  position: fixed;
  z-index: 9999;
  background: rgba(28,31,34,.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  padding: 4px 0;
  min-width: 160px;
  font-size: 13px;
}
.ctx-menu button {
  all: unset;
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.ctx-menu button:hover { background: var(--surface-2); }
.ctx-menu button.danger:hover { color: var(--danger); }

.library-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.lib-header-area {
  flex: 0 0 auto;
  padding: 20px 24px 0;
  border-bottom: 1px solid var(--border);
}
.lib-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 10px;
  min-height: 42px;
}
.bulk-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.lib-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.filter-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.filter-select, .filter-date {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
  line-height: 1.4;
  cursor: pointer;
}
.filter-select:focus, .filter-date:focus {
  outline: none;
  border-color: var(--accent);
}
.filter-date::-webkit-calendar-picker-indicator { filter: invert(0.5); opacity: 0.65; cursor: pointer; }
.filter-date::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.btn.filter-active { border-color: var(--accent); color: var(--accent); }
.btn.filter-active:hover { background: var(--accent-dim); border-color: var(--accent); }
.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.scan-status-text {
  font-size: 0.8em;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scan-pbar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}
.scan-pbar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 600ms ease;
}
.lib-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 24px;
}

/* ─────── Grid ─────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
}
.cell {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 4px;
}
.cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms;
}
.cell:hover img { transform: scale(1.03); }
.play-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,.5);
  opacity: .9;
  pointer-events: none;
}
.play-badge svg { filter: drop-shadow(0 2px 4px rgba(0,0,0,.7)); }
.like-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms, color 120ms, background 120ms;
}
.cell:hover .like-btn,
.like-btn.liked { opacity: 1; }
.like-btn.liked { color: var(--accent); }
.like-btn:hover { background: rgba(0,0,0,.75); }

.page-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.header-actions { display: flex; gap: 8px; }
#upload-btn { cursor: pointer; }
.upload-status {
  margin: 0 0 16px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.upload-progress-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 150ms ease;
  width: 0%;
}
.folder-toggle-btn { display: none; }

.lib-scroll-area.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(227,108,90,.06);
}
.tree-row.drag-over {
  background: var(--surface-3);
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}

/* ─────── Duplicate filename highlight ─────── */
.grid.show-filenames .cell.dup-filename { outline: 2px solid var(--ok); outline-offset: -2px; }

/* ─────── Filename label overlay ─────── */
.cell-name {
  display: none;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(30,30,30,.82);
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  padding: 3px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.grid.show-filenames .cell-name { display: block; }
.filter-names-btn { margin-left: auto; }

/* ─────── Folder drag-drop highlight (task 3) ─────── */
.tree-row.drag-folder-over {
  background: rgba(227,108,90,.18);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.tree-row.drag-source { opacity: 0.5; }

/* ─────── Grid section headers (item 3) ─────── */
.grid-section-header {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 2px 2px;
  margin-top: 8px;
}
.grid-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: var(--border);
  margin: 8px 0 4px;
}

/* ─────── Selection mode (item 9) ─────── */
.cell-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  border-radius: 50%;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 120ms;
  pointer-events: none;
  z-index: 2;
}
.grid.select-mode .cell-check { opacity: 1; }
.cell.selected .cell-check { background: var(--accent); color: #fff; }
.cell.selected .chk-mark { display: block; }
.grid.select-mode .cell { cursor: default; }
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 5px;
}
.btn-danger {
  border-color: var(--danger);
  color: #ff9a8f;
}
.btn-danger:hover { background: #3a1a17; }

.cell .duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
}

/* ─────── Lightbox ─────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, .96);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 16px;
}
.lightbox[hidden] { display: none !important; }
.lb-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  position: relative;
  padding: 0 88px;
}
.lb-status {
  color: var(--text);
  background: rgba(0,0,0,.55);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.lb-status[hidden] { display: none !important; }
/* Item 13: images fill height */
.lb-image, .lb-video {
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  border-radius: 4px;
  transform-origin: center;
  transition: transform 150ms ease;
}
.lb-image { cursor: zoom-in; }
/* Item 7: bottom action bar */
.lb-bottom {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  margin-top: 10px;
  padding: 0 88px;
}
.lb-caption {
  color: var(--text-dim);
  font-size: 13px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.lb-actions .btn {
  text-decoration: none;
}
.lb-like-btn { gap: 4px; }
.lb-like-btn.liked { color: var(--accent); }
.lb-close, .lb-prev, .lb-next {
  position: absolute;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: 1px solid rgba(255,255,255,.25);
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
  cursor: pointer;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 32px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, transform 120ms;
  z-index: 10;
}
.lb-close:hover, .lb-prev:hover, .lb-next:hover { background: rgba(0,0,0,.85); transform: scale(1.05); }
.lb-prev:hover, .lb-next:hover { transform: translateY(-50%) scale(1.05); }
.lb-close { top: 16px; right: 20px; }
.lb-prev  { left: 20px; top: 50%; transform: translateY(-50%); }
.lb-next  { right: 20px; top: 50%; transform: translateY(-50%); }

/* Info panel */
.lb-info-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 5;
  padding: 16px;
}
.lb-info-panel[hidden] { display: none !important; }
.lightbox.info-open .lb-stage { padding-right: calc(88px + 280px); }
.lightbox.info-open .lb-bottom { padding-right: calc(88px + 280px); }
.lb-info-content { font-size: 12px; }
.info-section { margin-bottom: 14px; }
.info-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.info-row {
  display: flex;
  gap: 6px;
  padding: 2px 0;
  line-height: 1.4;
}
.info-label {
  color: var(--text-dim);
  flex: 0 0 90px;
  font-size: 11px;
}
.info-value {
  color: var(--text);
  flex: 1;
  word-break: break-word;
  font-size: 11px;
}

/* ─────── Move modal ─────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay[hidden] { display: none !important; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 380px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  all: unset;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  margin-top: 8px;
  display: block;
}
.modal-search:focus { outline: none; border-color: var(--accent); }
.modal-search::placeholder { color: var(--text-dim); }
.move-row.current-folder {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.modal-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  font-size: 13px;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.move-row {
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
}
.move-row:hover { background: var(--surface-2); color: var(--text); }
.move-row.active { background: var(--surface-3); color: var(--text); }

/* ─────── Roots / tables ─────── */

.roots-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.roots-table th,
.roots-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.roots-table th {
  font-weight: 500;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.roots-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .btn { padding: 6px 10px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.ok {
  background: rgba(111, 194, 111, 0.1);
  border-color: var(--ok);
  color: #bde5bd;
}

.progress-row td { background: var(--surface-2); }
.progress-line {
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-size: 13px;
}
.progress-phase {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  background: var(--accent-dim);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
}
.progress-path {
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dryrun-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  max-height: 280px;
  overflow: auto;
  font-size: 12px;
  color: var(--text-dim);
}

/* ─────── Responsive ─────── */

/* Tablet: narrow icon-only rail */
@media (min-width: 600px) and (max-width: 800px) {
  :root { --rail-w: var(--rail-w-narrow); }
  .main { max-width: calc(100% - var(--rail-w-narrow)); padding: 16px; }
  .rail-list a span { display: none; }
  .rail-user-name { display: none; }
  .rail-list a { justify-content: center; }
  .subnav { margin: -16px -16px 16px; padding: 16px 16px 0; top: -16px; }
}

/* Mobile: bottom tab bar, drawer folder pane */
@media (max-width: 599px) {
  /* Rail → fixed bottom tab bar */
  .rail {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 56px;
    flex: none;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 300;
  }
  .rail .brand { display: none; }
  .rail-list {
    flex-direction: row;
    padding: 0;
    flex: 1;
    gap: 0;
  }
  .rail-list li { flex: 1; }
  .rail-list a {
    flex-direction: column;
    justify-content: center;
    height: 56px;
    gap: 2px;
    padding: 6px 4px;
    font-size: 10px;
    border-radius: 0;
  }
  .rail-list a span { display: block; }
  .rail-list a.active { background: transparent; color: var(--accent); }
  .rail-user {
    flex-direction: row;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 0 12px;
    margin: 0;
    align-self: stretch;
    flex-shrink: 0;
  }
  .rail-user-name { display: none; }

  /* Main: full width, clear space for fixed bottom bar */
  .main {
    max-width: 100%;
    padding: 16px;
    padding-bottom: 72px;
    height: 100vh;
  }
  .subnav { margin: -16px -16px 16px; padding: 16px 16px 0; top: -16px; }
  body:has(.library) .main {
    padding: 0;
    height: calc(100vh - 56px);
  }

  /* Library: single column */
  .library {
    grid-template-columns: 1fr;
    height: 100%;
  }

  /* Folder pane: off-canvas drawer */
  .folder-pane {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: calc(100vh - 56px);
    z-index: 250;
    transition: left 200ms ease;
    box-shadow: 2px 0 20px rgba(0,0,0,.55);
    overflow-y: auto;
  }
  .folder-pane.drawer-open { left: 0; }

  /* Overlay behind the drawer */
  .folder-pane-overlay {
    display: none;
    position: fixed;
    inset: 0;
    bottom: 56px;
    background: rgba(0,0,0,.5);
    z-index: 249;
  }
  .folder-pane-overlay.visible { display: block; }

  /* Folders toggle button: only shown on mobile */
  .folder-toggle-btn { display: inline-flex; }

  /* ── General page headers: smaller on mobile ── */
  .page-header { margin-bottom: 12px; }
  .page-header h1 { font-size: 18px; }

  /* ── Library header: very compact — title + count inline, saves ~60px ── */
  .lib-header-area { padding: 4px 12px 0; }
  .lib-header-area .page-header { margin-bottom: 0; }
  .lib-header-area .page-header-row { align-items: center; gap: 6px; }
  .lib-header-area .page-header > div { display: flex; align-items: baseline; gap: 5px; flex: 1; min-width: 0; }
  .lib-header-area .page-header h1 { font-size: 15px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #lib-count { font-size: 11px; margin: 0; white-space: nowrap; flex-shrink: 0; }
  .lib-header-area .header-actions .btn { padding: 4px 10px; font-size: 12px; }

  /* Toolbar: wraps on small screens, compact height */
  .lib-toolbar { flex-wrap: wrap; min-height: 34px; padding: 4px 0 6px; gap: 6px; }
  .bulk-actions { flex-wrap: wrap; }

  /* Extra bottom padding so last grid row clears the tab bar */
  .lib-scroll-area { padding: 6px 10px 24px; }

  /* ── Touch targets: tree carets and depth buttons ── */
  .tree-caret { min-width: 28px; min-height: 28px; }
  .expand-depth-ctrl .btn { min-width: 30px; min-height: 30px; }

  /* ── Long-press visual feedback ── */
  .tree-row.lp-active { background: var(--surface-3); }

  /* ── Prevent iOS Safari auto-zoom on input focus ── */
  input, select, textarea { font-size: 16px !important; }

  /* ── Settings: momentum scrolling for tables ── */
  .card:has(table) { -webkit-overflow-scrolling: touch; }

  /* Grid: smaller cells */
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px; }

  /* Lightbox: compact */
  .lightbox { padding: 10px 8px 8px; }
  .lb-close {
    top: 8px; right: 8px;
    width: 40px; height: 40px; font-size: 22px;
  }
  .lb-prev {
    width: 40px; height: 40px; font-size: 22px; left: 4px;
  }
  .lb-next {
    width: 40px; height: 40px; font-size: 22px; right: 4px;
  }
  .lb-stage { padding: 0 44px; }
  .lb-bottom { padding: 0 8px; flex-wrap: wrap; gap: 4px; }
  .lb-caption { width: 100%; font-size: 11px; }
  .lb-actions { flex-wrap: wrap; gap: 4px; }

  /* Info panel → bottom sheet on mobile */
  .lb-info-panel {
    top: auto;
    left: 0; right: 0;
    width: 100%;
    height: 55vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
  }
  /* Undo right-padding adjustments (panel overlays from bottom) */
  .lightbox.info-open .lb-stage  { padding-right: 44px; }
  .lightbox.info-open .lb-bottom { padding-right: 8px; }

  /* Modal: full-width */
  .modal-box { width: calc(100vw - 24px); max-height: 80vh; }

  /* Settings cards: ensure tables scroll horizontally */
  .card { padding: 16px; }
  .card table { min-width: 400px; }
  .card > .card { padding: 0; }
  .roots-table { min-width: 400px; }
  .card:has(table) { overflow-x: auto; }
}

/* Settings sub-navigation */
.subnav {
  display: flex;
  gap: 8px;
  /* Pull up into .main's 32px padding so subnav spans full width and covers
     the padding area when sticky — prevents content bleeding above it. */
  margin: -32px -32px 16px;
  padding: 32px 32px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: -32px;
  z-index: 10;
}
.subnav a { padding:8px 14px; color:var(--text-dim); text-decoration:none; border-bottom:2px solid transparent; margin-bottom:-1px; }
.subnav a.active { color:var(--text); border-bottom-color:var(--accent); }
.subnav a:hover { color:var(--text); }

/* ──── Form controls inside cards (auto-style bare inputs/buttons/selects) ──── */
.card input[type=text],
.card input[type=password],
.card input[type=search],
.card input[type=number],
.card input:not([type]),
.card select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  transition: border-color 120ms;
}
.card input[type=text]:focus,
.card input[type=password]:focus,
.card input[type=search]:focus,
.card input[type=number]:focus,
.card input:not([type]):focus,
.card select:focus { outline: none; border-color: var(--text-dim); }
.card input[type=checkbox] { accent-color: var(--accent, #8ab4f8); }

.card button {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms;
}
.card button:hover { background: var(--surface-3); border-color: var(--text-dim); }
.card button.primary,
.card button[type=submit] {
  background: var(--accent, #8ab4f8);
  color: #0b0c0f;
  border-color: transparent;
}
.card button.primary:hover,
.card button[type=submit]:hover { filter: brightness(1.05); }
.card button.danger {
  border-color: #c2463a;
  color: #ff9a8f;
}
.card button.danger:hover { background: #3a1a17; }

.card table { width: 100%; border-collapse: collapse; }
.card table th, .card table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}
.card table th {
  color: var(--text-dim); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
}
.card table td code, .card table td strong { font-size: 13px; }
.card table td .muted { color: var(--text-dim); font-size: 12px; }

.card form { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  /* Grid cell: no zoom-in on hover */
  .cell img { transition: none; }
  .cell:hover img { transform: none; }

  /* Lightbox image: no zoom transition */
  .lb-image, .lb-video { transition: none; }

  /* Lightbox nav buttons: no scale pop on hover */
  .lb-close, .lb-prev, .lb-next { transition: background 120ms; }
  .lb-close:hover, .lb-prev:hover, .lb-next:hover { transform: none; }
  .lb-prev:hover, .lb-next:hover { transform: translateY(-50%); }

  /* Progress bars: instant fill */
  .upload-progress-fill, .scan-pbar-fill { transition: none; }

  /* Mobile drawer: no slide animation */
  .folder-pane { transition: none !important; }
}
.card .row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ─── Search people strip ─── */
.search-people-strip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 6px;
  flex-wrap: wrap;
}
.search-people-strip[hidden] { display: none !important; }
.search-people-label {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .05em;
  margin-right: 4px; white-space: nowrap;
}
.search-person-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px 3px 4px;
  text-decoration: none; color: var(--text);
  font-size: 13px; transition: border-color 120ms;
}
.search-person-chip:hover { border-color: var(--accent); color: var(--text); }
.search-person-thumb {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
}
.search-person-thumb-empty {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3); display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 14px;
}
.search-person-name { font-weight: 500; }
.search-person-count { font-size: 11px; color: var(--text-dim); }

/* ─────── btn-ghost ─────── */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

/* ─────── People page ─────── */
.people-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

#people-view, .person-detail {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.people-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.people-title { margin: 0; font-size: 18px; font-weight: 600; }
.people-count { color: var(--text-dim); font-size: 13px; }

.cluster-status {
  padding: 8px 20px;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 8px 20px 20px;
  overflow-y: auto;
  flex: 1;
}

.person-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 150ms, transform 150ms;
}
.person-card:hover { border-color: var(--text-dim); transform: translateY(-2px); }

.person-thumb {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface-2);
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
}
.person-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.person-thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--text-dim);
}

.person-info { padding: 8px 10px; }
.person-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-face-count { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

#people-view[hidden], .person-detail[hidden], #people-lb[hidden],
#people-empty[hidden], #cluster-status[hidden], #rename-form[hidden],
#unassigned-section[hidden], #unassigned-grid[hidden],
#merge-modal[hidden], #assign-modal[hidden] { display: none !important; }

/* ─── Person detail ─── */
.person-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.person-detail-name-wrap { display: flex; align-items: center; gap: 8px; flex: 1; }
.person-detail-name { font-size: 16px; font-weight: 600; }

.rename-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rename-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 13px;
  width: 220px;
}
.rename-input:focus { outline: none; border-color: var(--accent); }

.people-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px;
  padding: 12px 16px;
  overflow-y: auto;
  flex: 1;
}

.person-media-cell {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-2);
  border-radius: 4px;
}
.person-media-cell img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 150ms;
}
.person-media-cell:hover img { transform: scale(1.05); }

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
}

/* People page lightbox (minimal) */
.lb-open .people-lb-blocker { display: block; }
#people-lb {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#people-lb .lb-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 48px 64px;
  min-height: 0;
}
#people-lb #lb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
#people-lb .lb-bottom {
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
#people-lb .lb-close {
  position: absolute;
  top: 16px; right: 20px;
  background: none; border: none;
  color: var(--text); font-size: 24px;
  cursor: pointer; padding: 4px 8px;
  border-radius: 4px;
}
#people-lb .lb-close:hover { background: var(--surface-2); }
#people-lb .lb-prev, #people-lb .lb-next {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  background: none; border: none;
  color: var(--text); font-size: 40px;
  cursor: pointer; padding: 8px 16px;
  border-radius: 4px;
  line-height: 1;
}
#people-lb .lb-prev { left: 8px; }
#people-lb .lb-next { right: 8px; }
#people-lb .lb-prev:hover, #people-lb .lb-next:hover { background: var(--surface-2); }

/* ─── Person media cell overlays ─── */
.person-media-cell { position: relative; }
.cell-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 4px; gap: 4px;
  opacity: 0; transition: opacity 120ms;
  pointer-events: none;
}
.person-media-cell:hover .cell-overlay { opacity: 1; pointer-events: auto; }
.cell-btn {
  width: 26px; height: 26px;
  border: none; border-radius: 4px;
  font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 100ms;
}
.cell-btn-cover { background: rgba(0,0,0,.55); color: #ffd700; }
.cell-btn-cover:hover { background: rgba(0,0,0,.8); }
.cell-btn-remove { background: rgba(0,0,0,.55); color: #fff; }
.cell-btn-remove:hover { background: rgba(180,40,40,.8); }

/* ─── Unassigned faces section ─── */
.unassigned-section {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.unassigned-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; cursor: pointer; font-size: 13px; color: var(--text-dim);
  user-select: none;
}
.unassigned-header:hover { color: var(--text); background: var(--surface-2); }
.unassigned-toggle-icon { font-size: 11px; }
.unassigned-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 4px; padding: 8px 16px 16px;
  max-height: 260px; overflow-y: auto;
}
.unassigned-cell {
  position: relative; aspect-ratio: 1; overflow: hidden;
  border-radius: 4px; cursor: pointer;
  background: var(--surface-2);
}
.unassigned-cell img { width: 100%; height: 100%; object-fit: cover; transition: transform 120ms; }
.unassigned-cell:hover img { transform: scale(1.08); }
.unassigned-assign-hint {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: 10px; text-align: center; padding: 2px 0;
  opacity: 0; transition: opacity 120ms;
}
.unassigned-cell:hover .unassigned-assign-hint { opacity: 1; }

/* ─── Merge / Assign modals ─── */
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 400px; max-width: 94vw;
  max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-weight: 600; font-size: 14px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-hint { padding: 8px 16px 0; font-size: 12px; color: var(--text-dim); margin: 0; flex-shrink: 0; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
#merge-search, #assign-search { margin: 8px 16px; width: calc(100% - 32px); display: block; flex-shrink: 0; }
.merge-list {
  overflow-y: auto; flex: 1;
  padding: 4px 8px 8px;
}
.merge-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 6px; cursor: pointer;
}
.merge-item:hover { background: var(--surface-2); }
.merge-item-thumb {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.merge-item-thumb-empty {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-3); display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 18px;
}
.merge-item-name { font-size: 13px; font-weight: 500; }
.merge-item-count { font-size: 12px; color: var(--text-dim); }
.merge-empty { padding: 16px; text-align: center; color: var(--text-dim); font-size: 13px; }

/* ─── Assign face preview ─── */
.assign-face-preview { padding: 12px 16px 0; flex-shrink: 0; text-align: center; }
.assign-face-img { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }

/* ─── Sessions page ─── */
.session-user-heading {
  font-size: 15px; font-weight: 600;
  margin: 0 0 10px; color: var(--text);
}
.session-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.session-table th {
  text-align: left; padding: 6px 10px 6px 0;
  color: var(--text-dim); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.session-table td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.session-table tr:last-child td { border-bottom: none; }
.current-session-row td { background: rgba(227,108,90,.06); }
.merge-item-create { border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.merge-item-create:hover { background: rgba(227,108,90,.1); }
