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

/* =====================================================================
   Design tokens — light mode (Airtable-inspired)
   Dark mode (future) overrides on body.dark.
   ===================================================================== */
:root {
  /* Surfaces */
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --surface-3: #e8eaed;
  --surface2: var(--surface-2); /* legacy alias */

  /* Borders */
  --border: #e3e5e8;
  --border-strong: #d0d3d8;

  /* Text */
  --text: #1f2328;
  --text-muted: #6b7280;
  --text-subtle: #8a8f98;

  /* Accent */
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --accent-soft-hover: rgba(37, 99, 235, 0.16);

  /* Status */
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --error: var(--danger); /* legacy alias */

  /* Tag preset soft fills */
  --tag-key:    rgba(16, 185, 129, 0.14);   /* Avainkuva */
  --tag-key-fg: #047857;
  --tag-pick:   rgba(37, 99, 235, 0.14);    /* Valittu */
  --tag-pick-fg:#1d4ed8;
  --tag-arc:    rgba(107, 114, 128, 0.16);  /* Arkisto */
  --tag-arc-fg: #4b5563;
  --tag-out:    rgba(239, 68, 68, 0.12);    /* Ei käytössä */
  --tag-out-fg: #b91c1c;
  --tag-star:   rgba(245, 158, 11, 0.18);
  --tag-star-fg:#b45309;
  --tag-custom: rgba(37, 99, 235, 0.10);
  --tag-custom-fg: #1d4ed8;

  /* Radii */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-popover: 0 8px 24px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);

  /* Focus ring */
  --focus-ring: 0 0 0 2px rgba(37, 99, 235, 0.35);

  /* Spacing scale (for ad-hoc use) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Typography scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
}

html, body { overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  font-size: var(--fs-md);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom scrollbars (light-mode friendly, never on dark lightbox) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }
.lightbox *::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-color: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

nav {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  box-shadow: var(--shadow-sm);
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--fs-sm);
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}

nav a:hover { color: var(--text); background: var(--surface-2); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}
main.wide { max-width: 1700px; display: flex; gap: 1.25rem; align-items: flex-start; }
main.wide > .main-col {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0 0;
}
main.wide.coll-sidebar-hidden { gap: 0; }
.coll-sidebar[hidden] { display: none; }
#coll-sidebar-toggle.is-active { background: var(--accent-soft); color: var(--accent); }

/* Collection sidebar — left rail listing the workspace's collection tree with
   per-branch counts. Click a row to filter the table/gallery to that branch
   (full match OR any descendant). Cmd/Ctrl-click toggles multi-select. */
.coll-sidebar {
  flex: 0 0 auto;
  width: 240px;
  position: sticky;
  top: 1rem;
  align-self: flex-start;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  box-shadow: var(--shadow-sm);
  font-size: 0.88rem;
}
.coll-sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.4rem;
  padding: 0 0.25rem;
}
.coll-sidebar-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.coll-sidebar-body { display: flex; flex-direction: column; gap: 1px; }
.coll-row {
  display: flex; align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  color: var(--text);
  position: relative;
}
.coll-row:hover { background: var(--surface-2); }
.coll-row.is-active { background: var(--accent-soft); color: var(--accent); }
.coll-row.is-active .coll-count { color: var(--accent); }
.coll-row.is-all { font-weight: 600; }
.coll-toggle {
  flex: 0 0 14px;
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-subtle);
  font-size: 0.7rem;
  border-radius: 3px;
  cursor: pointer;
}
.coll-toggle.is-leaf { visibility: hidden; }
.coll-toggle:hover { background: var(--border); color: var(--text); }
.coll-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coll-count {
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.coll-children { display: flex; flex-direction: column; gap: 1px; padding-left: 14px; }
.coll-children.is-collapsed { display: none; }
.coll-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
}
@media (max-width: 900px) {
  main.wide { flex-direction: column; }
  .coll-sidebar { position: static; width: 100%; max-height: 320px; }
}

h1 { font-size: var(--fs-xl); font-weight: 600; margin-bottom: 1.25rem; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-lg); font-weight: 600; margin-bottom: 0.75rem; color: var(--text); }
h3 { font-size: var(--fs-md); font-weight: 600; }

/* =====================================================================
   Buttons — modern flat design with consistent sizing
   .btn          → primary (filled accent)
   .btn-secondary → outline
   .btn-ghost    → text-only, subtle hover
   .btn-danger   → destructive
   .btn-sm / default md / .btn-lg
   ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 32px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-lg { height: 40px; padding: 0 18px; font-size: var(--fs-md); }

/* Upload page */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s;
  cursor: default;
}
#drop-zone p { margin-bottom: 0.75rem; }
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(59,130,246,0.07);
}
#drop-zone label.btn { cursor: pointer; }

#progress { text-align: center; padding: 1.5rem; color: var(--text-muted); }

.error { color: var(--error); margin-top: 1rem; }
.success { color: var(--success); }

/* Edit page */
.edit-layout { display: flex; flex-direction: column; gap: 2rem; }

.ratio-tabs {
  display: flex;
  gap: 0.5rem;
}
.tab {
  padding: 0.5rem 1.2rem;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); border-color: #555; }
.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.crop-area { display: flex; flex-direction: column; gap: 1rem; }

.img-wrap {
  width: 100%;
  max-height: 60vh;
  background: var(--surface2);
  border-radius: var(--radius);
  overflow: hidden;
}
.img-wrap img { display: block; max-width: 100%; }

.crop-actions { display: flex; align-items: center; gap: 1rem; }

/* Unified toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  min-height: 2.4rem;
}
.toolbar-sep {
  flex: 1;
}

/* Straighten toolbar specifics */
.straighten-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.rotate-angle {
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 4rem;
}

/* Straighten drag mode */
.img-wrap { position: relative; }

#straighten-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 200;
  cursor: ew-resize;
}
#straighten-overlay.active { display: block; }

.img-wrap.straighten-mode {
  outline: 2px solid var(--accent);
  border-radius: var(--radius);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-ghost[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* Outline secondary — same shape as primary but neutral */
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* Destructive */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

/* Icon-only square */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}
.btn-icon.btn-sm { width: 28px; height: 28px; }

/* Dark preview button */
.btn-dark-preview {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  user-select: none;
}
.btn-dark-preview:hover { background: #2e2e2e; color: var(--text); }
.btn-dark-preview.active {
  background: #000;
  color: #fff;
  border-color: #000;
}
.dark-icon { font-size: 0.7em; }

/* Smooth opacity transition on the Cropper overlay */
.cropper-modal {
  transition: opacity 0.15s ease !important;
}

/* Previews */
.previews-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.previews-header h2 { margin-bottom: 0; }


.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.preview-thumb {
  width: 100%;
  border-radius: 4px;
  display: block;
}
.preview-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.no-crop { font-size: 0.85rem; color: var(--text-muted); }

/* Karuselli sub-previews inside one card */
.carousel-sub {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.carousel-sub:first-of-type { border-top: none; padding-top: 0; }

/* Airtable sync page */
.at-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.at-header h1 { margin-bottom: 0; }
.text-muted { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

.at-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.at-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.at-thumb {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}
.at-info {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.at-name {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.at-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* Gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.gallery-thumb {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}
.gallery-info {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.gallery-filename {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-dims { font-size: 0.8rem; color: var(--text-muted); }

/* Kuvapankki table view */
.bank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.bank-header h1 { margin-bottom: 0; }
.bank-actions { display: flex; gap: 0.5rem; }

.bank-filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-input, .select-input,
input[type="text"]:not(.tag-picker-input):not(.cropper-input),
input[type="number"]:not(.cropper-input),
input[type="email"], input[type="tel"], input[type="search"],
input[type="url"], input[type="password"],
textarea, select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea {
  height: auto;
  min-height: 64px;
  padding: 8px 10px;
  line-height: 1.45;
  resize: vertical;
}
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.search-input { flex: 1; min-width: 220px; max-width: 420px; }
.search-input:focus, .select-input:focus,
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* Checkbox / radio — Airtable-tyylinen */
input[type="checkbox"], input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  flex-shrink: 0;
  vertical-align: middle;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked, input[type="radio"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: '';
  width: 9px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
}
input[type="radio"]:checked::after {
  content: '';
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  overflow-y: visible;
  width: 100%;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}
.asset-table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
  color: var(--text);
}
.asset-table thead th {
  background: var(--surface-2);
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  position: sticky; top: 0;
  z-index: 3;
}
.asset-table thead th:last-child { border-right: 0; }
.asset-table tbody tr {
  transition: background 0.1s;
}
.asset-table tbody td {
  border-bottom: 1px solid var(--border);
}
.asset-table tbody tr:last-child td { border-bottom: 0; }
.asset-table tbody tr:hover td { background: var(--surface-2); }
.asset-table td {
  padding: 0.4rem 0.45rem;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}

/* "ID" column auto-sizes to fit its longest cell content (asset name) — never
   ellipsified, never shrunk below the rendered text. The resizer JS enforces a
   matching dynamic floor. */
.asset-table th[data-col="name"],
.asset-table td[data-col="name"] {
  width: 1%;
  min-width: 88px; /* fits 8 ID characters + padding */
  white-space: nowrap;
  max-width: none;
  overflow: visible;
}
.asset-table td[data-col="name"] { text-overflow: clip; }

/* "Kokoelma" column is the flexible filler — soaks up any leftover horizontal
   space so the table never ends with empty trailing whitespace on wide screens.
   Kept narrow on small screens by min-width. */
.asset-table th[data-col="collection"],
.asset-table td[data-col="collection"] {
  width: auto;
  min-width: 80px;
}
.asset-table thead th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.asset-table th {
  position: relative;
}
.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
}
.col-resizer:hover,
.col-resizer.dragging {
  background: var(--accent);
  opacity: 0.5;
}
/* Drag-to-reorder columns by grabbing the header. */
.asset-table thead th[draggable="true"] { cursor: grab; }
.asset-table thead th.col-dragging { opacity: 0.5; cursor: grabbing; }
.asset-table thead th.col-drop-before { box-shadow: inset 2px 0 0 0 var(--accent); }
.asset-table thead th.col-drop-after  { box-shadow: inset -2px 0 0 0 var(--accent); }
.asset-table td.thumb-cell,
.asset-table td.orientation-cell,
.asset-table td.select-col {
  max-width: none;
}
.row-thumb {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  background: var(--surface2);
}
.asset-table td.editable { padding: 0.25rem 0.3rem; }
.asset-table td.editable input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
}
/* ID column: input sizes to its content via the `size` attribute so the
   value never gets clipped. Cell still respects column min-width. */
.asset-table td[data-col="name"].editable input {
  width: auto;
  min-width: 100%;
}
.asset-table td.editable input:hover { border-color: var(--border); }
.asset-table td.editable input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
/* Permissions cell + popover */
.asset-table td.permissions-cell { vertical-align: top; padding: 0.25rem 0.3rem; }
.permissions-summary {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: pre-wrap;
  line-height: 1.3;
}
.permissions-summary:hover { border-color: var(--border); background: rgba(255,255,255,0.03); }
.permissions-summary.is-empty { color: var(--text-muted); }
.permissions-summary .perms-pill {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 4px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(99, 179, 237, 0.18);
  color: #8ec5ff;
  border: 1px solid rgba(99, 179, 237, 0.35);
  vertical-align: 2px;
}
.permissions-summary .perms-text { display: inline; }
/* Permission attachments column */
.asset-table td.permissions-att-cell { vertical-align: top; padding: 0.4rem 0.5rem; font-size: 0.85rem; }
.perms-att-list { display: flex; flex-direction: column; gap: 2px; }
.perms-att-link {
  color: var(--text);
  text-decoration: underline;
  word-break: break-all;
}
.perms-att-link:hover { color: var(--accent); }
/* Import dialog: permission attachments block */
.imp-perms-attach { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.35rem; }
.imp-perms-attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.imp-perms-attach-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
}
.imp-perms-attach-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.imp-perms-attach-meta { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.imp-perms-attach-desc {
  flex: 1; min-width: 80px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
  font: inherit;
  font-size: 0.78rem;
}
/* Permissions popover: attachments section */
.permissions-att-head { font-size: 0.8rem; margin-top: 0.6rem; color: var(--text-muted); }
.permissions-att-rows { display: flex; flex-direction: column; gap: 4px; margin: 4px 0; }
.permissions-att-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 4px;
}
.permissions-att-row a { flex: 0 1 auto; min-width: 0; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.permissions-att-row .perms-att-desc { flex: 1; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Table cell: attachment item layout */
.perms-att-item { display: flex; gap: 4px; align-items: baseline; }
.perms-att-item .perms-att-desc { color: var(--text-muted); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.permissions-popover {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  width: 340px;
  max-width: calc(100vw - 16px);
  box-shadow: var(--shadow-popover);
  font-size: 0.9rem;
}
.permissions-popover h5 {
  margin: 0 0 0.5rem 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}
.permissions-popover .permissions-rows { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.4rem; }
.permissions-popover .permissions-row { display: grid; grid-template-columns: auto 1fr auto; gap: 0.4rem; align-items: center; }
.permissions-popover .permissions-row input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem;
  font-family: inherit;
  font-size: 0.85rem;
}
.permissions-popover .permissions-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.permissions-popover .permissions-free { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.5rem; }
.permissions-popover .permissions-free textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 90px;
}
.permissions-popover .permissions-free textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.permissions-popover .permissions-actions {
  display: flex; gap: 0.4rem;
  justify-content: flex-end;
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

/* Import dialog: permissions cell — sized like a regular grid cell (Tagit). */
.imp-perms-body { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.3rem 0 0 0; }
.imp-perms-body[hidden] { display: none; }
.imp-perms-rows { display: flex; flex-direction: column; gap: 0.3rem; }
.imp-perms-row { display: grid; grid-template-columns: auto 1fr auto; gap: 0.4rem; align-items: center; }
.imp-perms-row input[type="text"] { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: 0.3rem 0.5rem; font-size: 0.9rem; }
.imp-perms-actions { display: flex; gap: 0.4rem; }
.imp-perms-free { display: flex; flex-direction: column; gap: 0.25rem; }
.imp-perms-free textarea { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: 0.4rem 0.5rem; font-size: 0.9rem; resize: vertical; }

.asset-table td.longtext-cell {
  vertical-align: middle;
  position: relative;
}
.asset-table td.longtext-cell .longtext-display {
  display: block;
  width: 100%;
  padding: 0.35rem 1.6rem 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.35;
  min-height: 28px;
  cursor: text;
  /* Single-line truncation when not active */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}
.asset-table td.longtext-cell .longtext-display.is-empty { color: var(--text-muted, #888); }
.asset-table td.longtext-cell .longtext-display:hover { border-color: var(--border); }
.asset-table td.longtext-cell .longtext-display:focus { border-color: var(--accent); }
.asset-table td.longtext-cell .longtext-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.35rem 1.6rem 0.35rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  line-height: 1.35;
  min-height: 28px;
  white-space: pre-wrap;
  outline: none;
}
.asset-table td.longtext-cell .longtext-expand {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  background: rgba(0,0,0,0.25);
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted, #aaa);
  cursor: pointer;
  font-size: 0.85rem;
  display: none;
  align-items: center;
  justify-content: center;
}
.asset-table td.longtext-cell:hover .longtext-expand,
.asset-table td.longtext-cell:focus-within .longtext-expand {
  display: inline-flex;
}
.asset-table td.longtext-cell .longtext-expand:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

/* Long-text popup editor */
.longtext-popup-back {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 10050;
  display: flex; align-items: center; justify-content: center;
}
.longtext-popup-card {
  background: #1f1f23;
  color: #eee;
  width: min(720px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.longtext-popup-title { font-size: 1rem; font-weight: 600; }
.longtext-popup-textarea {
  flex: 1;
  min-height: 240px;
  background: #14141a;
  border: 1px solid #3a3a42;
  border-radius: 4px;
  color: #eee;
  padding: 0.6rem 0.8rem;
  font: inherit;
  line-height: 1.4;
  resize: vertical;
}
.longtext-popup-textarea:focus { outline: none; border-color: var(--accent, #3b82f6); }
.longtext-popup-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.status-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
}
.row-actions {
  position: sticky; right: 0;
  background: var(--surface);
  text-align: center;
  padding: 0.2rem 0.3rem !important;
  box-shadow: -2px 0 4px rgba(0,0,0,0.25);
  z-index: 2;
}
.asset-table thead th.row-actions-col {
  position: sticky; right: 0;
  background: var(--surface2, #2a2a2e);
  z-index: 3;
}
.row-del-btn {
  background: transparent; border: 0; color: var(--text-muted);
  cursor: pointer; font-size: 0.95rem; line-height: 1;
  width: 24px; height: 24px; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.55; transition: opacity 0.1s, background 0.1s, color 0.1s;
}
.row-del-btn:hover { opacity: 1; background: #5a1f1f; color: #ffb3b3; }
nav a.active-nav { color: var(--text); }

/* Per-crop rating cells */
.crop-ratings {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 0.4rem;
  min-width: 420px;
}
.rating-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.rating-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.save-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.rating-cell.is-saved .save-dot { background: var(--success); }
.rating-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.78rem;
  width: 100%;
  cursor: pointer;
}
/* Rating value colors — mirror Airtable palette */
.rating-select.rating-avainkuva { background: rgba(59,130,246,0.25);  color: #93c5fd; border-color: rgba(59,130,246,0.4); }
.rating-select.rating-valittu   { background: rgba(6,182,212,0.22);   color: #67e8f9; border-color: rgba(6,182,212,0.4); }
.rating-select.rating-arkisto   { background: rgba(34,197,94,0.18);   color: #86efac; border-color: rgba(34,197,94,0.35); }
.rating-select.rating-none      { background: var(--surface2); color: var(--text-muted); }

.crop-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}
.badge-done { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-missing { background: var(--surface2); color: var(--text-muted); }

/* Table thumbnail cells */
.asset-table td.thumb-cell {
  padding: 0.4rem 0.5rem;
  text-align: center;
  vertical-align: middle;
}
.crop-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface2);
}
.crop-thumb-16x9 { aspect-ratio: 16/9; width: 80px; }
.crop-thumb-4x5  { aspect-ratio: 4/5;  width: 48px; }
.crop-thumb-9x16 { aspect-ratio: 9/16; width: 40px; }
.carousel-pair {
  display: flex;
  gap: 3px;
  justify-content: center;
}
.crop-thumb-half {
  width: 48px;
  aspect-ratio: 4/5;
  object-fit: cover;
  border-radius: 3px;
  background: var(--surface2);
  display: block;
}
.crop-thumb-empty {
  color: var(--text-muted);
  font-size: 1rem;
  text-align: center;
  opacity: 0.5;
}
.readonly-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.filename-cell {
  max-width: 220px;
}
.filename-cell .readonly-text {
  max-width: 220px;
}

/* Collection multi-select cell */
.collection-cell { padding: 0.35rem 0.6rem; min-width: 160px; }
.collection-trigger {
  width: 100%;
  min-height: 2rem;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.25rem 1.4rem 0.25rem 0.4rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 4px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.collection-trigger:hover { border-color: var(--border); background: var(--surface2); }
.collection-trigger .caret {
  position: absolute;
  right: 0.4rem;
  top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.7rem;
}
.chip {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
  background: rgba(59,130,246,0.18);
  color: #93c5fd;
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 999px;
  line-height: 1.2;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collection-trigger .chip,
.collection-cell .chip,
td[data-col="collection"] .chip {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collection-trigger,
.collection-cell {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
td[data-col="collection"] {
  max-width: 0; /* let the column width control the cell, not content */
}
.chip-placeholder { color: var(--text-muted); font-size: 0.85rem; }

.collection-popover {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 0.5rem;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.collection-list {
  overflow-y: auto;
  max-height: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.collection-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.88rem;
}
.collection-option:hover { background: var(--surface2); }
.collection-option input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.collection-option-label {
  display: flex; flex: 1; align-items: center; gap: 0.5rem;
  cursor: pointer; min-width: 0;
}
.collection-option-del,
.collection-option-add {
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: 3px;
  padding: 0 0.45rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
}
.collection-option:hover .collection-option-del,
.collection-option:hover .collection-option-add { visibility: visible; }
.collection-option-del:hover { background: #3a1f1f; color: #f87171; }
.collection-option-add:hover { background: #1f2f3a; color: #60a5fa; }
.collection-empty {
  padding: 0.6rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}
.collection-add-row {
  display: flex;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}
.collection-search {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
}
.collection-search:focus { outline: none; border-color: var(--accent); }
.collection-add-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Selection column + bulk actions */
.asset-table th.select-col,
.asset-table td.select-col {
  width: 36px;
  padding: 0.4rem 0.5rem;
  text-align: center;
}
.asset-table td.select-col input[type="checkbox"],
.asset-table th.select-col input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 16px;
  height: 16px;
}
.asset-table tr.row-selected > td { background: var(--accent-soft); }
.asset-table tr.row-selected:hover > td { background: var(--accent-soft-hover); }

/* Preview-mode arrow-key navigation indicator */
.asset-table tr.preview-nav-row > td {
  box-shadow: inset 0 1px 0 #f59e0b, inset 0 -1px 0 #f59e0b;
  background: rgba(245, 158, 11, 0.07);
}
.asset-table tr.preview-nav-row > td:first-child {
  box-shadow: inset 1px 1px 0 #f59e0b, inset 0 -1px 0 #f59e0b;
}
.asset-table tr.preview-nav-row > td:last-child {
  box-shadow: inset -1px 1px 0 #f59e0b, inset 0 -1px 0 #f59e0b;
}
.asset-table td.preview-nav-cell {
  outline: 2px solid #f59e0b;
  outline-offset: -2px;
  background: rgba(245, 158, 11, 0.18) !important;
}

/* Table-view active row + cell (number-key shortcut target) */
.asset-table tr.table-active-row > td {
  box-shadow: inset 0 1px 0 #3b82f6, inset 0 -1px 0 #3b82f6;
  background: rgba(59, 130, 246, 0.06);
}
.asset-table tr.table-active-row > td:first-child {
  box-shadow: inset 1px 1px 0 #3b82f6, inset 0 -1px 0 #3b82f6;
}
.asset-table tr.table-active-row > td:last-child {
  box-shadow: inset -1px 1px 0 #3b82f6, inset 0 -1px 0 #3b82f6;
}
.asset-table td.table-active-cell {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
  background: rgba(59, 130, 246, 0.18) !important;
}
.tbl-shortcut-col-label { display: inline-flex; align-items: center; gap: 0.3rem; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.75rem;
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: var(--radius);
}
.bulk-bar[hidden] { display: none; }
.bulk-count {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9rem;
}
.bulk-sep { flex: 1; }

/* Clickable thumbnails */
.clickable-thumb { cursor: pointer; transition: transform 0.1s ease, outline-color 0.15s; }
.clickable-thumb:hover { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Lightbox */
.lightbox[hidden] { display: none !important; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.lightbox-stage {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-image {
  max-width: 90vw;
  max-height: 85vh;
  display: block;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.lb-pair {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  max-width: 95vw;
  max-height: 85vh;
}
.lb-image-half {
  max-width: 46vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.lightbox-topbar[hidden] { display: none !important; }
.lightbox-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.85), rgba(0,0,0,0.55));
  z-index: 12;
}
.lightbox-topbar .lightbox-caption {
  color: #eee;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
  position: static;
  transform: none;
  background: none;
  padding: 0;
  pointer-events: auto;
}
.lightbox-topbar-actions { display: flex; gap: 0.5rem; margin-left: auto; margin-right: 3.5rem; align-items: center; }

/* Lightbox lives over a dark backdrop, so its toolbar buttons need a
   light-on-dark variant of the ghost button instead of the default
   light-theme one. */
.lightbox-topbar .btn,
.lightbox-topbar .btn-ghost,
.lightbox-topbar-actions .btn,
.lightbox-topbar-actions .btn-ghost {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
}
.lightbox-topbar .btn:hover,
.lightbox-topbar .btn-ghost:hover,
.lightbox-topbar-actions .btn:hover,
.lightbox-topbar-actions .btn-ghost:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.32);
  color: #fff;
}
.lightbox-topbar .btn[aria-pressed="true"],
.lightbox-topbar-actions .btn[aria-pressed="true"],
.lightbox-topbar #lb-layout-toggle.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.lightbox-topbar .select-input,
.lightbox-topbar-actions .select-input,
.lightbox-topbar input[type="text"],
.lightbox-topbar input[type="number"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
}
.lightbox-topbar .select-input option { color: var(--text); background: var(--surface); }
.lightbox-topbar .lb-shortcut-cat-label,
.lightbox-topbar .lb-apply-all-toggle {
  color: rgba(255,255,255,0.85);
  font-size: 0.85rem;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.lightbox-topbar .lb-apply-all-toggle input[type="checkbox"] { accent-color: var(--accent); }
.lightbox-topbar .lightbox-close {
  position: static;
  margin-left: auto;
  flex-shrink: 0;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
}
.lightbox-btn {
  position: absolute;
  background: rgba(255,255,255,0.10);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
  user-select: none;
  backdrop-filter: blur(8px);
}
.lightbox-btn:hover { background: rgba(255,255,255,0.22); border-color: rgba(255,255,255,0.32); transform: scale(1.05); }
.lightbox-btn:active { transform: scale(0.97); }
.lb-empty {
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 3rem;
  font-style: italic;
}
.lightbox-close { top: 1rem; right: 1rem; font-size: 1.6rem; }

/* Inline crop editor in lightbox */
.lightbox-edit[hidden] { display: none !important; }
.lightbox-edit {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.95);
  z-index: 10;
  /* Tiukka padding: vain sen verran että topbar (yläpuolella, ~3.5rem) ja
     reunat eivät leikkaa croppia. */
  padding: 3.5rem 0.25rem 0.25rem;
}
.lb-edit-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Pieni puskuri, jotta cropperin sininen rajaviiva (~2px) ei leikkaudu
     reunoista topbarin / toolbarin alle. */
  padding: 4px 0;
}
.lb-edit-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}
.lb-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.5rem 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 0.4rem;
}
.lb-edit-label { color: #ddd; font-size: 0.9rem; }
.lb-edit-spacer { flex: 1; }
.lightbox-prev  { left: 1rem;  top: 50%; transform: translateY(-50%); font-size: 2rem; }
.lightbox-next  { right: 1rem; top: 50%; transform: translateY(-50%); font-size: 2rem; }

/* Drag & drop overlay */
.drop-overlay[hidden] { display: none !important; }
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(59,130,246,0.15);
  backdrop-filter: blur(2px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border: 3px dashed var(--accent);
}
.drop-overlay-inner {
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 1.5rem 2.5rem;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

/* Sortable headers */
/* Header-click sort disabled — use the separate "Järjestä" button instead. */
th.sortable { user-select: none; }
th.sortable .sort-ind { display: none; }
th.sort-active { color: var(--accent); }

/* Cell drag-select */
td.cell-selectable { position: relative; }
td.cell-selected {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: rgba(59,130,246,0.08);
}
#fill-handle {
  position: fixed;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 1.5px solid #fff;
  border-radius: 2px;
  cursor: crosshair;
  z-index: 50;
  display: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
#fill-handle:hover { transform: scale(1.15); }

/* Rating widget (active scale, replaces default select on rating columns) */
.rating-widget { display: inline-block; }
.rating-widget.rating-inherited .rating-select { font-style: italic; opacity: 0.85; }
.rating-widget.rating-inherited.star-rating { opacity: 0.7; }
.star-rating { display: inline-flex; gap: 1px; cursor: pointer; user-select: none; }

/* =====================================================================
   Tag widget — Airtable-tyylinen pyöreä chip, soft fill
   ===================================================================== */
.tags-widget {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  min-height: 22px;
}
.tags-widget.tags-inherited { opacity: 0.65; font-style: italic; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag-chip.tag-stars         { background: var(--tag-star);   color: var(--tag-star-fg); }
.tag-chip.tag-status-avainkuva { background: var(--tag-key);  color: var(--tag-key-fg); }
.tag-chip.tag-status-valittu   { background: var(--tag-pick); color: var(--tag-pick-fg); }
.tag-chip.tag-status-arkisto   { background: var(--tag-arc);  color: var(--tag-arc-fg); }
.tag-chip.tag-status-eikäytössä,
.tag-chip.tag-status-eikaytossa { background: var(--tag-out); color: var(--tag-out-fg); }
.tag-chip.tag-custom        { background: var(--tag-custom); color: var(--tag-custom-fg); }
.tag-chip .tag-x {
  background: transparent; border: 0; color: inherit;
  cursor: pointer; padding: 0 0 0 2px; font-size: 0.95rem; line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
}
.tag-chip:hover .tag-x { opacity: 0.7; }
.tag-chip .tag-x:hover { opacity: 1; }
.tag-add {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  background: transparent; border: 1px dashed var(--border-strong); border-radius: 50%;
  color: var(--text-muted); cursor: pointer; font-size: 0.85rem; line-height: 1; padding: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.tag-add:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); border-style: solid; }

/* Tag picker popover */
.tag-picker {
  position: absolute; z-index: 10010;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 8px; min-width: 240px; max-width: 340px;
  box-shadow: var(--shadow-popover);
  color: var(--text);
}
.tag-picker-section { margin-bottom: 8px; }
.tag-picker-section:last-child { margin-bottom: 0; }
.tag-picker-label {
  font-size: 10px; text-transform: uppercase; color: var(--text-subtle);
  margin-bottom: 4px; letter-spacing: 0.06em; font-weight: 600;
}
.tag-picker-row { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-picker-tag {
  background: var(--surface-2); color: var(--text); border: 1px solid transparent;
  padding: 3px 10px; border-radius: var(--radius-pill); cursor: pointer;
  font-size: var(--fs-xs); font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.lb-layout-icon { display: inline-block; transform: rotate(90deg); }
.lb-apply-all-toggle {
  display: inline-flex; align-items: center; gap: 0.3rem;
  margin-left: 0.5rem;
  font-size: 0.78rem; color: var(--text-muted);
  cursor: pointer; user-select: none;
}
.lb-apply-all-toggle input { margin: 0; }
/* Cropper.js: kill the default white viewbox outline so the crop window
   shows the original pixels with no overlay tint or border. */
.cropper-view-box { outline: 0 !important; box-shadow: none !important; }
.cropper-face { background-color: transparent !important; opacity: 0 !important; }
.tag-picker-tag:hover:not(:disabled) { background: var(--surface-3); }
.tag-picker-tag:disabled { opacity: 0.45; cursor: default; }
.tag-picker-tag.used {
  background: var(--danger-soft); color: var(--danger); cursor: pointer;
  position: relative;
}
.tag-picker-tag.used::after {
  content: '×'; margin-left: 4px; font-weight: 700; opacity: 0.9;
}
.tag-picker-tag.used:hover { background: rgba(239,68,68,0.2); }
.tag-picker-input {
  width: 100%; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 4px 8px; border-radius: var(--radius-sm); font-size: var(--fs-xs);
  height: 28px;
}
.tag-picker-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.star-rating .star { color: #555; font-size: 1.1rem; line-height: 1; padding: 0 1px; transition: color 0.1s; }
.star-rating .star.on { color: #f5b301; }
.star-rating .star:hover { color: #ffd34d; }

/* Modal overlay (used by rating-categories dialog) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.40);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.5rem; min-width: 440px; max-width: 90vw; max-height: 85vh; overflow: auto;
  box-shadow: var(--shadow-lg);
}

/* Inline editor autosave hint */
.lb-edit-autosave { font-size: 0.85rem; color: #bbb; }

/* Filter panel (Airtable-style) */
.filter-badge {
  display: inline-block;
  min-width: 1.2em;
  padding: 0 0.35em;
  margin-left: 0.25em;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  text-align: center;
  line-height: 1.4;
}
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border, #333);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.filter-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.filter-panel-title { font-weight: 600; color: var(--text); }
.filter-rows { display: flex; flex-direction: column; gap: 0.4rem; }
.filter-empty { font-size: 0.9rem; padding: 0.25rem 0; }
.filter-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.filter-prefix {
  min-width: 2.2rem;
  color: var(--text-muted, #aaa);
  font-size: 0.85rem;
  text-align: right;
}
.filter-field, .filter-op { min-width: 10rem; }
.filter-val { min-width: 10rem; flex: 0 1 auto; }
.filter-val-spacer { min-width: 10rem; }
.filter-remove { line-height: 1; padding: 0.15rem 0.5rem; }
.filter-panel-actions { margin-top: 0.6rem; }

/* Popover variant: anchored under its toggle button (positioned via JS). */
.filter-panel-pop {
  z-index: 1300;
  min-width: 360px;
  max-width: 90vw;
  max-height: 60vh;
  overflow: auto;
  margin-bottom: 0;
}
.filter-panel-close {
  appearance: none;
  background: transparent;
  border: 0;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 0.25rem;
}
.filter-panel-close:hover { background: var(--surface-2); color: var(--text); }

/* Global "Tallennetaan taustalla…" banner pinned to the bottom-right so the
   user sees in-flight saves even after closing the lightbox. */
.global-save-banner {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-popover);
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  display: inline-flex; align-items: center; gap: 0.5rem;
}
.global-save-banner::before {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
.global-save-banner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Import-dialog photographer combobox: input + caret toggle + custom dropdown
   menu (existing list + inline "+ Lisää uusi kuvaaja" form). */
.imp-ph-combo { position: relative; }
.imp-ph-combo input#imp-photographer { padding-right: 1.85rem; }
.imp-ph-combo-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}
.imp-ph-combo-toggle:hover { background: var(--surface-2); color: var(--text); }
.imp-ph-combo-menu {
  position: absolute;
  left: 0; right: 0; top: calc(100% + 4px);
  z-index: 1400;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-popover);
  padding: 4px;
  max-height: 280px;
  overflow: auto;
  display: flex; flex-direction: column;
}
.imp-ph-combo-menu[hidden] { display: none; }
.imp-ph-combo-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.imp-ph-combo-item:hover { background: var(--surface-2); }
.imp-ph-combo-name { font-weight: 500; }
.imp-ph-combo-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; }
.imp-ph-combo-empty { padding: 0.5rem 0.6rem; font-size: 0.85rem; color: var(--text-muted); }
.imp-ph-combo-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.imp-ph-combo-add {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  margin-top: 2px;
}
.imp-ph-combo-add:hover { background: var(--accent); color: #fff; }

/* Inline "Uusi kuvaaja" form rendered into the same dropdown. */
.imp-ph-combo-form { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.4rem; }
.imp-ph-combo-form-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.imp-ph-combo-field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.imp-ph-combo-field-label { color: var(--text-muted); }
.imp-ph-combo-field-label .req { color: var(--danger, #dc2626); }
.imp-ph-combo-field input {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.imp-ph-combo-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.imp-ph-combo-field.has-error input { border-color: var(--danger, #dc2626); }
.imp-ph-combo-field-error {
  font-size: 0.75rem;
  color: var(--danger, #dc2626);
  min-height: 0;
}
.imp-ph-combo-field-error:empty { display: none; }
.imp-ph-combo-form-status { font-size: 0.78rem; color: var(--text-muted); min-height: 1em; }
.imp-ph-combo-form-actions { display: flex; justify-content: flex-end; gap: 0.4rem; }

/* Aloitusnumero rendered inline in the pills row. */
.imp-pill-startnum {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.18rem 0.55rem 0.18rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.imp-pill-startnum .imp-pill-startnum-label .req { color: var(--danger, #dc2626); margin-left: 1px; }
.imp-pill-startnum input {
  width: 56px;
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  text-align: right;
}
.imp-pill-startnum input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* Auth / workspace pages */
.auth-shell {
  max-width: 480px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border, #333);
  border-radius: var(--radius);
}
.auth-shell-wide { max-width: 800px; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; margin: 1rem 0; }
.auth-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--text-muted, #aaa); }
.auth-form input { padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: var(--fs-md); }
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.auth-form button { margin-top: 0.5rem; }
.auth-error { color: var(--danger); min-height: 1.2em; font-size: var(--fs-sm); }
.ws-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.ws-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; margin-bottom: 2rem; }
.ws-card {
  display: flex; flex-direction: column; gap: 0.25rem;
  padding: 1rem; border: 1px solid var(--border, #333); border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-decoration: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.ws-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.ws-create h2 { font-size: 1rem; margin: 0 0 0.5rem 0; }
.ws-create-form { display: flex; gap: 0.5rem; }
.ws-create-form input { flex: 1; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
nav .nav-spacer { flex: 1; }

/* Others' ratings badges */
.others-ratings { display: inline-flex; gap: 0.15rem; margin-left: 0.4rem; vertical-align: middle; }
.others-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.3em; height: 1.3em; border-radius: 50%;
  font-size: 0.75rem; font-weight: 700; line-height: 1;
  background: #2a2a2a; color: #ddd;
  cursor: help;
}
.others-chip.rating-avainkuva { background: #f59e0b; color: #1a1a1a; }
.others-chip.rating-valittu   { background: #3b82f6; color: #fff; }
.others-chip.rating-arkisto   { background: #555; color: #ccc; }

/* Task 13: Inverted dim — default fully obscures outside crop, D reveals context */
.lightbox .cropper-modal {
  background-color: #000 !important;
  opacity: 1 !important;
  transition: opacity 0.12s ease;
}
.lightbox.show-context .cropper-modal {
  opacity: 0.5 !important;
}

/* Task 8: orientation cell */
.imp-preset-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
/* Merge the three stacked gray cards (pattern → pills → preset) into a single
   continuous panel: hide internal borders, remove shared margins, and keep
   only the outer corners rounded. */
.imp-pattern-label + .imp-pills,
.imp-pills + .imp-preset-row {
  margin-top: 0 !important;
  border-top: 0 !important;
}
.imp-pattern-label:has(+ .imp-pills) {
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
}
.imp-pills:has(+ .imp-preset-row) {
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 0;
}
.imp-pills + .imp-preset-row {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.imp-pattern-label + .imp-pills:not(:has(+ .imp-preset-row)) {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.imp-preset-row .lbl-row { font-weight: 600; }
.imp-preset-row .select-input { min-width: 200px; }

.imp-preset-dd { position: relative; }
.imp-preset-dd-btn {
  display: inline-flex; align-items: center; justify-content: space-between;
  gap: 0.6rem;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font: inherit;
  cursor: pointer;
}
.imp-preset-dd-btn:hover { border-color: var(--border-strong); }
.imp-preset-dd-current { color: var(--text); }
.imp-preset-dd-caret { color: var(--text-subtle); font-size: 0.75rem; }
.imp-preset-dd-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 280px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  z-index: 50;
  padding: 4px 0;
}
.imp-preset-menu-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: var(--fs-sm);
}
.imp-preset-menu-row:hover { background: var(--surface-2); }
.imp-preset-menu-row.is-selected { background: var(--accent-soft); color: var(--accent); }
.imp-preset-menu-label { flex: 1; }
.imp-preset-menu-x {
  background: transparent; border: 0;
  color: var(--text-muted); cursor: pointer;
  font-size: 1.05rem; line-height: 1;
  padding: 0 6px;
}
.imp-preset-menu-x:hover { color: var(--danger); }
.imp-preset-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.imp-preset-menu-save {
  color: var(--accent);
  font-weight: 500;
}
.imp-preset-menu-empty {
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
}

.collection-option-text { display: inline-flex; align-items: baseline; gap: 0.15rem; }
.collection-option-parent { color: var(--text-muted); font-size: 0.85em; }
.collection-option-leaf { color: var(--text); }

.orientation-cell { padding: 0.25rem 0.5rem; text-align: center; }
.orientation-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  line-height: 0;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.orientation-icon svg { display: block; }
.orientation-icon:hover {
  background: var(--surface2);
  border-color: var(--border);
}

/* Column resize: enforce a sensible minimum so cells never disappear */
.asset-table th { min-width: 70px; }
.asset-table th.select-col,
.asset-table th[data-col="orientation"],
.asset-table th[data-col="image"],
.asset-table th[data-col="thumb-16x9"],
.asset-table th[data-col="thumb-4x5"],
.asset-table th[data-col="thumb-9x16"],
.asset-table th[data-col="thumb-8x5"] { min-width: 44px; }

/* Upload progress overlay */
.upload-progress {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 2000;
  font-size: 0.85rem;
}
.upload-progress[hidden] { display: none; }
.upload-progress .up-label { font-weight: 600; margin-bottom: 0.5rem; }
.upload-progress .up-track {
  width: 100%;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.upload-progress .up-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s ease;
}
.upload-progress .up-meta {
  margin-top: 0.4rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.upload-progress.indeterminate .up-track {
  position: relative;
  overflow: hidden;
}
.upload-progress.indeterminate .up-fill {
  width: 35% !important;
  animation: up-indet 1.1s linear infinite;
}
@keyframes up-indet {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(285%); }
}

/* View mode toggle — Airtable-style segmented control with floating "thumb" */
.view-mode-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 2px;
  margin-right: 0.5rem;
  gap: 1px;
}
.vm-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 4px 12px;
  height: 28px;
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.vm-btn:hover { color: var(--text); }
.vm-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Gallery view */
.gallery-wrap[hidden], .folder-wrap[hidden], .table-wrap[hidden] { display: none; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  padding: 1rem;
}
.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow-sm);
}
.gallery-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.gallery-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), var(--shadow-md); }
.gallery-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}
.gallery-meta {
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
}
.gallery-id { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-filename { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Folder view */
.folder-wrap { padding: 0.5rem 0; }
.folder-node { margin-bottom: 1rem; }
.folder-node-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.folder-icon { font-size: 1.1rem; }
.folder-count { color: var(--text-muted); font-weight: normal; font-size: 0.85em; }
.folder-grid { padding: 0.5rem 0; }

/* Source rotation toolbar in lightbox (main column) */
.lb-source-bar {
  position: absolute;
  top: 4rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  background: rgba(0,0,0,0.65);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  backdrop-filter: blur(4px);
  z-index: 5;
  font-size: 0.85rem;
  color: var(--text);
}
.lb-source-bar[hidden] { display: none; }
.lb-source-bar input[type="range"] { width: 220px; }
.lb-source-bar input[type="number"] {
  width: 4.5rem;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
}
.lb-source-label { font-weight: 600; }
.lb-source-hint { font-size: 0.78rem; }

/* Existing-path picker in import dialog */
.imp-coll-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}
.imp-coll-existing {
  flex: 1;
  min-width: 200px;
  font-size: 0.85rem;
}
.orientation-select {
  width: 100%;
  background: transparent;
  color: inherit;
  border: 1px solid transparent;
  padding: 0.25rem 0.4rem;
  font: inherit;
  border-radius: 4px;
}
.orientation-select:hover, .orientation-select:focus { border-color: #444; outline: none; }

/* Task 9: Import dialog */
.import-dialog {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.40);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 24px;
}
.import-dialog[hidden] { display: none; }
.import-dialog-card {
  background: var(--surface);
  color: var(--text);
  width: min(960px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
}
/* Header: stays at top */
.import-dialog-card h2 {
  margin: 0;
  padding: 18px 24px 4px;
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--text);
}
.import-dialog-card #import-count {
  margin: 0 24px 14px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}
/* Body: scrollable, holds the form sections */
.import-dialog-card > .import-grid,
.import-dialog-card > .imp-pattern-label,
.import-dialog-card > .imp-pills,
.import-dialog-card > .imp-preset-row,
.import-dialog-card > .import-preview-wrap,
.import-dialog-card > #imp-warn {
  margin-left: 24px;
  margin-right: 24px;
}
.import-dialog-card > .import-preview-wrap { margin-bottom: 16px; }
/* Make the section between header and footer scroll */
.import-dialog-card #imp-close-x { z-index: 5; top: 12px; right: 12px; }
.import-storage {
  font-size: var(--fs-xs);
  margin: 10px 24px 14px;
  padding: 8px 0 16px;
  line-height: 1.4;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
}
.import-storage-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
}
.import-storage-label {
  color: var(--text-subtle, var(--text-muted));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}
.import-storage-value {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.import-storage-pending {
  font-style: italic;
  opacity: 0.8;
}
.import-storage-warnline {
  flex-basis: 100%;
  color: var(--danger);
  font-weight: 500;
  margin-top: 2px;
}
.import-storage-warn .import-storage-value { color: var(--danger); }
.import-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  margin-top: 4px;
}
.import-grid label,
.import-grid .imp-grid-cell {
  display: flex; flex-direction: column; gap: 6px;
  font-size: var(--fs-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.import-grid label:focus-within,
.import-grid .imp-grid-cell:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.import-grid .lbl-row {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}
.import-grid .req { color: var(--danger); margin-left: 2px; }
/* Inputs inherit from generic .select-input rules + base input styles */
.imp-pattern-label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: var(--fs-sm);
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.imp-pattern-label .lbl-row {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}
.imp-pattern-rail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-height: 36px;
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--fs-sm);
}
.imp-chip {
  display: inline-flex; align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  cursor: grab;
  user-select: none;
  position: relative;
}
.imp-chip.dragging { opacity: 0.4; }
.imp-chip.drop-before { box-shadow: -3px 0 0 0 #3b82f6; }
.imp-chip.drop-after  { box-shadow:  3px 0 0 0 #3b82f6; }
.imp-chip-token {
  background: #2c3a52;
  color: #d6e4ff;
  border: 1px solid #3b5680;
}
.imp-chip-text {
  background: #2a2a30;
  color: #eee;
  border: 1px dashed #555;
}
.imp-chip-text-inner {
  outline: none;
  min-width: 0.4rem;
  white-space: pre;
  cursor: text;
}
.imp-chip-text-inner:focus { background: #1a1a20; }
.imp-chip-x {
  background: transparent;
  border: 0;
  color: #aab;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0 0 0.15rem;
  cursor: pointer;
}
.imp-chip-x:hover { color: #fff; }
.imp-rail-tail {
  flex: 1;
  min-width: 1.5rem;
  align-self: stretch;
}
.imp-rail-tail.drop-active { box-shadow: inset 3px 0 0 0 #3b82f6; }
.imp-pill-add {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  border: 1px dashed var(--border-strong) !important;
  cursor: pointer !important;
}
.imp-pill-add:hover {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
.imp-checkbox-row {
  display: flex; align-items: center; gap: 0.45rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: #ccc;
}
.imp-coll-stack { display: flex; flex-direction: column; gap: 0.4rem; }
.imp-coll-root-row { display: flex; align-items: center; gap: 0.5rem; }
.imp-coll-root-pill {
  display: inline-block;
  padding: 3px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.imp-coll-root-hint { font-size: 0.78rem; }
.imp-coll-list { display: flex; flex-direction: column; gap: 0.3rem; }
.imp-coll-item {
  display: flex; align-items: center; gap: 0.4rem;
  background: #2a2a30;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  position: relative;
}
.imp-coll-item.dragging { opacity: 0.4; }
.imp-coll-item.drop-before { box-shadow: 0 -3px 0 0 #3b82f6; }
.imp-coll-item.drop-after  { box-shadow: 0  3px 0 0 #3b82f6; }
.imp-coll-handle {
  cursor: grab;
  color: #888;
  user-select: none;
  padding: 0 0.2rem;
  letter-spacing: -2px;
  font-size: 0.9rem;
}
.imp-coll-handle:active { cursor: grabbing; }
.imp-coll-input {
  flex: 1;
  background: transparent;
  border: 0;
  color: #eee;
  padding: 0.3rem 0.4rem;
  font: inherit;
  outline: none;
}
.imp-coll-x {
  background: transparent; border: 0;
  color: #aab; cursor: pointer;
  font-size: 1rem; line-height: 1;
  padding: 0 0.3rem;
}
.imp-coll-x:hover { color: #fff; }
.imp-coll-add { align-self: flex-start; }
.imp-coll-tree {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
}
/* Force horizontal layout — `.import-grid label` (column flex) would otherwise
   stack the checkbox above the text and make rows look centred. */
label.imp-coll-tree-row {
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start;
  gap: 0.5rem;
  padding: 4px 8px;
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text);
  text-align: left;
}
label.imp-coll-tree-row:hover { background: var(--surface-2); }
label.imp-coll-tree-row input[type="checkbox"] { margin: 0; flex: 0 0 auto; }
.imp-coll-tree-label { display: inline-flex; align-items: baseline; gap: 0; text-align: left; }
.imp-coll-tree-crumb { color: var(--text-subtle); font-size: var(--fs-xs); }
.imp-coll-tree-leaf  { color: var(--text); }
.imp-coll-empty {
  padding: 8px 10px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: left;
}

/* Per-row "+" affordance — hidden by default, slides in on row hover so the
   row "makes room" for it. No always-visible empty slot in the tree. */
.imp-coll-tree-row-add {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  height: 1.4rem;
  width: 0;
  padding: 0;
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: #9aa;
  cursor: pointer;
  font: inherit; font-weight: 600; font-size: 1rem; line-height: 1;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition: width 0.16s ease, opacity 0.16s ease, background 0.12s ease, color 0.12s ease;
}
label.imp-coll-tree-row:hover .imp-coll-tree-row-add,
label.imp-coll-tree-row:focus-within .imp-coll-tree-row-add,
.imp-coll-tree-row-add:hover,
.imp-coll-tree-row-add:focus {
  width: 1.4rem;
  opacity: 1;
  pointer-events: auto;
}
.imp-coll-tree-row-add { color: var(--text-muted); }
.imp-coll-tree-row-add:hover { background: var(--accent-soft); color: var(--accent); }

/* Always-visible "+ Lisää uusi" row pinned to the top of the tree for
   root-level adding. Persistent, never hover-gated — root has no parent row
   to hover. */
.imp-coll-tree-root-add-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 5px 8px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  font: inherit;
  border-bottom: 1px dashed var(--border);
  transition: background 0.12s ease, color 0.12s ease;
}
.imp-coll-tree-root-add-row:hover { background: var(--accent-soft); color: var(--accent); }
.imp-coll-tree-root-add-row:focus { outline: none; background: var(--accent-soft); color: var(--accent); }
.imp-coll-tree-add-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1rem; height: 1rem; flex: 0 0 auto;
  font-weight: 600;
  color: inherit;
}
.imp-coll-tree-add-input-row {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 6px 8px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.imp-coll-tree-add-input-row .btn { padding: 4px 9px; }

/* Standalone search/filter row above the tree. Slim, left-aligned. */
.imp-coll-search-row {
  display: flex; gap: 0.4rem;
  align-items: center;
}
.req { color: var(--danger); margin-left: 2px; }
.lbl-row { display: inline-flex; align-items: center; gap: 0.2rem; }
.chip-path {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  color: var(--text-muted);
}
.imp-pills {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.imp-pills > small:first-child {
  flex: 1 0 100%;
  margin-bottom: 2px;
}
.imp-pill {
  display: inline-block;
  padding: 3px 10px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--fs-xs);
  cursor: grab;
  user-select: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.imp-pill:hover { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.imp-pill:active { cursor: grabbing; }
.import-preview-wrap { margin-top: 16px; }
.import-preview-wrap h3 {
  margin: 0 0 6px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}
.import-preview {
  max-height: 240px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--fs-xs);
}
.import-preview-row { padding: 2px 0; border-bottom: 1px dotted var(--border); }
.import-preview-row:last-child { border-bottom: none; }
.ip-orig { color: var(--text-subtle); }
.ip-id   { color: var(--warn); font-weight: 500; }
.ip-name { color: var(--text); }
.import-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 24px;
  margin-top: auto;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}

/* Task 10: Straighten controls */
.lb-edit-rotate {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: #ccc;
  margin-left: 1rem;
}
.lb-edit-rotate input[type="range"] { width: 160px; }
.lb-edit-rotate input[type="number"] {
  width: 56px;
  background: #2a2a30; color: #eee;
  border: 1px solid #444; border-radius: 4px;
  padding: 0.15rem 0.3rem;
  font: inherit;
}

/* Task 4/5: bulk bar size selector */
.bulk-size-label {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: #ccc; font-size: 0.85rem;
}
.bulk-size-label select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 2px 6px; font: inherit;
}

/* =====================================================================
   View tabs (Airtable-tyyliset alleviivatut tabit)
   ===================================================================== */
.view-tabs-bar,
.workspace-bar {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 6px 0.85rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--surface);
  min-height: 36px;
}
.view-add-btn { font-size: 16px; line-height: 1; color: var(--text-muted); }
.view-add-btn:hover { color: var(--text); }

/* Workspace overflow (kebab) menu */
.ws-overflow { position: relative; }
.ws-overflow-menu[hidden] { display: none !important; }
.ws-overflow-menu {
  position: absolute;
  right: 0; top: calc(100% + 4px);
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: 4px;
  z-index: 1200;
  display: flex; flex-direction: column;
}
.ws-overflow-item {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 7px 10px;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.ws-overflow-item:hover { background: var(--surface-2); }
.ws-overflow-item .ws-ic { width: 16px; text-align: center; opacity: 0.85; }
.ws-overflow-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

/* View toolbar (lower row, Airtable-style) */
.view-toolbar {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 6px 0.85rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  min-height: 44px;
}

/* View-specific filter/sort/show-others row that sits between the
   workspace-bar (view tabs) and the view-toolbar (mode segments). */
.view-filter-bar {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 6px 0.85rem;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.view-toolbar .vt-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 4px 4px;
}
.view-toolbar .vt-spacer { flex: 1; }
.view-toolbar .vt-ic {
  font-size: 13px;
  line-height: 1;
  opacity: 0.7;
  margin-right: 1px;
}
.view-toolbar .vt-label { font-size: var(--fs-sm); color: var(--text-muted); }
.view-toolbar .density-label {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0 6px;
}
.view-toolbar .density-label select.select-input {
  height: 28px;
  font-size: var(--fs-sm);
  padding: 2px 22px 2px 8px;
}
.view-toolbar #row-density-custom { width: 64px; height: 28px; font-size: var(--fs-sm); }

/* Shortcut pill: "1–9 → [select]   ☐ Kaikkiin croppeihin" */
.vt-shortcut {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 3px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  height: 30px;
}
.vt-shortcut-keys {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 1;
}
.vt-shortcut-arrow { color: var(--text-subtle); font-size: 12px; }
.vt-shortcut-select.select-input {
  height: 24px;
  font-size: var(--fs-sm);
  padding: 0 22px 0 8px;
  background-color: var(--surface);
  border-color: var(--border);
}
.vt-applyall {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding-left: 8px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.vt-applyall input[type="checkbox"] { margin: 0; }
.view-tabs { display: flex; gap: 2px; flex-wrap: wrap; align-items: stretch; }
.view-tab {
  display: inline-flex;
  align-items: stretch;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: 0;
  overflow: hidden;
  position: relative;
  transition: color 0.12s, background 0.12s;
}
.view-tab:hover { color: var(--text); background: var(--surface-2); }
.view-tab-label {
  background: transparent;
  color: inherit;
  border: 0;
  padding: 6px 12px;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
}
.view-tab-x {
  background: transparent;
  color: var(--text-subtle);
  border: 0;
  padding: 0 6px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.view-tab:hover .view-tab-x, .view-tab.active .view-tab-x { opacity: 0.7; }
.view-tab-x:hover { background: var(--danger-soft); color: var(--danger); opacity: 1 !important; }
.view-tab.active {
  background: transparent;
  color: var(--text);
  font-weight: 600;
}
.view-tab.active::after {
  content: '';
  position: absolute;
  left: 4px; right: 4px; bottom: -7px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.view-spacer { flex: 1; }

.lb-export-menu {
  position: fixed;
  z-index: 1100;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  min-width: 240px;
  box-shadow: var(--shadow-popover);
  font-size: var(--fs-sm);
}
.lb-export-menu h5 {
  margin: 0 0 6px 0;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-subtle);
  letter-spacing: 0.06em;
}
.lb-export-menu .lb-export-sizes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}
.lb-export-menu .lb-export-sizes label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.lb-export-menu .lb-export-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.view-cols-popover {
  position: absolute;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius-md);
  z-index: 1000;
  max-height: 400px;
  overflow: auto;
  box-shadow: var(--shadow-popover);
  right: 1rem;
  margin-top: 4px;
  min-width: 220px;
}
.view-cols-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.2rem 0.3rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.view-cols-row:hover { background: #2a2a30; }
.view-cols-handle {
  cursor: grab;
  color: var(--text-muted);
  user-select: none;
  padding: 0 0.2rem;
  font-size: 0.85rem;
}
.view-cols-row.dragging { opacity: 0.5; }
.view-cols-reset {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}
.view-cols-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.view-cols-row.drop-after  { box-shadow: inset 0 -2px 0 var(--accent); }

/* Folder-view collapsibility */
.folder-node-header {
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.4rem;
  border-radius: 4px;
}
.folder-node-header:hover { background: var(--surface2); }
.folder-chevron {
  display: inline-block;
  width: 0.9rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.folder-node-body { padding: 0.4rem 0 0.6rem 1.6rem; }
.folder-node-body[hidden] { display: none; }

/* Inherited (non-manual) crop rating: italic + slightly dim so it's clear
   the value is following the source rating until overridden. */
.rating-select.rating-inherited {
  font-style: italic;
  opacity: 0.85;
}

/* Links column: small inline links inside the table cell */
.links-cell {
  font-size: 0.78rem;
  white-space: normal;
  max-width: 220px;
  line-height: 1.35;
}
.links-cell .link-group { margin-bottom: 0.15rem; }
.links-cell .link-group-label { color: var(--text-muted); margin-right: 0.3rem; }
.links-cell a { color: #60a5fa; margin-right: 0.35rem; }
.links-cell a:hover { text-decoration: underline; }

/* ===== Row density (table) ===== */
:root { --row-thumb-h: 48px; --row-thumb-w: 72px; --row-pad-y: 0.4rem; }
body.density-small  { --row-thumb-h: 32px; --row-thumb-w: 48px; --row-pad-y: 0.15rem; }
body.density-medium { --row-thumb-h: 48px; --row-thumb-w: 72px; --row-pad-y: 0.4rem; }
body.density-large  { --row-thumb-h: 96px; --row-thumb-w: 144px; --row-pad-y: 0.6rem; }
body.density-custom { /* values overridden inline via JS */ }

body[class*="density-"] .asset-table td        { padding-top: var(--row-pad-y); padding-bottom: var(--row-pad-y); }
body[class*="density-"] .row-thumb             { width: var(--row-thumb-w); height: var(--row-thumb-h); }
body[class*="density-"] .crop-thumb-cell img,
body[class*="density-"] .crop-thumb-cell .crop-thumb-empty {
  height: var(--row-thumb-h);
}

.density-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

/* ===== Export dialog ===== */
.export-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
}
.export-checks label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

/* ===== Source-rotation toolbar: move OFF the image ===== */
.lb-source-bar {
  /* Override earlier definition — anchor to bottom, full-width strip */
  position: absolute;
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  transform: none;
  justify-content: center;
  border-radius: 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.85);
  padding: 0.55rem 1rem;
}
/* When source-bar is visible, shrink the image so it never overlaps */
.lightbox.source-bar-active .lb-image,
.lightbox.source-bar-active .lb-image-half { max-height: 75vh; }
.lightbox.source-bar-active .lightbox-stage { padding-bottom: 4rem; }

/* ===== Preview mode (side-pane lightbox) ===== */
body.preview-mode {
  /* Reserve right half for the preview pane */
}
body.preview-mode main.wide,
body.preview-mode main {
  margin-right: 50vw;
  max-width: calc(100vw - 50vw);
  transition: margin-right 0.15s ease;
}
body.preview-mode .lightbox {
  position: fixed;
  top: 0;
  left: auto;
  right: 0;
  bottom: 0;
  width: 50vw;
  height: 100vh;
  padding: 1rem;
  background: rgba(0,0,0,0.96);
  border-left: 1px solid var(--border);
  z-index: 100; /* keep below regular modals */
}
body.preview-mode .lightbox .lb-image,
body.preview-mode .lightbox .lb-image-half {
  max-width: calc(50vw - 2rem);
  max-height: 78vh;
}
/* Carousel pair (8x5 = vasen + oikea) — keep BOTH halves inside the
   half-screen pane. The container itself caps at 50vw and each half gets
   half of that minus the gap. */
body.preview-mode .lightbox .lb-pair {
  max-width: calc(50vw - 2rem);
  width: 100%;
}
body.preview-mode .lightbox .lb-pair .lb-image-half {
  max-width: calc(25vw - 1.25rem);
  flex: 1 1 0;
  min-width: 0;
}
body.preview-mode .lightbox .lightbox-prev,
body.preview-mode .lightbox .lightbox-next {
  width: 36px; height: 36px; font-size: 1.1rem;
}
body.preview-mode #preview-mode-toggle { background: var(--accent-soft, rgba(59,130,246,0.18)); color: var(--text); }

/* Empty-state placeholder for the side preview pane when no asset is selected. */
.preview-empty {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50vw;
  background: rgba(0,0,0,0.96);
  border-left: 1px solid var(--border);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  z-index: 99;
  color: var(--text-muted, #aaa);
  text-align: center;
}
body.preview-mode .preview-empty { display: flex; }
body.preview-mode .preview-empty[data-lb-open="1"] { display: none; }
.preview-empty-icon { font-size: 2.4rem; opacity: 0.55; }
.preview-empty-msg { font-size: 0.95rem; max-width: 22rem; line-height: 1.4; }

/* Close-X for the preview side pane (visible whenever preview mode is on). */
.preview-close-x {
  position: fixed;
  top: 0.6rem;
  right: 0.7rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(40,40,40,0.9);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  z-index: 200;
  display: none;
}
body.preview-mode .preview-close-x { display: inline-flex; align-items: center; justify-content: center; }
.preview-close-x:hover { background: rgba(70,70,70,1); }

/* Inline photographer-card panel inside the import dialog. Surfaces existing
   contact details for the typed name, or empty fields for a brand-new
   photographer. */
.imp-ph-card {
  margin-top: 0.4rem;
  padding: 0.5rem 0.6rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex; flex-direction: column; gap: 0.4rem;
}
.imp-ph-card[hidden] { display: none; }
.imp-ph-card-status {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.imp-ph-card-status[data-kind="ok"]  { color: var(--success, #16a34a); }
.imp-ph-card-status[data-kind="new"] { color: var(--warn, #d97706); }
.imp-ph-card-status[data-kind="err"] { color: var(--danger, #dc2626); }
.imp-ph-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.6rem;
}
.imp-ph-card-grid label {
  display: flex; flex-direction: column; gap: 0.2rem;
  font-size: 0.82rem;
}
.imp-ph-card-wide { grid-column: 1 / -1; }
.imp-ph-key {
  color: var(--text-muted, #9aa);
  font-size: 0.78rem;
}
.imp-ph-card-grid input,
.imp-ph-card-grid textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.86rem;
}
.imp-ph-card-grid textarea { resize: vertical; min-height: 2.2rem; }
.imp-ph-card-grid input:focus,
.imp-ph-card-grid textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* ===== Photographers dialog + info popover ===== */
.ph-list {
  display: flex; flex-direction: column; gap: 0.5rem;
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.ph-card {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--border, #333);
  border-radius: 6px;
  background: var(--surface2, #1e1e25);
}
.ph-card-notes { grid-column: 1 / -1; }
.ph-card-notes textarea {
  width: 100%;
  resize: vertical;
  min-height: 2.2rem;
  background: var(--surface, #2a2a30);
  border: 1px solid var(--border, #444);
  color: var(--text, #eee);
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  font: inherit;
  font-size: 0.9rem;
}
.ph-card-notes textarea:focus { outline: none; border-color: #3b82f6; }
.ph-card input {
  background: var(--surface, #2a2a30);
  border: 1px solid var(--border, #444);
  color: var(--text, #eee);
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  font: inherit;
  font-size: 0.88rem;
  min-width: 0;
}
.ph-card input:focus { outline: none; border-color: #3b82f6; }
.ph-card-name input { font-weight: 500; }
.ph-card-remove {
  background: transparent;
  border: 0;
  color: var(--text-muted, #888);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem 0.45rem;
  border-radius: 4px;
}
.ph-card-remove:hover { color: var(--danger, #ef4444); background: rgba(239,68,68,0.08); }
.ph-empty { padding: 1rem; color: var(--text-muted, #888); font-size: 0.9rem; text-align: center; }

/* Photographer cell: click-to-open dropdown trigger + popover. */
.photographer-cell {
  position: relative; /* anchor for the absolutely-positioned info chip */
}
.ph-select-trigger {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.2rem 1.85rem 0.2rem 0.45rem; /* reserve right space for the (i) chip */
  font: inherit;
  color: var(--text);
  text-align: left;
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  box-sizing: border-box;
}
.photographer-cell .ph-info-chip {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  margin: 0; /* override default margin-left from base style */
}
.ph-select-trigger:hover {
  border-color: var(--border);
  background: var(--surface-2);
}
.ph-select-trigger.is-empty { color: var(--text-subtle); }
.ph-select-popover {
  z-index: 1200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-popover);
  padding: 0.4rem;
  display: flex; flex-direction: column;
  gap: 0.4rem;
  max-height: 60vh;
  width: 280px;
}
.ph-select-search {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.ph-select-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.ph-select-list {
  display: flex; flex-direction: column;
  overflow: auto;
  min-height: 0;
}
.ph-select-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.ph-select-item:hover { background: var(--surface-2); }
.ph-select-item.is-active { background: var(--accent-soft); }
.ph-select-name { font-weight: 500; }
.ph-select-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}
.ph-select-clear { color: var(--text-muted); font-style: italic; }
.ph-select-empty {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.ph-select-add {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.ph-select-add:hover { background: var(--accent); color: #fff; }

/* Inline "Uusi kuvaaja" form rendered into the same popover. */
.ph-select-form {
  display: flex; flex-direction: column;
  gap: 0.5rem;
  padding: 0.1rem;
}
.ph-select-form-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.ph-select-field {
  display: flex; flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}
.ph-select-field-label { color: var(--text-muted); }
.ph-select-field-label .req { color: var(--danger, #dc2626); }
.ph-select-field input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.ph-select-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.ph-select-field.has-error input {
  border-color: var(--danger, #dc2626);
}
.ph-select-field-error {
  min-height: 0;
  font-size: 0.75rem;
  color: var(--danger, #dc2626);
}
.ph-select-field-error:empty { display: none; }
.ph-select-form-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1em;
}
.ph-select-form-actions {
  display: flex; justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

/* Info-chip rendered next to a photographer name in the table — clicking opens
   the shared #photographer-popover with phone/email/contact details. */
.ph-info-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.1rem; height: 1.1rem;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: rgba(59,130,246,0.18);
  color: #93c5fd;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  vertical-align: middle;
  flex: 0 0 auto;
}
.ph-info-chip:hover { background: rgba(59,130,246,0.3); color: #fff; }

.ph-popover {
  position: fixed;
  background: var(--surface2, #1e1e25);
  border: 1px solid var(--border, #333);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 0.7rem 0.8rem;
  font-size: 0.88rem;
  color: var(--text, #eee);
  z-index: 200;
  min-width: 220px;
  max-width: 320px;
}
.ph-popover[hidden] { display: none; }
.ph-popover-name { font-weight: 600; margin: 0 0 0.4rem; font-size: 0.95rem; }
.ph-popover-row { display: flex; gap: 0.5rem; padding: 0.15rem 0; }
.ph-popover-key { color: var(--text-muted, #999); flex: 0 0 8rem; }
.ph-popover-val { color: var(--text, #eee); word-break: break-word; flex: 1; }
.ph-popover-val a { color: #93c5fd; text-decoration: none; }
.ph-popover-val a:hover { text-decoration: underline; }
.ph-popover-empty { color: var(--text-muted, #999); font-style: italic; font-size: 0.85rem; }
.ph-popover-edit {
  display: inline-block; margin-top: 0.5rem;
  background: transparent; border: 0; color: #93c5fd; cursor: pointer;
  font-size: 0.82rem; padding: 0;
}
.ph-popover-edit:hover { text-decoration: underline; }

/* Import dialog tag-target checkboxes (Lähdekuva + crops + select all) */
.imp-tag-targets {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
  padding: 0.4rem 0;
  font-size: 0.88rem;
}
.imp-tag-targets label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.imp-tag-targets .imp-tag-target-all { font-weight: 500; padding-right: 0.6rem; border-right: 1px solid var(--border); margin-right: 0.2rem; }

/* Generic modal × close in top-right of modal-card */
.modal-close-x {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close-x:hover { background: var(--surface2); color: var(--text); }

/* Picker apply-all checkbox row */
.tag-picker-apply-all {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

/* Import-dialog source-tags widget host */
.imp-tags-host { display: block; margin-top: 0.3rem; }
.imp-tags-host .tags-widget { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }
