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

:root {
  --bg: #f2f2f7;
  --bg-elevated: #e8e8ed;
  --surface: #ffffff;
  --surface-2: #f9f9fb;
  --surface-3: #f4f4f6;
  --surface-hover: rgba(0,0,0,0.028);
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.12);
  --border-light: rgba(0,0,0,0.04);
  --text: #1a1a1f;
  --text-2: #64647a;
  --text-3: #9d9dab;
  --primary: #6366f1;
  --primary-hover: #5558e6;
  --primary-light: #818cf8;
  --primary-bg: rgba(99,102,241,0.07);
  --primary-ring: rgba(99,102,241,0.18);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,0.07);
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.03), 0 1px 1px rgba(0,0,0,0.02);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 2px 6px rgba(0,0,0,0.03);
  --shadow: 0 2px 8px rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 16px 48px rgba(0,0,0,0.06);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.12), 0 24px 64px rgba(0,0,0,0.08);
  --transition: 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-fast: 0.12s cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #f0f2f8;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.admin-gate-active {
  min-height: 100dvh;
  overflow: hidden;
}

.app-shell.hidden,
.admin-gate-shell.hidden {
  display: none;
}

html[data-admin-session="active"] .admin-gate-shell {
  display: none;
}

html[data-admin-session="active"] .app-shell.hidden {
  display: block;
}

/* ── Admin Gate (Login Page Redesign) ── */
.admin-gate-shell {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: #f0f2f8;
  overflow: hidden;
}

/* Animated gradient blobs */
.gate-bg-blobs {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.gate-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: gate-blob-float 18s ease-in-out infinite alternate;
}

.gate-blob-1 {
  width: 420px; height: 420px;
  background: radial-gradient(circle, #6366f1, #818cf8);
  top: -8%; left: -6%;
  animation-delay: 0s;
}

.gate-blob-2 {
  width: 360px; height: 360px;
  background: radial-gradient(circle, #3b82f6, #60a5fa);
  top: 55%; right: -4%;
  animation-delay: -6s;
  animation-duration: 22s;
}

.gate-blob-3 {
  width: 280px; height: 280px;
  background: radial-gradient(circle, #2dd4bf, #5eead4);
  bottom: -10%; left: 35%;
  animation-delay: -12s;
  animation-duration: 20s;
}

@keyframes gate-blob-float {
  0%   { transform: translate(0, 0) scale(1); }
  33%  { transform: translate(30px, -20px) scale(1.06); }
  66%  { transform: translate(-20px, 15px) scale(0.95); }
  100% { transform: translate(10px, -10px) scale(1.02); }
}

/* Card container */
.admin-gate-card {
  position: relative;
  display: flex;
  width: min(460px, 100%);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.06), 0 2px 12px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  overflow: hidden;
  animation: gate-card-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  z-index: 1;
}

@keyframes gate-card-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Left gradient accent strip */
.gate-accent {
  flex: 0 0 6px;
  background: linear-gradient(180deg, #6366f1, #3b82f6, #06b6d4);
  border-radius: 24px 0 0 24px;
}

/* Main body */
.gate-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 40px 36px 32px;
}

/* Brand / Logo area */
.gate-brand {
  text-align: center;
  margin-bottom: 32px;
}

.gate-logo-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px; height: 72px;
  border-radius: 22px;
  background: linear-gradient(135deg, #ede9fe, #dbeafe, #e0f2fe);
  margin-bottom: 16px;
  animation: gate-logo-glow 3s ease-in-out infinite alternate;
}

@keyframes gate-logo-glow {
  from { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
  to   { box-shadow: 0 0 20px 4px rgba(99, 102, 241, 0.15); }
}

.gate-logo {
  font-size: 2.2rem;
  line-height: 1;
}

.gate-brand h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #4338ca, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gate-subtitle {
  color: var(--text-2);
  font-size: 0.88rem;
  font-weight: 500;
  margin: 0;
}

/* Form area */
.gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gate-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--text-2);
}

.gate-label svg {
  color: var(--text-3);
  flex-shrink: 0;
}

.gate-input-wrap {
  position: relative;
}

.gate-input-wrap input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.gate-input-wrap input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12), 0 0 16px rgba(99, 102, 241, 0.08);
}

.gate-input-wrap input::placeholder {
  color: var(--text-3);
  font-size: 0.88rem;
}

/* Login button */
.gate-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  margin-top: 4px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: #fff;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.gate-login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4);
}

.gate-login-btn:active {
  transform: translateY(0) scale(0.98);
}

.gate-login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.gate-login-btn svg {
  transition: transform 0.2s;
}

.gate-login-btn:hover svg {
  transform: translateX(3px);
}

/* Status message */
.gate-status {
  text-align: center;
  min-height: 1.4em;
  color: var(--text-3);
  font-size: 0.8rem;
  margin: 0;
  transition: color 0.2s;
}

.gate-status.error {
  color: var(--danger);
}

/* Footer hint */
.gate-hint {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  text-align: center;
  color: var(--text-3);
  font-size: 0.74rem;
  line-height: 1.6;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.topbar-left,
.topbar-right { min-width: 0; }

.topbar-left {
  flex: 1 1 auto;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.logo span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.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;
}

.topbar-btn {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--text-3);
  cursor: pointer;
  transition: var(--transition-fast);
}

.topbar-btn:hover { background: rgba(0,0,0,0.05); color: var(--text); }
.topbar-btn:active { transform: scale(0.92); }

.admin-logout-top:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.06);
}

/* ── Overlay & Modal ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  animation: overlayIn 0.2s ease;
}

.overlay.hidden { display: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 90%;
  max-width: 480px;
  max-height: min(85vh, calc(100dvh - 24px));
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 0;
}

.modal-header h2 {
  font-size: 1.12rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.close-btn {
  width: 30px; height: 30px;
  border: none;
  background: var(--surface-3);
  border-radius: 50%;
  font-size: 1.1rem;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.close-btn:hover { background: var(--bg-elevated); color: var(--text); }
.close-btn:active { transform: scale(0.9); }

.modal-body { padding: 20px 24px 24px; }

.form-section { margin-bottom: 24px; }
.form-section h3 {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 14px;
}

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text);
}

.form-group small, .section-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.45;
}

input[type="url"], input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--primary-ring);
}

textarea { resize: vertical; }

.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; }

.icon-btn-sm {
  width: 38px; height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  flex-shrink: 0;
}

.icon-btn-sm:hover { background: var(--surface-3); color: var(--text); }
.icon-btn-sm:active { transform: scale(0.94); }

/* ── Switch ── */
.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 0.88rem;
  cursor: pointer;
}

.switch-label input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 46px; height: 26px;
  background: var(--bg-elevated);
  border-radius: 13px;
  transition: var(--transition);
  flex-shrink: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  background: white;
  border-radius: 50%;
  transition: var(--transition-spring);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15), 0 0 1px rgba(0,0,0,0.1);
}

.switch-label input:checked + .switch { background: linear-gradient(135deg, #6366f1, #3b82f6); }
.switch-label input:checked + .switch::after { left: 22px; }
.switch-label input:focus-visible + .switch {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.stream-mode-section.hidden,
.oauth-flow-info.hidden { display: none; }

.oauth-flow-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px;
  margin-top: 4px;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  background: #f0f9ff;
  color: #075985;
  font-size: 0.78rem;
  line-height: 1.55;
}

.oauth-flow-info strong {
  font-size: 0.82rem;
  color: #0c4a6e;
}

/* ── Buttons ── */
.btn {
  padding: 9px 20px;
  border: none;
  border-radius: 980px;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.005em;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover { background: linear-gradient(135deg, #5558e6, #2563eb); box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35), inset 0 1px 0 rgba(255,255,255,0.15); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.btn-outline:hover { background: var(--primary-bg); border-color: rgba(99, 102, 241, 0.4); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 8px 14px;
}

.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 1;
}

.toolbar-right .hint {
  min-width: 0;
  max-width: min(42vw, 360px);
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
  text-align: right;
}

.active-job-banner {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 180;
  width: min(680px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 8px 9px 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 14px 40px rgba(15,23,42,0.14), 0 3px 10px rgba(15,23,42,0.08);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  transform: translateX(-50%);
  animation: activeJobPillIn 0.26s cubic-bezier(0.25, 0.1, 0.25, 1);
}

@supports (padding: env(safe-area-inset-bottom)) {
  .active-job-banner {
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@keyframes activeJobPillIn {
  from { opacity: 0; transform: translate(-50%, 8px) scale(0.98); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.active-job-banner.hidden { display: none; }

.active-job-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-bg);
  flex: 0 0 auto;
  animation: activeJobDotPulse 1.6s ease-in-out infinite;
}

@keyframes activeJobDotPulse {
  0%, 100% { opacity: 0.72; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1.08); }
}

.active-job-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.active-job-title {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
}

.active-job-meta {
  min-width: 0;
  font-size: 0.74rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.active-job-meta::before {
  content: '·';
  margin-right: 8px;
  color: var(--text-3);
}

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

.active-job-actions .btn {
  height: 30px;
  min-width: 52px;
  padding: 0 12px;
  font-size: 0.74rem;
  border-radius: 999px;
  justify-content: center;
  transition: all var(--transition-fast);
}

.active-job-actions .active-job-view {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.active-job-actions .active-job-view:hover {
  background: rgba(99,102,241,0.12);
}

.active-job-actions .active-job-stop {
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.2);
  color: var(--danger);
}

.active-job-actions .active-job-stop:hover {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.28);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 8px;
}



/* ── Generation Progress Dialog ── */
.generation-progress-dialog {
  width: min(92vw, 420px);
  max-width: 420px;
  overflow: hidden;
  border: 1px solid rgba(99,102,241,0.12);
  box-shadow: 0 24px 70px rgba(15,23,42,0.22), 0 8px 24px rgba(99,102,241,0.12);
}

.generation-progress-body {
  padding: 22px;
}

.generation-image-skeleton {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(99,102,241,0.14), rgba(59,130,246,0.08));
  border: 1px solid rgba(99,102,241,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}

.generation-image-skeleton::before {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  animation: generationSkeletonSweep 1.7s ease-in-out infinite;
}

.generation-image-outline {
  position: absolute;
  inset: 18px;
  border-radius: 16px;
  border: 1px solid rgba(79,70,229,0.18);
  background: linear-gradient(180deg, rgba(255,255,255,0.56), rgba(255,255,255,0.22));
}

.generation-skeleton-sun {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(251,191,36,0.5);
  box-shadow: 0 0 30px rgba(251,191,36,0.35);
}

.generation-skeleton-mountain {
  position: absolute;
  bottom: 18px;
  width: 58%;
  height: 42%;
  border-radius: 18px 18px 10px 10px;
  background: linear-gradient(135deg, rgba(99,102,241,0.45), rgba(37,99,235,0.22));
  clip-path: polygon(0 100%, 44% 20%, 100% 100%);
}

.generation-skeleton-mountain-a { left: 10px; }
.generation-skeleton-mountain-b {
  right: 6px;
  width: 48%;
  opacity: 0.72;
}

@keyframes generationSkeletonSweep {
  0% { transform: translateX(-100%); }
  55%, 100% { transform: translateX(100%); }
}

.generation-progress-copy {
  margin-top: 18px;
  text-align: center;
}

.generation-progress-eyebrow {
  margin: 0 0 5px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.generation-progress-copy h2 {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
}

.generation-progress-meta {
  margin: 8px 0 0;
  color: var(--text-2);
  font-size: 0.86rem;
  line-height: 1.5;
}

.generation-progress-meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  font-size: 0.8rem;
  color: var(--text-3);
}

.generation-progress-percent {
  min-width: 4ch;
  text-align: right;
  font-weight: 750;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.generation-progress-bar {
  position: relative;
  height: 9px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(99,102,241,0.12);
}

.generation-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6366f1, #2563eb, #06b6d4);
  transition: width 0.32s ease;
}

.generation-progress-detail {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--text-3);
  font-size: 0.74rem;
  line-height: 1.4;
  text-align: center;
}

.generation-progress-actions {
  margin-top: 18px;
  justify-content: center;
}

.generation-progress-actions .danger {
  color: var(--danger);
  border-color: rgba(239,68,68,0.24);
  background: rgba(239,68,68,0.06);
}

/* ── Toast ── */
.toast {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.4;
}

.toast.hidden { display: none; }
.toast.success { background: rgba(34,197,94,0.08); color: #15803d; border: 1px solid rgba(34,197,94,0.15); }
.toast.error { background: rgba(239,68,68,0.06); color: #b91c1c; border: 1px solid rgba(239,68,68,0.12); }

/* ── Main Layout ── */
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Hero Section ── */
.hero-section {
  padding: 16px 0 12px;
  text-align: center;
}

.hero-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #4338ca, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-desc {
  margin: 0;
  color: var(--text-3);
  font-size: 0.84rem;
}

/* ── Input Section ── */
.input-section {
  position: relative;
}

.input-section::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 2px;
  background: linear-gradient(180deg, #6366f1, #3b82f6);
  opacity: 0.5;
}

/* ── Controls Section ── */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Results Section ── */
.results-section {
  margin-top: 24px;
}

/* ── Input Card ── */
.input-card {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  padding: 16px 16px 16px 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.input-card:focus-within {
  border-color: rgba(99,102,241,0.35);
  box-shadow: 0 0 0 3.5px var(--primary-ring), 0 0 20px rgba(99,102,241,0.05), var(--shadow-sm);
}

.input-card textarea {
  border: none;
  padding: 4px 2px;
  font-size: 0.95rem;
  min-height: 64px;
  line-height: 1.6;
  background: transparent;
}

.input-card textarea:focus { box-shadow: none; }

.input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.toolbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.prompt-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.hint {
  font-size: 0.72rem;
  color: var(--text-3);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: var(--transition-fast);
  font: inherit;
}

.tool-btn:hover { background: var(--surface-3); color: var(--primary); }
.tool-btn:active { transform: scale(0.9); }

.enhance-prompt-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-2);
  box-shadow: none;
}
.enhance-prompt-btn.hidden { display: none; }
.enhance-prompt-btn:hover { background: var(--surface-3); color: var(--primary); }
.enhance-prompt-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.enhance-label,
.enhance-label.hidden,
.enhance-loading.hidden,
.enhance-icon.hidden { display: none; }
.enhance-prompt-btn .spinner {
  width: 16px; height: 16px;
  border-color: rgba(99,102,241,0.18);
  border-top-color: var(--primary);
}

.ref-preview-list {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ref-preview-list.hidden { display: none; }
.ref-preview-item { position: relative; display: inline-flex; }
.ref-preview-item img {
  height: 36px; width: 36px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

.ref-remove {
  position: absolute; top: -5px; right: -5px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--danger); color: white;
  border: none; font-size: 0.6rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: var(--transition-fast);
}
.ref-remove:hover { transform: scale(1.15); }

.btn-send {
  width: 82px;
  min-width: 82px;
  height: 36px;
  padding: 0 18px;
  border-radius: 980px;
  font-size: 0.88rem;
  font-weight: 550;
  justify-content: center;
  flex-shrink: 0;
}

.btn-text.hidden,
.btn-loading.hidden { display: none; }

.btn-loading {
  display: inline-flex;
  align-items: center;
  min-width: 28px;
  justify-content: center;
}

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Options Bar ── */
.options-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

.opt { display: flex; flex-direction: column; gap: 5px; }

.opt > label {
  font-size: 0.66rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.opt select {
  width: auto;
  min-width: 90px;
  padding: 5px 8px;
  font-size: 0.8rem;
  border-radius: var(--radius-xs);
}

.opt-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Custom Select ── */
.custom-select { position: relative; }

.cs-trigger {
  width: auto;
  min-width: 90px;
  padding: 5px 26px 5px 10px;
  font-size: 0.8rem;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%239d9dab' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
  outline: none;
  white-space: nowrap;
}

.cs-trigger:focus, .cs-trigger:hover { border-color: var(--primary); }

.cs-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  animation: dropdownIn 0.15s cubic-bezier(0.25, 0.1, 0.25, 1);
  overflow: hidden;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.cs-dropdown.hidden { display: none; }

.cs-item {
  padding: 8px 14px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition-fast);
  white-space: nowrap;
}

.cs-item:hover { background: var(--primary-bg); color: var(--primary); }
.cs-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 550; }

.cs-divider {
  height: 1px;
  background: var(--border-light);
  margin: 3px 0;
}

/* ── Segmented Control ── */
.seg {
  display: inline-flex;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
  padding: 2.5px;
  position: relative;
}

.seg button {
  padding: 5px 14px;
  border: none;
  background: transparent;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 450;
  color: var(--text-2);
  cursor: pointer;
  border-radius: 5px;
  transition: var(--transition);
  position: relative;
  z-index: 1;
}

.seg button.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 0.5px 1px rgba(0,0,0,0.04);
}

.seg button:not(.active):hover { color: var(--text); }

/* ── Advanced Panel ── */
.advanced-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.advanced-panel summary {
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}

.advanced-panel summary:hover { color: var(--text); }

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px 14px;
}

.adv-group { display: flex; flex-direction: column; gap: 4px; }

.adv-group label {
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.adv-group select {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: var(--radius-xs);
}

/* ── History Toolbar ── */
.history-toolbar {
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.history-search,
.history-toolbar input[type="search"] {
  flex: 1 1 160px;
  min-width: 120px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
}

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

.history-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  font-size: 0.74rem;
  border-radius: 980px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  transition: all var(--transition);
}

.history-actions .btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.history-actions .btn svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.history-actions .btn:hover svg { transform: rotate(20deg); }

.history-fav-btn.active {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #b45309;
}

.history-fav-btn.active svg { fill: #f59e0b; stroke: #f59e0b; }

.history-status {
  display: inline-flex;
  align-items: center;
  color: var(--text-3);
  font-size: 0.76rem;
}

.history-status.error { color: var(--danger); }

/* ── Prompt History ── */
.prompt-history-panel {
  margin: 0 16px 14px;
  padding: 10px 12px;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
}

.prompt-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.prompt-history-header h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
}

.prompt-history-header p {
  display: none;
}

.prompt-history-header .btn {
  padding: 3px 10px;
  font-size: 0.7rem;
  border-radius: 980px;
}

.prompt-history-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.prompt-history-row label {
  display: none;
}

.prompt-history-row select {
  min-width: 0;
  flex: 1 1 180px;
  padding: 6px 8px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
}

.prompt-history-row .btn {
  padding: 4px 10px;
  font-size: 0.7rem;
  border-radius: 980px;
}

.prompt-history-row .btn.danger {
  margin-left: auto;
}

.prompt-history-status {
  min-height: 0;
  margin-top: 6px;
  color: var(--text-3);
  font-size: 0.72rem;
}

.prompt-history-status:empty { display: none; }

.prompt-history-status.error { color: var(--danger); }

/* ── Gallery ── */
.gallery {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.gallery-card {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  animation: cardIn 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.gallery-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

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

.gallery-card .img-wrap {
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.gallery-card img {
  width: 100%;
  display: block;
  transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.gallery-card:hover img { transform: scale(1.03); }

.gallery-card .card-bar {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-bar .btn { padding: 5px 14px; font-size: 0.78rem; border-radius: var(--radius-xs); }

.card-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.card-actions .favorite-btn {
  min-width: 32px;
  padding-inline: 9px;
  color: var(--text-3);
  transition: var(--transition-fast);
}

.card-actions .favorite-btn.active {
  color: #b45309;
  background: #fffbeb;
  border-color: #fcd34d;
}

.card-actions .card-delete-btn { color: var(--danger); }

.card-actions .history-regenerate-btn,
.card-actions .history-reference-btn,
.card-actions .history-copy-btn {
  padding-inline: 10px;
}

.card-meta {
  min-width: 0;
  color: var(--text-3);
  font-size: 0.74rem;
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card-prompt,
.card-tags {
  padding: 0 12px;
  color: var(--text-3);
  font-size: 0.76rem;
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card-prompt { margin-top: 8px; color: var(--text-2); }
.card-tags { margin-top: 4px; }

.gallery-card-error {
  border-color: rgba(239,68,68,0.2);
  background: rgba(239,68,68,0.02);
}

.result-error-body {
  min-height: 140px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #b91c1c;
  font-size: 0.86rem;
  line-height: 1.5;
}

/* ── Error Bar ── */
.error-bar {
  margin-top: 14px;
  padding: 12px 16px;
  background: rgba(239,68,68,0.05);
  color: #b91c1c;
  border: 1px solid rgba(239,68,68,0.15);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  word-break: break-word;
}

.error-bar.hidden { display: none; }

/* ── Error Dialog ── */
.error-dialog { max-width: 430px; overflow: hidden; }
.error-dialog-header { padding-bottom: 0; }

.error-dialog-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.error-dialog-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(239,68,68,0.08);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.15);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
}

.error-dialog-body { padding-top: 14px; }

.error-dialog-summary {
  color: var(--text-2);
  font-size: 0.86rem;
  margin-bottom: 12px;
}

.error-dialog-message {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239,68,68,0.15);
  background: rgba(239,68,68,0.04);
  color: #991b1b;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 34vh;
  overflow-y: auto;
}

.error-dialog-actions {
  padding: 14px 0 0;
  justify-content: flex-end;
}

.error-dialog-kind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.error-dialog-kind {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1;
}

.error-dialog-kind[data-tone="danger"] {
  background: rgba(239,68,68,0.1);
  color: #dc2626;
}
.error-dialog-kind[data-tone="warning"] {
  background: rgba(245,158,11,0.1);
  color: #b45309;
}
.error-dialog-kind[data-tone="info"] {
  background: rgba(0,102,230,0.08);
  color: #1d4ed8;
}

.error-dialog-meta {
  font-size: 0.78rem;
  color: var(--text-3);
}
.error-dialog-meta.hidden { display: none; }

.error-dialog-suggestion {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.82rem;
  line-height: 1.55;
}

.error-dialog-debug {
  margin-top: 12px;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.error-dialog-debug summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 0.8rem;
}

.error-dialog-debug-text {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #dbeafe;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayIn 0.2s ease;
}

.lightbox.hidden { display: none; }

.lightbox img {
  max-width: 94vw;
  max-height: 94vh;
  border-radius: 10px;
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.lightbox-close {
  position: absolute;
  top: 16px; right: 20px;
  width: 40px; height: 40px;
  border: none;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.lightbox-close:hover { background: rgba(255,255,255,0.25); }
.lightbox-close:active { transform: scale(0.9); }

/* ── Checkerboard ── */
.checkerboard {
  background-image:
    linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
    linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
    linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ── Account Switcher ── */
.account-switcher {
  position: relative;
  min-width: 0;
}

.switcher-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  max-width: 180px;
}

.switcher-btn:hover { border-color: var(--border); background: rgba(0,0,0,0.02); color: var(--text); }
.switcher-btn:active { transform: scale(0.97); }

.switcher-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.switcher-dot.inactive { background: var(--text-3); }
.switcher-dot.expired { background: var(--danger); }

.switcher-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switcher-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  animation: dropdownIn 0.15s cubic-bezier(0.25, 0.1, 0.25, 1);
  overflow: hidden;
}

.switcher-dropdown.hidden { display: none; }

.dropdown-list { max-height: 240px; overflow-y: auto; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-align: left;
}

.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.active { background: var(--primary-bg); }

.dropdown-item:focus-visible,
.btn:focus-visible,
.topbar-btn:focus-visible,
.tool-btn:focus-visible,
.seg button:focus-visible,
.icon-btn-sm:focus-visible,
.switcher-btn:focus-visible,
.cs-trigger:focus-visible,
.cs-item:focus-visible,
.account-card:focus-visible,
.gallery-card img[role="button"]:focus-visible {
  outline: 2.5px solid var(--primary);
  outline-offset: 2px;
}

.dropdown-item .item-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.dropdown-item.active .item-dot { background: var(--primary); }

.dropdown-item .item-info {
  flex: 1;
  overflow: hidden;
}

.dropdown-item .item-name {
  display: block;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-item .item-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-item .item-badge {
  font-size: 0.65rem;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-3);
  flex-shrink: 0;
  font-weight: 500;
}

.dropdown-item .item-badge.oauth { background: rgba(34,197,94,0.08); color: #15803d; }

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
}

.dropdown-manage {
  color: var(--text-2);
  font-size: 0.8rem;
}

.dropdown-manage svg { color: var(--text-3); }

/* ── Settings Modal ── */

.modal-settings {
  width: min(940px, 96vw);
  max-height: min(680px, 85vh);
  display: flex;
  flex-direction: column;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.settings-body::-webkit-scrollbar { width: 4px; }
.settings-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.settings-center-modal .modal-header {
  align-items: flex-start;
  gap: 16px;
}

.modal-subtitle {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-3);
  line-height: 1.45;
}

.settings-center-shell {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.settings-center-nav {
  position: sticky;
  top: 0;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.settings-nav-item {
  width: 100%;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-2);
  padding: 9px 10px;
  text-align: left;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.settings-nav-item.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.settings-nav-item:focus-visible,
.quick-start-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.settings-center-panels {
  min-width: 0;
}

.settings-panel {
  display: grid;
  gap: 14px;
}

.settings-panel.hidden { display: none; }

.settings-panel-head,
.settings-hero,
.settings-note-card {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.settings-panel-head,
.settings-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.settings-panel-head h3,
.settings-hero h3 {
  font-size: 0.95rem;
  line-height: 1.25;
  margin-bottom: 4px;
}

.settings-panel-head p,
.settings-hero p,
.settings-note-card span {
  font-size: 0.76rem;
  color: var(--text-3);
  line-height: 1.5;
}

.settings-kicker {
  margin-bottom: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.settings-status-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.7rem;
  font-weight: 600;
}

.quick-start-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-start-card {
  display: grid;
  gap: 5px;
  min-height: 88px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.quick-start-card:hover {
  transform: translateY(-1px);
  border-color: var(--primary-light);
  background: var(--surface-hover);
}

.quick-start-card strong {
  font-size: 0.86rem;
}

.quick-start-card span {
  color: var(--text-3);
  font-size: 0.75rem;
  line-height: 1.45;
}

.settings-note-card {
  display: grid;
  gap: 4px;
}

.settings-note-card strong {
  font-size: 0.82rem;
}

.settings-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-section:last-child { border-bottom: none; }

.settings-section h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  letter-spacing: -0.01em;
}

.settings-section p {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.45;
}

.settings-grid {
  display: grid;
  gap: 12px;
}

.settings-grid .form-group { margin-bottom: 0; }

.settings-grid label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.settings-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}

.settings-inline label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}

.settings-inline-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.settings-inline-check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  transition: background var(--transition-fast);
}

.settings-inline-check-grid label:hover { background: var(--surface-hover); }

.settings-inline-check-grid input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  border-radius: 4px;
  flex-shrink: 0;
}

.switch-label.compact {
  font-size: 0.78rem;
  padding: 6px 0;
}

.switch-label.compact .switch { transform: scale(0.88); }

/* ── Backup / Storage / Watermark ── */

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.backup-preview {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-2);
  max-height: 120px;
  overflow-y: auto;
  font-family: 'SF Mono', ui-monospace, monospace;
  line-height: 1.5;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-spring);
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-webkit-slider-thumb:active { transform: scale(0.95); }

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 2px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color var(--transition);
}

input[type="color"]:hover { border-color: var(--primary); }

.watermark-preview {
  margin-top: 12px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(15,23,42,0.92), rgba(51,65,85,0.72)),
    repeating-conic-gradient(rgba(255,255,255,0.18) 0% 25%, rgba(255,255,255,0.06) 0% 50%) 0 0 / 18px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(15,23,42,0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 108px;
  font-size: 0.85rem;
  color: #fff;
  overflow: hidden;
}

.storage-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.storage-stats .stat-item {
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  text-align: center;
}

.stat-item .stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.stat-item .stat-label {
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 2px;
}

.storage-diagnostics {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-2);
  line-height: 1.6;
}

.danger-zone {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(239,68,68,0.15);
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
}

.danger-zone h4 {
  font-size: 0.8rem;
  color: var(--danger);
  margin-bottom: 8px;
  font-weight: 600;
}

.danger-zone p {
  font-size: 0.75rem;
  color: var(--text-2);
  margin-bottom: 10px;
}

.prompt-enhancement-options {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.prompt-enhancement-options label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  transition: background var(--transition-fast);
}

.prompt-enhancement-options label:hover { background: var(--surface-hover); }

.modal-settings .modal-footer {
  position: sticky;
  bottom: 0;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  margin: 0 -20px -20px;
  background: var(--surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Account Management Modal ── */

.modal-lg {
  width: min(560px, 92vw);
  max-height: min(700px, 85vh);
  display: flex;
  flex-direction: column;
}

.modal-lg .modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
  -webkit-overflow-scrolling: touch;
}

.account-manager-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.account-tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin: 0 0 2px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: 999px;
}

.account-tab {
  min-width: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  padding: 8px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.account-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.account-tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.account-panel {
  display: grid;
  gap: 14px;
}

.account-panel.hidden { display: none; }

.account-panel-head,
.oauth-login-card,
.advanced-account-section,
.account-test-footer {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.account-panel-head,
.oauth-login-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.account-panel-head h3,
.oauth-login-card h3,
.advanced-account-section h3 {
  font-size: 0.9rem;
  line-height: 1.25;
  margin-bottom: 4px;
}

.account-panel-head p,
.oauth-login-card p {
  font-size: 0.76rem;
  color: var(--text-3);
  line-height: 1.5;
}

.oauth-login-copy { min-width: 0; }

.oauth-login-kicker {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7c3aed;
  margin-bottom: 4px;
}

.oauth-login-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 600;
}

.oauth-state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}

.oauth-login-state.busy .oauth-state-dot { background: var(--warning); }
.oauth-login-state.success .oauth-state-dot { background: var(--success); }
.oauth-login-state.expired .oauth-state-dot { background: var(--danger); }
.oauth-login-state.success,
.oauth-login-state.expired {
  color: var(--text);
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.btn-oauth {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-oauth:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-oauth svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.oauth-status {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.oauth-status.success {
  background: rgba(34,197,94,0.08);
  color: #15803d;
  border: 1px solid rgba(34,197,94,0.15);
}

.oauth-status.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.15);
}

.oauth-manual {
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.oauth-manual h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.account-list {
  display: grid;
  gap: 8px;
}

.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition);
}

.account-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.account-card.active {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.account-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.account-card.active .account-radio {
  border-color: var(--primary);
}

.account-card.active .account-radio::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.account-info {
  flex: 1;
  min-width: 0;
}

.account-info .account-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-info .account-detail {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-badge {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 5px;
  font-weight: 500;
  flex-shrink: 0;
}

.account-badge.oauth {
  background: rgba(34,197,94,0.08);
  color: #15803d;
}

.account-badge.manual {
  background: var(--surface-3);
  color: var(--text-3);
}

.account-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.account-card-actions .btn {
  padding: 4px 8px;
  font-size: 0.72rem;
}

.account-actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.account-subhead {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 8px;
}

.oauth-account-section {
  display: grid;
  gap: 8px;
}

.account-advanced-checks {
  align-items: flex-start;
  flex-direction: column;
}

.account-test-footer {
  display: grid;
  gap: 10px;
}

.account-migration-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.account-migration-actions .section-hint {
  flex: 1 1 220px;
}

.account-store-config-actions {
  align-items: center;
  flex-wrap: wrap;
}

.account-store-config-actions .section-hint {
  flex: 1 1 240px;
  margin-bottom: 0;
}

.global-settings {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}

.global-settings h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ── Edit Account Modal ── */

.edit-account-form {
  display: grid;
  gap: 14px;
}

.edit-account-form .form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* ── Form Group Wide ── */

.form-group.wide { grid-column: 1 / -1; }

/* ── Danger Modifier ── */

.btn-outline.danger,
.btn.danger {
  color: var(--danger);
  border-color: rgba(239,68,68,0.25);
}

.btn-outline.danger:hover,
.btn.danger:hover {
  background: var(--danger-bg);
}

/* ── Watermark Preview Lines ── */

.watermark-preview .wm-line {
  display: block;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9), 0 0 10px rgba(0,0,0,0.45);
}

.watermark-preview .wm-line.with-bg {
  background: rgba(0,0,0,0.34);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.watermark-preview .wm-line.with-shadow {
  text-shadow: 0 1px 2px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.55);
}

.watermark-preview .wm-line.small {
  font-size: 0.72rem;
  font-weight: 500;
  opacity: 0.82;
  margin-top: 6px;
}

/* ── OAuth Manual Flow ── */

.oauth-manual-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.oauth-manual-desc {
  font-size: 0.78rem;
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: 10px;
}

.oauth-manual-desc.oauth-manual-step2 {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.oauth-manual-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

/* ── Section Hint ── */

.section-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-3);
  line-height: 1.45;
  margin-bottom: 10px;
}

/* ── Account Empty ── */

.account-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-3);
  font-size: 0.82rem;
}

/* ── Badge ── */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 5px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-3);
}

.badge-expired {
  background: rgba(245,158,11,0.08);
  color: #b45309;
}

/* ── Route Mode Info ── */

.route-mode-info {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.route-mode-info.responses {
  background: var(--primary-bg);
  color: var(--primary);
}

.route-mode-info.images {
  background: rgba(34,197,94,0.08);
  color: #15803d;
}

.route-mode-info.oauth {
  background: rgba(168,85,247,0.08);
  color: #7c3aed;
}

.route-mode-info.muted {
  background: var(--surface-3);
  color: var(--text-3);
}

/* ── Storage Diagnostics Detail ── */

.storage-diagnostics-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.storage-diagnostics-list {
  display: grid;
  gap: 4px;
}

.storage-diagnostics-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.75rem;
}

.storage-diagnostics-label {
  color: var(--text-2);
}

.storage-diagnostics-value {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ── Stream Mode Section ── */

.stream-mode-section {
  padding: 8px 0;
}

.stream-mode-section + .stream-mode-section {
  border-top: 1px solid var(--border-light);
}

/* ── OAuth Flow Info ── */

.oauth-flow-info {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(168,85,247,0.06);
  border: 1px solid rgba(168,85,247,0.12);
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 8px;
}

.oauth-flow-info strong {
  display: block;
  color: #7c3aed;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.oauth-flow-info span {
  line-height: 1.45;
}

/* ── Responsive: Settings Modal (≤640px) ── */

@media (max-width: 640px) {
  .admin-gate-shell {
    padding: 18px;
    align-items: start;
    padding-top: max(40px, env(safe-area-inset-top));
  }
  .admin-gate-card {
    border-radius: 20px;
  }
  .gate-body {
    padding: 32px 24px 28px;
  }
  .gate-logo-ring {
    width: 60px; height: 60px;
  }
  .gate-logo { font-size: 1.8rem; }
  .gate-brand h1 { font-size: 1.35rem; }
  .modal-settings { max-width: 96vw; }
  .modal-settings .modal-body { padding: 12px 14px 16px; }
  .settings-center-shell { grid-template-columns: 1fr; gap: 12px; }
  .settings-center-nav {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: var(--radius-sm);
  }
  .settings-nav-item { text-align: center; }
  .settings-panel-head,
  .settings-hero { flex-direction: column; }
  .settings-status-pill { align-self: flex-start; }
  .quick-start-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .form-group.wide { grid-column: auto; }
  .settings-section { padding: 14px; }
  .danger-zone .btn { width: 100%; justify-content: center; }
  .modal-settings .modal-footer { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); margin: 0 -14px -16px; }
  .modal-lg { width: 96vw; }
  .modal-lg .modal-body { padding: 0 14px 16px; }
  .account-tabs { grid-template-columns: 1fr; border-radius: var(--radius-sm); }
  .account-tab { text-align: center; }
  .account-panel-head,
  .oauth-login-card { flex-direction: column; align-items: stretch; }
  .account-panel-head .btn,
  .oauth-login-card .btn { justify-content: center; width: 100%; }
  .oauth-manual-actions { flex-direction: column; }
}

/* ── Responsive: Mobile (≤600px) ── */

@media (max-width: 600px) {
  .topbar { padding: 0 14px; gap: 6px; }
  .logo span { display: none; }
  .switcher-btn { max-width: 120px; padding: 6px 10px; }

  .main { padding: 16px 10px calc(60px + env(safe-area-inset-bottom)); }

  .input-card { scroll-margin-bottom: 24dvh; }

  .input-toolbar {
    align-items: center;
    flex-direction: row;
    gap: 8px;
  }

  .toolbar-left {
    width: auto;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .toolbar-left::-webkit-scrollbar { display: none; }

  .prompt-tools { flex-wrap: nowrap; }

  .ref-preview-list { flex-shrink: 0; }

  .toolbar-right {
    width: auto;
    flex: 1 1 150px;
    min-width: 0;
    justify-content: flex-end;
    gap: 8px;
  }

  .toolbar-right .hint {
    display: inline-block;
    max-width: min(42vw, 220px);
  }

  .active-job-banner {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    bottom: 10px;
    padding: 7px 7px 7px 10px;
    gap: 8px;
  }

  .active-job-main { gap: 6px; }

  .active-job-title {
    max-width: 42vw;
    font-size: 0.78rem;
  }

  .active-job-meta { display: none; }

  .active-job-actions .btn {
    height: 30px;
    min-width: 48px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .btn-send { flex-shrink: 0; }

  .advanced-grid { grid-template-columns: 1fr; }

  .options-bar { gap: 8px; padding: 10px 12px; }

  .gallery { grid-template-columns: 1fr; }

  .switcher-btn { max-width: 140px; }

  .modal-footer { flex-wrap: wrap; }

  .backup-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .lightbox-close {
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
  }

  .settings-inline-check-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .account-actions { flex-direction: column; }

  .prompt-history-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .prompt-history-row select { min-width: 100%; }
}

/* ── Responsive: Small Phone (≤360px) ── */

@media (max-width: 360px) {
  .topbar { padding: 0 10px; }

  .logo span { display: none; }

  .switcher-btn {
    max-width: 116px;
    padding-inline: 10px;
  }

  .main { padding-left: 8px; padding-right: 8px; }

  .modal {
    width: 100%;
    max-height: calc(100dvh - 16px);
    border-radius: var(--radius);
  }

  .modal-header { padding: 16px 16px 0; }
  .modal-body { padding: 16px; }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  .options-bar .opt {
    min-width: min(100%, 148px);
  }


  .generation-progress-dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
  }

  .generation-progress-body { padding: 14px; }
  .generation-image-skeleton { height: 118px; }
  .generation-progress-actions { flex-direction: column; }
  .generation-progress-actions .btn { width: 100%; }
}

/* ── Safe Area (Notch Devices) ── */

@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: env(safe-area-inset-top);
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .main {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
}

/* ── Reduced Motion ── */

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


  .generation-image-skeleton::before {
    animation: none !important;
  }
}
