/* ============================================================
   Semble Tools — stylesheet
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --border: #e4e4e8;
  --text: #111112;
  --text-2: #58585f;
  --text-3: #9898a3;
  --accent: #4338ca;
  --accent-soft: rgba(67, 56, 202, 0.08);
  --danger: #dc2626;
  --success: #16a34a;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Type scale */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13.5px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --lh-tight: 1.3;
  --lh-snug: 1.45;
  --lh-base: 1.6;
  /* Optical letter-spacing */
  --tracking-tight: -0.011em;
  --tracking-caps: 0.06em;

  --sidebar-w: 200px;
  --nav-h: 58px;
}

/* Auto dark */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --surface: #1a1a1c;
    --surface-2: #222226;
    --border: #2d2d32;
    --text: #f0f0f2;
    --text-2: #8c8c96;
    --text-3: #52525c;
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.10);
  }
}

/* Forced light */
html[data-theme="light"] {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --border: #e4e4e8;
  --text: #111112;
  --text-2: #58585f;
  --text-3: #9898a3;
  --accent: #4338ca;
  --accent-soft: rgba(67, 56, 202, 0.08);
}

/* Forced dark */
html[data-theme="dark"] {
  --bg: #0f0f10;
  --surface: #1a1a1c;
  --surface-2: #222226;
  --border: #2d2d32;
  --text: #f0f0f2;
  --text-2: #8c8c96;
  --text-3: #52525c;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.10);
}

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

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  letter-spacing: -0.003em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}

/* Tabular figures so counts/dates line up in columns */
.col-num,
.lr-count,
.key-display,
.batch-log,
.page-foot,
.bulk-bar-label span {
  font-variant-numeric: tabular-nums;
}

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

.hidden { display: none !important; }

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.mono { font-family: var(--mono); }

/* ---------- Keyboard focus ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 5px;
}
/* Inputs already show a focus ring via box-shadow; avoid doubling up */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}

/* ---------- Loading / skeleton ---------- */
@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes shimmer {
  0% { background-position: -480px 0; }
  100% { background-position: 480px 0; }
}

.skeleton-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.skel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.skel-row:last-child { border-bottom: none; }

.skel {
  background: var(--surface-2);
  background-image: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border) 50%,
    var(--surface-2) 100%
  );
  background-size: 480px 100%;
  background-repeat: no-repeat;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: 4px;
}

.skel-thumb { width: 36px; height: 26px; flex-shrink: 0; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.skel-line { height: 10px; }
.skel-line.w-60 { width: 60%; }
.skel-line.w-40 { width: 40%; }
.skel-line.w-80 { width: 80%; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Gate ---------- */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}

.gate-brand {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
  margin-bottom: 10px;
}

.gate-tagline {
  font-size: var(--fs-base);
  color: var(--text-2);
  margin: 0 0 22px;
  line-height: var(--lh-base);
}

.gate-error {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
  margin: 8px 0 0;
}

.gate-help {
  font-size: 12px;
  color: var(--text-3);
  margin: 16px 0 0;
  line-height: 1.6;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Mobile header (desktop: hidden) ---------- */
.mobile-header {
  display: none;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 15px 16px 11px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
  flex: 1;
}

.nav-item {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  padding: 9px 16px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

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

.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.sidebar-foot {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.me-chip {
  font-size: 12px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.me-chip img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}

.theme-btn {
  font: inherit;
  font-size: 11px;
  color: var(--text-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--text-3);
}

/* ---------- Main / view ---------- */
.main { min-width: 0; }

.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 28px 80px;
}

/* ---------- View header ---------- */
.view-head {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.view-head h1 {
  font-size: var(--fs-lg);
  font-weight: 680;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  margin: 0;
  color: var(--text);
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}

.btn:hover { background: var(--surface-2); }

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { opacity: 0.88; background: var(--accent); }

.btn-danger {
  color: var(--danger);
  border-color: var(--border);
}

.btn-danger:hover { background: rgba(220, 38, 38, 0.07); }

.btn-block { width: 100%; }

.btn-sm {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 5px;
}

/* ---------- Form fields ---------- */
.field {
  display: block;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-3);
  margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="url"],
select,
textarea {
  font: inherit;
  font-size: 13px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input.mono,
textarea.mono {
  font-family: var(--mono);
  font-size: 12px;
}

select { cursor: pointer; }

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ---------- Toolbar row ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .grow { flex: 1 1 200px; }

.toolbar select,
.toolbar input {
  width: auto;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------- Table ---------- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-3);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  user-select: none;
}

.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: var(--surface-2); }

/* checkbox col — only visible on hover or when checked */
.data-table .col-check {
  width: 32px;
  padding-right: 4px;
}

.data-table tbody tr .cb-cell {
  opacity: 0;
  transition: opacity 0.15s;
}

.data-table tbody tr:hover .cb-cell,
.data-table tbody tr.row-checked .cb-cell {
  opacity: 1;
}

.data-table input[type="checkbox"] {
  width: auto;
  cursor: pointer;
  accent-color: var(--accent);
}

/* thumbnail col */
.col-thumb { width: 50px; }

.row-thumb {
  width: 40px;
  height: 30px;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.row-thumb-ph {
  width: 40px;
  height: 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: block;
}

/* title + site cell */
.cell-title {
  font-weight: 500;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cell-title a {
  color: inherit;
  text-decoration: none;
}

.cell-title a:hover { text-decoration: underline; }

.cell-site {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

/* mono number col */
.col-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  text-align: right;
}

/* date col */
.col-date {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

/* remove col */
.col-action {
  width: 32px;
  text-align: center;
}

.row-rm {
  font: inherit;
  font-size: 13px;
  color: var(--text-3);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.data-table tbody tr:hover .row-rm { opacity: 1; }
.row-rm:hover { color: var(--danger); background: rgba(220, 38, 38, 0.07); }

/* ---------- Type chip ---------- */
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}

.chip-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chip-success {
  background: rgba(22, 163, 74, 0.08);
  border-color: var(--success);
  color: var(--success);
}

/* ---------- Collection pill toggles ---------- */
.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.pill {
  font: inherit;
  font-size: 12px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.pill:hover { border-color: var(--text-3); color: var(--text); }

.pill.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.pill.active .pill-check::before { content: "✓ "; }

/* ---------- URL preview card (Add view) ---------- */
.preview-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  gap: 14px;
  padding: 14px;
}

.preview-thumb {
  width: 80px;
  height: 56px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
  display: block;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.preview-body { min-width: 0; flex: 1; }

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.preview-desc {
  font-size: 12px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.preview-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}

.preview-site {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

/* ---------- Status badge (in library / not) ---------- */
.status-line {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-saved { color: var(--success); }
.status-new { color: var(--text-3); }

/* ---------- Link row (search/discover results) ---------- */
.link-rows {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.link-row:last-child { border-bottom: none; }
.link-row:hover { background: var(--surface-2); }

.lr-thumb {
  width: 36px;
  height: 26px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
  display: block;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.lr-body { flex: 1; min-width: 0; }

.lr-title {
  font-size: var(--fs-base);
  font-weight: 550;
  line-height: var(--lh-snug);
  letter-spacing: -0.005em;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lr-title a { color: inherit; text-decoration: none; }
.lr-title a:hover { text-decoration: underline; }

.lr-meta {
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 3px;
  flex-wrap: wrap;
}

.lr-site { font-family: var(--mono); }

.lr-count { font-family: var(--mono); color: var(--text-3); }

.lr-badge {
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}

.lr-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.save-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.save-btn:hover { border-color: var(--accent); color: var(--accent); }

.save-btn.saved {
  color: var(--success);
  border-color: var(--success);
  opacity: 0.75;
  cursor: default;
}

/* ---------- Bulk action bar ---------- */
.bulk-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  z-index: 10;
}

.bulk-bar-label {
  color: var(--text-2);
  white-space: nowrap;
  font-weight: 500;
}

.bulk-bar-label span {
  color: var(--text);
  font-weight: 700;
}

/* ---------- Collapsible ---------- */
.collapsible-head {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  width: 100%;
  text-align: left;
  padding: 12px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}

.collapsible-head:hover { color: var(--text); }
.collapsible-caret { font-size: 10px; }
.collapsible-body { padding: 8px 0; }

/* ---------- Batch progress ---------- */
.batch-log {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 10px;
  line-height: 1.7;
}

.batch-ok { color: var(--success); }
.batch-err { color: var(--danger); }
.batch-summary { font-weight: 700; margin-top: 6px; }

/* ---------- Inline states ---------- */
.loading-line {
  color: var(--text-3);
  font-size: 13px;
  padding: 16px 0;
  animation: pulse 1.6s ease-in-out infinite;
}

.empty-line {
  color: var(--text-3);
  font-size: 13px;
  padding: 16px 0;
}

.error-line {
  color: var(--danger);
  font-size: 13px;
  padding: 10px 0;
}

/* ---------- Collections table ---------- */
.col-name { font-weight: 600; }
.col-access-open { color: var(--text-2); }
.col-access-closed { color: var(--text-3); }

/* ---------- Inline create form ---------- */
.inline-form {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-form .field {
  margin-bottom: 0;
  flex: 1 1 180px;
}

/* ---------- Settings view ---------- */
.settings-section {
  margin-bottom: 28px;
}

.settings-section h2 {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-3);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.settings-status {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 8px;
}

.key-display {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 10px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Discover ---------- */
.discover-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 12px;
}

.discover-meta strong { color: var(--text-2); }

/* ---------- Pagination ---------- */
.page-foot {
  padding: 14px 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
}

/* ============================================================
   Mobile-only elements
   ============================================================ */

.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 52px;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.mobile-brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.mobile-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  bottom: env(safe-area-inset-bottom, 0);
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  align-items: stretch;
  /* Ensure content isn't hidden behind home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-nav .nav-item {
  flex: 1;
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  padding: 6px 2px;
  border-left: none;
  border-top: 2px solid transparent;
  border-bottom: none;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}

.mobile-nav .nav-item.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left: none;
  border-top-color: var(--accent);
}

/* ============================================================
   Responsive — ≤ 680px
   ============================================================ */
@media (max-width: 680px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar { display: none; }
  .mobile-header { display: flex; }
  .mobile-nav { display: flex; }

  /* Account for bottom nav + safe area */
  .view {
    padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  /* Bulk bar floats above mobile nav */
  .bulk-bar {
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  }

  /* Main search input goes full-width, filters wrap below */
  .toolbar .grow {
    flex: 1 1 100%;
  }

  /* Hide less-critical table columns */
  .data-table .col-check,
  .data-table .col-thumb,
  .col-date { display: none; }

  /* Inline form stacks */
  .inline-form {
    flex-direction: column;
  }
  .inline-form .field { flex: none; width: 100%; }

  /* More breathing room in link rows for touch */
  .link-row { padding: 13px 14px; }

  /* Preview card stacks on narrow screens */
  .preview-card { flex-direction: column; }
  .preview-thumb { width: 100%; height: 140px; }

  /* Gate card on small screens */
  .gate { padding: 16px; }
  .gate-card { padding: 24px; border-radius: 10px; }
}
