/* ════════════════════════════════════════════════════════════════════════════
   GeminiTagger Web — Design System & Component Styles
   Dark glassmorphism theme with blue-violet accent palette
   ════════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────────────────────────── */
:root {
  /* Background layers */
  --bg-base:    #0c0f1a;
  --bg-surface: #131726;
  --bg-elevated:#1a2035;
  --bg-card:    #1e2540;
  --bg-hover:   #252d4a;

  /* Borders */
  --border:     rgba(100,120,200,0.15);
  --border-md:  rgba(100,120,200,0.25);
  --border-bright: rgba(100,130,255,0.4);

  /* Accent palette */
  --accent:     #6366f1;
  --accent-2:   #8b5cf6;
  --accent-glow:rgba(99,102,241,0.35);
  --accent-grad:linear-gradient(135deg, #6366f1, #8b5cf6);

  /* Semantic colours */
  --green:  #22c55e;
  --blue:   #3b82f6;
  --yellow: #f59e0b;
  --orange: #f97316;
  --red:    #ef4444;
  --purple: #a855f7;
  --teal:   #14b8a6;

  /* Text */
  --text-primary:   #e8eaf6;
  --text-secondary: #9ba3c0;
  --text-muted:     #5a6380;

  /* State colours (badge backgrounds) */
  --state-empty:      #ef4444;
  --state-embedded:   #a855f7;
  --state-skipped:    #f59e0b;
  --state-processing: #3b82f6;
  --state-done:       #14b8a6;
  --state-edited:     #f59e0b;
  --state-failed:     #ef4444;

  /* Layout */
  --toolbar-h:    56px;
  --statusbar-h:  32px;
  --logs-h:       200px;
  --panel-w:      280px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-xs:    4px;
  --shadow:       0 4px 24px rgba(0,0,0,0.45);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* scrollbar */
::-webkit-scrollbar            { width: 6px; height: 6px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--border-md); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover{ background: var(--accent); }

/* ── Toolbar ─────────────────────────────────────────────────────────────────── */
#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  background: rgba(13,16,30,0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  z-index: 1000;
}

.toolbar-left   { display:flex; align-items:center; gap:10px; flex-shrink:0; }
.toolbar-center { display:flex; align-items:center; gap:6px; flex:1; justify-content:center; flex-wrap:nowrap; overflow-x:auto; overflow-y:hidden; scrollbar-width:none; -ms-overflow-style:none; }
.toolbar-center::-webkit-scrollbar { display:none; }
.toolbar-right  { display:flex; align-items:center; gap:6px; flex-shrink:0; }
.panel-toggles-wrap { display:flex; align-items:center; gap:6px; }

/* Logo */
.app-logo { display:flex; align-items:center; gap:8px; }
.logo-icon { font-size:18px; background:var(--accent-grad); -webkit-background-clip:text; -webkit-text-fill-color:transparent; }
.logo-text { font-weight:700; font-size:15px; letter-spacing:-0.3px; color:var(--text-primary); }
.logo-badge {
  font-size:9px; font-weight:600; letter-spacing:0.5px; text-transform:uppercase;
  background:var(--accent-grad); color:#fff; padding:2px 6px; border-radius:20px;
}

.toolbar-sep { width:1px; height:28px; background:var(--border); margin:0 4px; }

/* ── Status bar ──────────────────────────────────────────────────────────────── */
#statusbar {
  position: fixed;
  top: var(--toolbar-h); left: 0; right: 0;
  height: var(--statusbar-h);
  background: rgba(19,23,38,0.95);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  z-index: 99;
  font-size: 11.5px;
  color: var(--text-secondary);
}

#status-text  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#counter-text { flex-shrink: 0; color: var(--text-muted); }

#progress-wrap {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
#progress-bar {
  width: 160px; height: 6px; background: var(--bg-elevated);
  border-radius: 3px; overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}
#progress-label { font-size: 11px; color: var(--text-muted); min-width: 48px; text-align: right; }

/* ── Main layout ─────────────────────────────────────────────────────────────── */
#main-layout {
  position: fixed;
  top: calc(var(--toolbar-h) + var(--statusbar-h));
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  overflow: hidden;
  transition: bottom 0.3s ease;
}

#main-layout.logs-open {
  bottom: var(--logs-h);
}

/* ── Side panels ─────────────────────────────────────────────────────────────── */
.side-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, opacity 0.25s ease;
}

#metadata-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

.side-panel.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Centre content (image grid) ────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-base);
  position: relative;
}

/* ── Image grid ──────────────────────────────────────────────────────────────── */
#image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  align-content: flex-start;
  min-height: 100%;
}

/* Empty state */
.grid-empty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  pointer-events: none;
}
.grid-empty-icon { font-size: 56px; opacity: 0.4; }
.grid-empty-title { font-size: 18px; font-weight: 600; color: var(--text-secondary); }
.grid-empty-sub   { font-size: 13px; max-width: 300px; line-height: 1.5; }

/* ── Image card ──────────────────────────────────────────────────────────────── */
.image-card {
  width: 186px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  position: relative;
}
.image-card:hover   { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-md); }
.image-card.selected{ border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-glow); }

/* Card thumbnail */
.card-thumb {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
  background: var(--bg-elevated);
}
.card-thumb-placeholder {
  width: 100%;
  height: 130px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  opacity: 0.4;
}

/* Card badge */
.card-badge {
  display: block;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 6px;
  color: #fff;
  text-transform: uppercase;
}
.badge-empty      { background: var(--state-empty); }
.badge-embedded   { background: var(--state-embedded); }
.badge-skipped    { background: var(--state-skipped); color:#000; }
.badge-processing { background: var(--state-processing); animation: pulse-badge 1.2s ease infinite; }
.badge-done       { background: var(--state-done); }
.badge-edited     { background: var(--state-edited); color:#000; }
.badge-failed     { background: var(--state-failed); }

/* Card border colour per state */
.image-card[data-state="done"]       { border-color: rgba(20,184,166,0.45); }
.image-card[data-state="processing"] { border-color: rgba(59,130,246,0.55); }
.image-card[data-state="failed"]     { border-color: rgba(239,68,68,0.55); }
.image-card[data-state="skipped"]    { border-color: rgba(245,158,11,0.45); }
.image-card[data-state="edited"]     { border-color: rgba(245,158,11,0.6); }
.image-card[data-state="embedded"]   { border-color: rgba(168,85,247,0.45); }

/* Card filename */
.card-name {
  padding: 5px 6px;
  font-size: 9.5px;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

@keyframes pulse-badge {
  0%,100% { opacity:1; }
  50%      { opacity:0.65; }
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  text-decoration: none;
  color: inherit;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled               { opacity: 0.38; cursor: not-allowed; }

.btn-primary { background: var(--accent-grad); color: #fff; border-color: transparent; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.15); }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-md); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-bright); }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-md); }
.btn-danger-ghost:hover:not(:disabled) { color: var(--red); border-color: var(--red); }

.btn-sm  { padding: 5px 10px; font-size: 11.5px; }
.btn-xs  { padding: 3px 8px;  font-size: 11px; }
.full-w  { width: 100%; justify-content: center; }

/* Active toggle */
.panel-toggle.active { background: var(--bg-elevated); color: var(--accent); border-color: var(--border-bright); }

.btn-icon { font-size: 13px; line-height:1; }

/* ── Form elements ───────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 5px;
}

.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.form-hint { font-weight: 400; text-transform: none; color: var(--text-muted); }

.form-input, .form-select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.form-sub-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.form-textarea { resize: vertical; min-height: 64px; }
.form-select   { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a6380'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.form-sep { color: var(--text-muted); flex-shrink: 0; }

.input-row { display: flex; align-items: center; gap: 8px; }
.gap-sm    { gap: 6px; }

.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.check-col  { display: flex; flex-direction: column; gap: 6px; }

.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  transition: background 0.12s, border-color 0.12s;
}
.check-item:hover { background: var(--bg-elevated); border-color: var(--border-md); }
.check-item input { accent-color: var(--accent); cursor: pointer; }

.divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── Model list ──────────────────────────────────────────────────────────────── */
.model-list-wrap {
  margin-top: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}

.model-list { padding: 4px; display: flex; flex-direction: column; gap: 3px; }

.model-list-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11.5px;
}

.model-token {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: grab;
  user-select: none;
  transition: background 0.12s;
}
.model-token:hover { background: var(--bg-hover); border-color: var(--border-md); }
.model-token.sortable-ghost { opacity: 0.4; }
.model-token.sortable-drag  { opacity: 0; }

.model-rank   { font-size:10px; font-weight:700; color:var(--text-muted); min-width:18px; text-align:center; }
.model-grip   { color:var(--text-muted); font-size:13px; }
.model-name   { flex:1; font-size:11.5px; color:var(--accent); }
.model-remove {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px; border-radius: 3px;
  transition: color 0.12s, background 0.12s;
}
.model-remove:hover { color: var(--red); background: rgba(239,68,68,0.12); }

/* ── Keyword pills ───────────────────────────────────────────────────────────── */
.kw-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 32px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
}

.kw-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-hover);
  border: 1px solid var(--border-md);
  border-radius: 20px;
  font-size: 11.5px;
  color: var(--text-primary);
  cursor: grab;
  user-select: none;
  transition: background 0.12s;
}
.kw-pill:hover    { background: var(--accent); border-color: var(--accent); }
.kw-pill.sortable-ghost { opacity: 0.35; }

.kw-remove {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 0; margin-left: 2px;
  transition: color 0.12s;
}
.kw-remove:hover { color: var(--red); }

.kw-count-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-md);
  color: var(--text-secondary);
}
.kw-count-badge.warn  { background: rgba(239,68,68,0.15); color: var(--red); border-color: var(--red); }
.kw-count-badge.ok    { background: rgba(34,197,94,0.12);  color: var(--green); border-color: var(--green); }

/* ── Metadata panel specifics ────────────────────────────────────────────────── */
.filename-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 16px;
  color: var(--text-muted);
  text-align: center;
  font-size: 12.5px;
}
.meta-empty-icon { font-size: 36px; opacity: 0.4; }

.meta-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Drop zone overlay ───────────────────────────────────────────────────────── */
.drop-zone-overlay {
  position: absolute;
  inset: 0;
  background: rgba(99,102,241,0.12);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}
.drop-zone-inner { text-align: center; }
.drop-zone-icon  { font-size: 52px; }
.drop-zone-text  { font-size: 18px; font-weight: 600; color: var(--accent); margin-top: 8px; }

/* ── Logs panel ──────────────────────────────────────────────────────────────── */
#logs-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--logs-h);
  background: rgba(13,16,30,0.96);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 98;
  transition: transform 0.25s ease;
}

#logs-panel.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#logs-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px;
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.log-entry { padding: 1px 0; }
.log-entry .ts { color: var(--text-muted); margin-right: 6px; }
.log-entry.err  { color: #f87171; }
.log-entry.ok   { color: #4ade80; }
.log-entry.info { color: var(--blue); }

/* ── Toast notifications ─────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.2s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }
.toast.info    { border-color: var(--accent); }

@keyframes toast-in {
  from { opacity:0; transform: translateX(20px); }
  to   { opacity:1; transform: translateX(0); }
}

/* ── Upload progress overlay ─────────────────────────────────────────────────── */
#upload-progress {
  position: fixed;
  bottom: 60px;
  right: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  display: none;
  z-index: 150;
  min-width: 200px;
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Glow pulse for processing state */
@keyframes glow-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(59,130,246,0); }
  50%      { box-shadow: 0 0 12px 3px rgba(59,130,246,0.35); }
}
.image-card[data-state="processing"] { animation: glow-pulse 2s ease infinite; }

/* ── Google Auth Overlay & User Badge ────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(10, 13, 20, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
#login-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}
.login-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: 20px;
  padding: 40px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65), 0 0 40px rgba(59, 130, 246, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.login-logo-icon {
  font-size: 42px;
  background: linear-gradient(135deg, #60a5fa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 12px rgba(96, 165, 250, 0.3));
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}
.google-signin-btn-wrap {
  min-height: 44px;
  display: flex;
  justify-content: center;
  margin: 8px 0;
}
.login-footer {
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 16px;
  width: 100%;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px 3px 4px;
  font-size: 12px;
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.user-profile-badge:hover {
  border-color: var(--border-md);
}
.user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}
.user-name {
  font-weight: 500;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 50%;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-logout:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* ── Mobile Responsiveness ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Convert body to flex to easily handle dynamic toolbar height */
  body {
    display: flex;
    flex-direction: column;
  }

  /* Toolbar: stacked into 3 rows */
  #toolbar {
    position: sticky;
    top: 0;
    z-index: 1000 !important;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 10px;
    gap: 12px;
    overflow: visible;
  }
  
  .toolbar-left, .toolbar-center, .toolbar-right {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    flex-shrink: 0;
  }
  
  .toolbar-right {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    flex-direction: column;
    gap: 10px;
  }
  .panel-toggles-wrap {
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
  }
  .user-profile-badge {
    width: 100%;
    justify-content: center;
    padding: 6px 12px;
  }
  .user-name {
    display: inline-block !important;
    max-width: 200px;
  }

  .toolbar-sep {
    display: none;
  }
  
  /* Restore button text and logo */
  .toolbar-center .btn {
    font-size: 11.5px; 
    padding: 6px 12px;
    gap: 5px;
  }
  .toolbar-center .btn > * {
    font-size: 13px;
  }
  .logo-text, .logo-badge { display: inline-block; }

  /* Statusbar adjustments */
  #statusbar {
    position: relative;
    top: auto;
    height: auto;
    min-height: var(--statusbar-h);
    padding: 8px 10px;
  }
  #progress-bar { width: 100px; }
  #status-text { font-size: 10.5px; }
  
  /* Main layout fills remaining space */
  #main-layout {
    position: relative;
    top: auto;
    bottom: auto;
    flex: 1;
  }
  
  /* Side panels become sliding overlays */
  .side-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 100;
    width: 85%;
    max-width: 320px;
    height: 100%;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
  }
  
  #settings-panel { left: 0; transform: translateX(0); }
  #settings-panel.collapsed { transform: translateX(-110%); width: 85%; opacity: 0; }
  
  #metadata-panel { right: 0; transform: translateX(0); border-left: 1px solid var(--border); }
  #metadata-panel.collapsed { transform: translateX(110%); width: 85%; opacity: 0; }
  
  /* Adjust center grid */
  #image-grid { justify-content: center; padding: 10px; }
  .image-card { width: calc(50% - 10px); min-width: 140px; }
  .card-thumb, .card-thumb-placeholder { height: 110px; }
  
  .grid-empty { padding: 40px 10px; }
}

@media (max-width: 480px) {
  .image-card { width: 100%; min-width: unset; }
  .card-thumb, .card-thumb-placeholder { height: 180px; }
  .user-profile-badge { padding: 4px 10px; gap: 6px; }
}
