:root {
  --font-system: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, 'Cascadia Code', 'Consolas', monospace;

  --text-caption2: 11px;
  --text-caption1: 12px;
  --text-footnote: 13px;
  --text-subhead: 15px;
  --text-body: 16px;
  --text-headline: 17px;
  --text-title3: 20px;
  --text-title2: 22px;

  --line-height-tight: 1.15;
  --line-height-normal: 1.45;
  --line-height-relaxed: 1.55;

  --system-blue: #007AFF;
  --system-green: #34C759;
  --system-indigo: #5856D6;
  --system-orange: #FF9500;
  --system-red: #FF3B30;
  --system-gray: #8E8E93;

  --label-primary: #111827;
  --label-secondary: rgba(60, 60, 67, 0.72);
  --label-tertiary: rgba(60, 60, 67, 0.45);

  --fill-primary: rgba(120, 120, 128, 0.20);
  --fill-secondary: rgba(120, 120, 128, 0.14);
  --fill-tertiary: rgba(120, 120, 128, 0.09);
  --fill-quaternary: rgba(120, 120, 128, 0.05);

  --bg-primary: #F2F2F7;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F9F9FB;
  --separator: rgba(60, 60, 67, 0.16);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.14);
  --shadow-focus: 0 0 0 4px rgba(0, 122, 255, 0.28);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-modal: 20px;
  --radius-full: 9999px;

  --duration-fast: 150ms;
  --duration-normal: 220ms;
  --ease-out: cubic-bezier(0, 0, 0.58, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@media (prefers-color-scheme: dark) {
  :root {
    --system-blue: #0A84FF;
    --system-green: #30D158;
    --system-indigo: #5E5CE6;
    --system-orange: #FF9F0A;
    --system-red: #FF453A;

    --label-primary: #F9FAFB;
    --label-secondary: rgba(235, 235, 245, 0.72);
    --label-tertiary: rgba(235, 235, 245, 0.45);

    --fill-primary: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.28);
    --fill-tertiary: rgba(120, 120, 128, 0.20);
    --fill-quaternary: rgba(120, 120, 128, 0.12);

    --bg-primary: #0B0B0F;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --separator: rgba(84, 84, 88, 0.55);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-popover: 0 14px 36px rgba(0, 0, 0, 0.5);
  }
}

@media (prefers-contrast: high) {
  :root {
    --label-secondary: rgba(60, 60, 67, 0.88);
    --separator: rgba(60, 60, 67, 0.48);
  }
}

@media (prefers-contrast: high) and (prefers-color-scheme: dark) {
  :root {
    --label-secondary: rgba(235, 235, 245, 0.90);
    --separator: rgba(84, 84, 88, 0.85);
  }
}

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

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-bottom: 48px;
  font-family: var(--font-system);
  font-size: var(--text-subhead);
  line-height: var(--line-height-normal);
  color: var(--label-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

body.has-queue-bar {
  padding-bottom: 104px;
}

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-lg {
  width: 28px;
  height: 28px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* Header & Navigation */
header.toolbar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--separator);
  padding: var(--space-3) var(--space-6);
  position: sticky;
  top: 0;
  z-index: 30;
}

.toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-title-btn {
  background: transparent;
  border: none;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: var(--radius-sm);
  color: var(--label-primary);
  font-family: var(--font-system);
  font-size: var(--text-title2);
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.brand-title-btn:hover { opacity: 0.78; }

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Dropdown / Popover */
details.dropdown {
  position: relative;
  display: inline-block;
}

details.dropdown[open] { z-index: 50; }

details.dropdown > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

details.dropdown > summary::-webkit-details-marker { display: none; }

.dropdown-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 260px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 60;
}

.dropdown-section {
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dropdown-divider {
  height: 1px;
  background-color: var(--separator);
  margin: 4px 0;
}

.dropdown-item {
  width: 100%;
  min-height: 38px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--label-primary);
  font-family: var(--font-system);
  font-size: var(--text-footnote);
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.dropdown-item:hover:not(:disabled) { background-color: var(--fill-tertiary); }
.dropdown-item:disabled { opacity: 0.45; cursor: not-allowed; }
.dropdown-item.active {
  background-color: rgba(0, 122, 255, 0.12);
  color: var(--system-blue);
}
.dropdown-item.danger { color: var(--system-red); }
.dropdown-item.muted { color: var(--label-tertiary); cursor: default; }

/* Badges */
.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-caption1);
  font-weight: 600;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--separator);
  color: var(--label-primary);
  white-space: nowrap;
}

.pill-badge.perm-view {
  background-color: rgba(0, 122, 255, 0.12);
  color: var(--system-blue);
  border-color: rgba(0, 122, 255, 0.30);
}

.pill-badge.perm-ok {
  background-color: rgba(52, 199, 89, 0.14);
  color: var(--system-green);
  border-color: rgba(52, 199, 89, 0.32);
}

.pill-badge.perm-strong {
  background-color: rgba(255, 149, 0, 0.14);
  color: var(--system-orange);
  border-color: rgba(255, 149, 0, 0.35);
}

.pill-badge.perm-admin,
.pill-badge.perm-none {
  background-color: rgba(255, 59, 48, 0.14);
  color: var(--system-red);
  border-color: rgba(255, 59, 48, 0.35);
}

.perm-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Main Container */
main.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.tab-panel { display: none; flex-direction: column; gap: var(--space-4); }
.tab-panel.active { display: flex; }

/* Startup Spinner & Auth Gate */
.auth-loading-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 72px var(--space-6);
  color: var(--label-secondary);
}

.auth-loading-state.visible { display: flex; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--separator);
  border-top-color: var(--system-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-gate {
  background-color: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: var(--space-5) auto;
  max-width: 540px;
  width: 100%;
  text-align: center;
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  align-items: center;
  box-shadow: var(--shadow-popover);
}

.auth-gate.visible { display: flex; }
.auth-gate.error { border-color: rgba(255, 59, 48, 0.45); }

.auth-gate-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background-color: rgba(0, 122, 255, 0.12);
  color: var(--system-blue);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-gate.error .auth-gate-icon {
  background-color: rgba(255, 59, 48, 0.12);
  color: var(--system-red);
}

.google-signin-slot {
  min-height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: var(--space-1) 0;
}

.client-id-setup-box {
  width: 100%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: left;
  display: none;
  flex-direction: column;
  gap: var(--space-2);
}

.client-id-setup-box.visible { display: flex; }

/* Inline Status Banner (page-level notices when needed) */
.status-banner {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-footnote);
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.status-banner.visible { display: flex; }
.status-banner.error {
  background-color: rgba(255, 59, 48, 0.12);
  color: var(--system-red);
  border: 1px solid rgba(255, 59, 48, 0.35);
}
.status-banner.success {
  background-color: rgba(52, 199, 89, 0.12);
  color: var(--system-green);
  border: 1px solid rgba(52, 199, 89, 0.35);
}
.status-banner.info {
  background-color: rgba(0, 122, 255, 0.10);
  color: var(--system-blue);
  border: 1px solid rgba(0, 122, 255, 0.30);
}

/* Search Panel & Progressive Disclosure */
.panel {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}

.main-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-3);
}

.search-mode-col {
  flex: 0 0 260px;
  max-width: 100%;
}

.search-input-col {
  flex: 1 1 320px;
  min-width: 240px;
}

.search-cta-col {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  header.toolbar { padding: var(--space-3) var(--space-4); }
  main.container { padding: var(--space-4); }
  .search-mode-col { flex: 1 1 100%; }
  .search-cta-col { width: 100%; justify-content: flex-end; }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: var(--text-caption1);
  font-weight: 600;
  color: var(--label-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#main-search-input-slot .field-label.slot-hideable {
  display: none;
}

.textarea-wrap { position: relative; }

.codes-counter-badge {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-family: var(--font-mono);
  font-size: var(--text-caption2);
  color: var(--label-secondary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  pointer-events: none;
}

.codes-counter-badge.over-limit {
  background-color: rgba(255, 59, 48, 0.14);
  color: var(--system-red);
  border-color: rgba(255, 59, 48, 0.45);
  font-weight: 700;
}

textarea.apple-textarea,
input.apple-input,
select.apple-select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
  background-color: var(--bg-tertiary);
  color: var(--label-primary);
  font-family: var(--font-system);
  font-size: var(--text-subhead);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

textarea.apple-textarea {
  min-height: 44px;
  max-height: 220px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--text-footnote);
  line-height: 1.45;
  padding-right: 104px;
}

textarea.apple-textarea:focus {
  min-height: 108px;
}

input.apple-input,
select.apple-select {
  min-height: 44px;
}

textarea.apple-textarea:focus,
input.apple-input:focus,
select.apple-select:focus {
  box-shadow: var(--shadow-focus);
  border-color: var(--system-blue);
}

.advanced-filters-panel {
  display: none;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--separator);
  flex-direction: column;
  gap: var(--space-3);
}

.advanced-filters-panel.open { display: flex; }

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  align-items: start;
}

.date-range-row {
  display: grid;
  grid-template-columns: 120px 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--separator);
  background-color: var(--bg-tertiary);
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--label-primary);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}

.checkbox-pill:hover { background-color: var(--fill-tertiary); }

.checkbox-pill input[type="checkbox"] {
  accent-color: var(--system-blue);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}

@media (max-width: 720px) {
  .date-range-row { grid-template-columns: 1fr; }
}

/* Active Filter Chips & Recent History */
.filter-chips-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--separator);
}

.filter-chips-bar.visible { display: flex; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background-color: rgba(0, 122, 255, 0.10);
  color: var(--system-blue);
  border: 1px solid rgba(0, 122, 255, 0.25);
  font-size: var(--text-caption1);
  font-weight: 600;
}

.filter-chip button {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
}

.recent-searches-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-2);
}

.recent-searches-bar.visible { display: flex; }

.recent-chip-btn {
  border: 1px solid var(--separator);
  background-color: var(--bg-tertiary);
  color: var(--label-secondary);
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: var(--text-caption1);
  cursor: pointer;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.recent-chip-btn:hover {
  background-color: var(--fill-tertiary);
  color: var(--label-primary);
}

/* Buttons */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-full);
  font-family: var(--font-system);
  font-size: var(--text-footnote);
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: var(--text-caption1);
}

.btn-xs {
  min-height: 26px;
  padding: 0 8px;
  font-size: var(--text-caption2);
}

.btn-icon {
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
}

.btn-primary { background-color: var(--system-blue); color: #FFFFFF; }
.btn-primary:hover:not(:disabled) { filter: brightness(0.93); }

.btn-green { background-color: var(--system-green); color: #FFFFFF; }
.btn-green:hover:not(:disabled) { filter: brightness(0.93); }

.btn-secondary {
  background-color: rgba(0, 122, 255, 0.12);
  color: var(--system-blue);
}
.btn-secondary:hover:not(:disabled) { background-color: rgba(0, 122, 255, 0.19); }

.btn-neutral {
  background-color: var(--bg-tertiary);
  color: var(--label-primary);
  border: 1px solid var(--separator);
}
.btn-neutral:hover:not(:disabled) { background-color: var(--fill-tertiary); }

.btn-danger-outline {
  background-color: rgba(255, 59, 48, 0.12);
  color: var(--system-red);
}
.btn-danger-outline:hover:not(:disabled) { background-color: rgba(255, 59, 48, 0.19); }

.btn-danger {
  background-color: var(--system-red);
  color: #FFFFFF;
}

.btn-queued {
  background-color: rgba(52, 199, 89, 0.16);
  color: var(--system-green);
  border: 1px solid rgba(52, 199, 89, 0.35);
}

.copy-inline-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--label-secondary);
  padding: 2px 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-caption2);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.copy-inline-btn:hover {
  background-color: var(--fill-tertiary);
  color: var(--system-blue);
}

/* Results Toolbar & Unmatched Box */
.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.unmatched-box {
  background-color: rgba(255, 149, 0, 0.12);
  border: 1px solid rgba(255, 149, 0, 0.35);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: none;
  flex-direction: column;
  gap: var(--space-2);
}

.unmatched-box.visible { display: flex; }

.unmatched-list {
  font-family: var(--font-mono);
  font-size: var(--text-caption1);
  max-height: 96px;
  overflow-y: auto;
  word-break: break-all;
}

/* Empty & Loading Skeleton States */
.empty-guide {
  background-color: var(--bg-secondary);
  border: 1px dashed var(--separator);
  border-radius: var(--radius-lg);
  padding: 56px var(--space-6);
  text-align: center;
  color: var(--label-secondary);
}

.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    var(--fill-tertiary) 25%,
    var(--fill-secondary) 50%,
    var(--fill-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

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

.search-skeleton-wrap {
  display: none;
  flex-direction: column;
  gap: var(--space-2);
}

.search-skeleton-wrap.visible { display: flex; }

.skeleton-row {
  height: 62px;
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
}

/* Card Grid */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(276px, 1fr));
  gap: var(--space-4);
}

.eps-card {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-3);
  overflow: visible;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.eps-card:hover { border-color: rgba(0, 122, 255, 0.45); }

.thumb-frame {
  position: relative;
  width: 100%;
  height: 170px;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.thumb-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 2;
}

.thumb-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  text-align: center;
  color: var(--label-secondary);
  font-size: var(--text-caption2);
  width: 100%;
  height: 100%;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: var(--space-2);
}

.card-title {
  font-size: var(--text-subhead);
  font-weight: 700;
  margin: 0;
  word-break: break-all;
}

.card-meta {
  font-size: var(--text-caption1);
  color: var(--label-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

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

.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-actions .btn-grow { flex: 1 1 0; }

.box-links-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Table View with Sticky Header */
.table-wrap {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  overflow: auto;
  max-height: min(72vh, 880px);
  box-shadow: var(--shadow-sm);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-footnote);
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
  vertical-align: middle;
}

table.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  color: var(--label-secondary);
  font-weight: 600;
  font-size: var(--text-caption1);
  background-color: var(--bg-tertiary);
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--separator);
}

table.data-table tbody tr {
  transition: background-color var(--duration-fast) var(--ease-out);
}

table.data-table tbody tr:hover {
  background-color: var(--fill-quaternary);
}

.thumb-mini-box {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--separator);
  background-color: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.thumb-mini {
  width: 50px;
  height: 50px;
  object-fit: contain;
  cursor: pointer;
}

.lazy-footer,
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

/* Dynamic Floating Queue Bar */
.queue-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--separator);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
  padding: 10px var(--space-6);
  display: none;
}

.queue-bar.visible { display: block; }

.queue-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.size-warning-text {
  color: var(--system-orange);
  font-weight: 700;
}

.size-danger-text {
  color: var(--system-red);
  font-weight: 700;
}

/* Floating Toast Notifications */
.toast-container {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 420px;
  width: calc(100vw - 32px);
  pointer-events: none;
}

body.has-queue-bar .toast-container {
  bottom: 84px;
}

.toast-item {
  pointer-events: auto;
  background-color: var(--bg-secondary);
  color: var(--label-primary);
  border: 1px solid var(--separator);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-footnote);
  font-weight: 600;
  animation: scaleIn var(--duration-normal) var(--ease-spring);
}

.toast-item.success { border-left-color: var(--system-green); }
.toast-item.info { border-left-color: var(--system-blue); }
.toast-item.error { border-left-color: var(--system-red); }

@keyframes scaleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Dialog Modals */
dialog.apple-dialog {
  overscroll-behavior: contain;
  border: 1px solid var(--separator);
  border-radius: var(--radius-modal);
  background-color: var(--bg-secondary);
  color: var(--label-primary);
  padding: var(--space-5);
  max-width: 820px;
  width: calc(100% - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

dialog.apple-dialog.dialog-compact {
  max-width: 420px;
}

dialog.apple-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.dialog-preview-box {
  position: relative;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.dialog-preview-box img {
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-caption1);
  margin-bottom: var(--space-4);
}

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-caption2);
  font-weight: 700;
}

.status-tag.ALLOW { background-color: rgba(52, 199, 89, 0.16); color: var(--system-green); }
.status-tag.DENY { background-color: rgba(255, 59, 48, 0.16); color: var(--system-red); }

/* Admin Subsections */
.admin-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-2);
  align-items: end;
}

details.verification-box {
  border: 1px dashed var(--separator);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background-color: var(--bg-tertiary);
}

details.verification-box > summary {
  cursor: pointer;
  font-weight: 700;
  font-size: var(--text-footnote);
  color: var(--label-secondary);
}

/* Print Optimization */
@media print {
  body {
    background-color: #FFFFFF !important;
    color: #000000 !important;
    padding: 0 !important;
  }
  header.toolbar,
  #search-form,
  #results-toolbar,
  .filter-chips-bar,
  .recent-searches-bar,
  .lazy-footer,
  .pagination-bar,
  #sticky-queue-bar,
  .toast-container,
  .copy-inline-btn,
  .col-select,
  .col-actions {
    display: none !important;
  }
  .table-wrap {
    max-height: none !important;
    overflow: visible !important;
    border: none !important;
    box-shadow: none !important;
  }
}
