/* ═══════════════════════════════════════════
   Design System — Image API Gateway
   ═══════════════════════════════════════════ */
:root {
  /* Palette */
  --color-bg: #f0f4f9;
  --color-surface: #ffffff;
  --color-overlay: rgba(15, 23, 42, 0.5);
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-border: #e6eaf0;
  --color-border-light: #f1f5f9;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-light: #eef2ff;
  --color-primary-subtle: rgba(79, 70, 229, 0.08);

  --color-success: #059669;
  --color-success-light: #ecfdf5;
  --color-warning: #d97706;
  --color-warning-light: #fffbeb;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-light: #fef2f2;

  --color-sidebar: #111827;
  --color-sidebar-hover: #1e293b;
  --color-sidebar-active: rgba(99, 102, 241, 0.18);
  --color-sidebar-text: #94a3b8;
  --color-sidebar-text-active: #ffffff;

  /* Typography */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;

  /* Spacing */
  --sidebar-width: 230px;
  --sidebar-collapsed: 64px;
  --drawer-width: 560px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.1), 0 4px 8px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 24px 48px -8px rgba(15, 23, 42, 0.14), 0 8px 16px -6px rgba(15, 23, 42, 0.06);
  --shadow-drawer: -12px 0 40px rgba(15, 23, 42, 0.15);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  background-image: radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
                    radial-gradient(at 100% 100%, rgba(79, 70, 229, 0.03) 0%, transparent 50%);
  min-height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   App Layout
   ═══════════════════════════════════════════ */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ═══════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  background-image: linear-gradient(180deg, #1e1b4b 0%, #111827 40%, #0f172a 100%);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--duration-normal) var(--ease-out);
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.brand-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--color-sidebar-text);
  opacity: 0.7;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-sidebar-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  text-align: left;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--color-sidebar-active);
  color: var(--color-sidebar-text-active);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: linear-gradient(180deg, #818cf8 0%, #6366f1 100%);
  border-radius: 0 3px 3px 0;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item.active svg {
  opacity: 1;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  color: var(--color-sidebar-text);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.sidebar-toggle:hover {
  background: var(--color-sidebar-hover);
  color: #fff;
}

.sidebar-toggle svg {
  transition: transform var(--duration-normal) var(--ease-out);
}

/* Collapsed sidebar */
.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .nav-item.active::before {
  display: none;
}

.sidebar.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* ═══════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px 48px;
  transition: margin-left var(--duration-normal) var(--ease-out);
  max-width: 100%;
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed);
}

/* ═══════════════════════════════════════════
   Panel Visibility
   ═══════════════════════════════════════════ */
.panel {
  display: none;
  animation: fadeSlideIn var(--duration-normal) var(--ease-out);
}

.panel.active {
  display: block;
}

.hidden {
  display: none !important;
}

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

/* ═══════════════════════════════════════════
   Connect Card
   ═══════════════════════════════════════════ */
.connect-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  overflow: hidden;
}

.connect-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--color-primary) 0%, #7c3aed 100%);
}

.connect-header {
  margin-bottom: 18px;
}

.connect-header h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 3px;
}

.connect-header p {
  color: var(--color-text-secondary);
  font-size: 13px;
}

.float-field-group {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.float-field-group .float-field {
  flex: 1;
}

/* ═══════════════════════════════════════════
   Floating Label Form Fields
   ═══════════════════════════════════════════ */
.float-field {
  position: relative;
  display: block;
  min-width: 0;
}

.float-field input,
.float-field select,
.float-field textarea {
  width: 100%;
  padding: 16px 14px 8px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fafbfc;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  transition: all var(--duration-fast) var(--ease-out);
  outline: none;
  height: 50px;
}

.float-field textarea {
  height: auto;
  min-height: 80px;
  resize: vertical;
  padding-top: 22px;
}

.float-field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.float-field input:hover,
.float-field select:hover,
.float-field textarea:hover {
  border-color: #cbd5e1;
}

.float-field input:focus,
.float-field select:focus,
.float-field textarea:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 4px var(--color-primary-subtle);
}

.float-field input:focus + .float-label,
.float-field input:not(:placeholder-shown) + .float-label,
.float-field select:focus + .float-label,
.float-field select:not([value=""]) + .float-label,
.float-field textarea:focus + .float-label,
.float-field textarea:not(:placeholder-shown) + .float-label {
  transform: translateY(-10px) scale(0.78);
  color: var(--color-primary);
}

.float-field input:focus:not(:placeholder-shown) + .float-label,
.float-field select:focus:not([value=""]) + .float-label {
  color: var(--color-primary);
}

.float-field input:not(:focus):not(:placeholder-shown) + .float-label,
.float-field textarea:not(:focus):not(:placeholder-shown) + .float-label {
  color: var(--color-text-secondary);
}

.float-label {
  position: absolute;
  left: 15px;
  top: 17px;
  font-size: 14px;
  color: var(--color-text-muted);
  pointer-events: none;
  transform-origin: left top;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.float-label.static {
  top: -8px;
  left: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.float-hint {
  display: block;
  margin-top: 4px;
  padding-left: 2px;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Password visibility toggle */
.pw-field {
  position: relative;
}

.pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  z-index: 2;
  transition: color var(--duration-fast) var(--ease-out);
}

.pw-toggle:hover {
  color: var(--color-text-secondary);
}

.pw-field input[type="password"],
.pw-field input[type="text"] {
  padding-right: 44px;
}

/* Validation states */
.float-field.valid input {
  border-color: var(--color-success);
}

.float-field.valid .float-label {
  color: var(--color-success);
}

.float-field.invalid input {
  border-color: var(--color-danger);
}

.float-field.invalid .float-label {
  color: var(--color-danger);
}

.float-field .validation-msg {
  display: none;
  margin-top: 4px;
  padding-left: 2px;
  font-size: 12px;
  color: var(--color-danger);
}

.float-field.invalid .validation-msg {
  display: block;
}

/* Checkline */
.checkline-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
  cursor: pointer;
}

.checkline-field input[type="checkbox"] {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  appearance: none;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #e2e8f0;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.checkline-field input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-out);
}

.checkline-field input[type="checkbox"]:checked {
  border-color: var(--color-primary);
  background: var(--color-primary);
}

.checkline-field input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

.checkline-field span {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--color-text);
  user-select: none;
}

.checkline-field span strong {
  font-size: 13px;
}

.checkline-field span small {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.4;
}

/* ═══════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════ */
button {
  font-family: var(--font-sans);
  line-height: 1.2;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--duration-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
}

button:active {
  transform: scale(0.97);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25), 0 1px 2px rgba(79, 70, 229, 0.15);
  letter-spacing: 0.01em;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--color-primary-hover) 0%, #6d28d9 100%);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.35);
  transform: translateY(-1px);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  height: 52px;
}

.btn-primary.btn-full {
  width: 100%;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--color-border);
}

.btn-ghost:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: #c7d2fe;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-danger-light);
  color: var(--color-danger);
  font-size: 13px;
  font-weight: 500;
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-sm:hover {
  background: var(--color-primary);
  color: #fff;
}

.btn-warning {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-warning-light);
  color: var(--color-warning);
  font-size: 13px;
  font-weight: 500;
}

.btn-warning:hover {
  background: var(--color-warning);
  color: #fff;
}

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

/* ═══════════════════════════════════════════
   Metric Cards
   ═══════════════════════════════════════════ */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

#adminMetrics.metric-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--duration-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.metric-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #c7d2fe;
}

.metric-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #f5f3ff 100%);
  color: var(--color-primary);
}

.metric-icon.accent {
  background: linear-gradient(135deg, #eef2ff 0%, #fef3c7 100%);
  color: var(--color-primary);
}

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

.metric-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}

.metric-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  word-break: break-all;
  color: var(--color-text);
}

.metric-value.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}

/* Stagger animation */
.stagger-in .metric-card {
  opacity: 0;
  animation: staggerIn 0.4s var(--ease-out) forwards;
}

.stagger-in .metric-card:nth-child(1) { animation-delay: 0.05s; }
.stagger-in .metric-card:nth-child(2) { animation-delay: 0.10s; }
.stagger-in .metric-card:nth-child(3) { animation-delay: 0.15s; }
.stagger-in .metric-card:nth-child(4) { animation-delay: 0.20s; }
.stagger-in .metric-card:nth-child(5) { animation-delay: 0.25s; }
.stagger-in .metric-card:nth-child(6) { animation-delay: 0.30s; }

@keyframes staggerIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ═══════════════════════════════════════════
   Surface / Card
   ═══════════════════════════════════════════ */
.surface {
  margin-bottom: 14px;
  padding: 18px 20px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-normal) var(--ease-out);
}

.surface:hover {
  box-shadow: var(--shadow-md);
}

.surface[id^="admin"] {
  scroll-margin-top: 160px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.section-head h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

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

.admin-toolbar {
  position: sticky;
  top: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 80px;
  margin-bottom: 8px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.admin-title {
  min-width: 0;
}

.admin-toolbar .admin-kicker {
  display: block;
  margin-bottom: 3px;
  background: linear-gradient(90deg, var(--color-primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-toolbar strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.admin-toolbar .admin-title > span:not(.admin-kicker) {
  display: block;
  margin-top: 4px;
  color: var(--color-text-muted);
  font-size: 12px;
}

.admin-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-section-nav {
  position: sticky;
  top: 88px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 46px;
  margin: 0 0 14px;
  padding: 6px;
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.admin-jump {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.admin-jump:hover {
  background: var(--color-surface);
  color: var(--color-primary);
}

.admin-jump.active {
  background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.hint {
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ═══════════════════════════════════════════
   Expand Panel
   ═══════════════════════════════════════════ */
.expand-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--duration-slow) var(--ease-out), margin var(--duration-slow) var(--ease-out);
  margin-bottom: 0;
}

.expand-panel.open {
  max-height: 300px;
  margin-bottom: 16px;
}

.expand-panel.always-visible {
  max-height: none;
  overflow: visible;
  margin-bottom: 16px;
}

/* ═══════════════════════════════════════════
   Form Row
   ═══════════════════════════════════════════ */
.form-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.debug-surface .form-row {
  align-items: flex-start;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 150px 150px;
  gap: 14px;
}

.form-row .float-field {
  flex: 1;
  min-width: 160px;
}

.form-row .float-field.narrow {
  flex: 0 0 130px;
}

.form-row .float-field.wide {
  flex: 2;
  min-width: 220px;
}

.form-row .float-field.full {
  flex: 1 1 100%;
  min-width: 100%;
}

.debug-surface .form-row .float-field.full {
  grid-column: 1 / -1;
  min-width: 0;
}

.debug-surface #runImageTest {
  grid-column: 1 / -1;
  width: fit-content;
}

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

/* ═══════════════════════════════════════════
   Login Card
   ═══════════════════════════════════════════ */
.login-card {
  max-width: 420px;
  margin: 40px auto 0;
  text-align: center;
}

.login-header {
  margin-bottom: 24px;
}

.login-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #f5f3ff 100%);
  color: var(--color-primary);
}

.login-header h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-header p {
  color: var(--color-text-secondary);
  font-size: 14px;
}

/* ═══════════════════════════════════════════
   Table
   ═══════════════════════════════════════════ */
.table-wrap {
  max-height: min(440px, calc(100vh - 250px));
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

#adminUsageSection .table-wrap,
#adminKeyUsageSection .table-wrap {
  max-height: min(520px, calc(100vh - 230px));
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  color: var(--color-text);
  white-space: nowrap;
  font-size: 13px;
}

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

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

tbody tr:hover {
  background: #f8fafc;
}

td code {
  display: inline-block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 3px 8px;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
}

.empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 32px 14px !important;
  font-style: italic;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: max-content;
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.section-head .table-tools {
  width: auto;
}

.table-search,
.table-filter {
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  outline: none;
}

.table-search:focus,
.table-filter:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.table-search {
  width: min(320px, 100%);
  padding: 0 12px;
}

.table-filter {
  padding: 0 10px;
}

.drawer-tools {
  justify-content: space-between;
}

.compact-table table {
  min-width: 620px;
}

.compact-table {
  max-height: 360px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  color: var(--color-text-secondary);
  font-size: 12px;
}

.pager-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-sm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secret-line,
.secret-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.secret-line code,
.secret-cell code {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.secret-cell {
  max-width: 520px;
}

.muted,
.muted-note {
  color: var(--color-text-muted);
}

.muted-note {
  font-size: 12px;
  line-height: 1.6;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 300;
  background: rgba(15, 23, 42, 0.18);
  pointer-events: none;
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-lg);
  color: var(--color-text);
  font-weight: 600;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

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

.back-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
  cursor: pointer;
}

/* ═══════════════════════════════════════════
   Status Pills
   ═══════════════════════════════════════════ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill {
  background: #ecfdf5;
  color: #059669;
}
.pill::before { background: currentColor; }

.pill.warn {
  background: #fffbeb;
  color: #b45309;
}

.pill.bad {
  background: #fef2f2;
  color: #dc2626;
}

/* ═══════════════════════════════════════════
   Empty State
   ═══════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.6;
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════
   Key Result Banner (sticky)
   ═══════════════════════════════════════════ */
.key-banner {
  position: sticky;
  top: 0;
  z-index: 10;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid #a5b4fc;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  color: #3730a3;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  box-shadow: var(--shadow-md);
}

.key-banner .banner-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
  border: none;
}

.key-banner .banner-dismiss:hover {
  background: rgba(37, 99, 235, 0.12);
}

/* ═══════════════════════════════════════════
   Secret Box (inline, deprecated by key-banner)
   ═══════════════════════════════════════════ */
.secret-box {
  margin: 0 0 14px;
  padding: 14px 16px;
  border: 1px solid #93c5fd;
  border-radius: var(--radius-md);
  background: #eff6ff;
  color: #1e40af;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ═══════════════════════════════════════════
   Test Result
   ═══════════════════════════════════════════ */
.test-result {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(260px, 380px) 1fr;
  gap: 16px;
  align-items: start;
  animation: fadeSlideIn var(--duration-normal) var(--ease-out);
}

.image-preview {
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.image-preview img {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  display: block;
}

.response-box {
  min-height: 220px;
  max-height: 460px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ═══════════════════════════════════════════
   Drawer
   ═══════════════════════════════════════════ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-out);
  backdrop-filter: blur(2px);
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 100%;
  background: var(--color-surface);
  z-index: 210;
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-out);
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
}

.drawer-head h3 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.drawer-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  transition: all var(--duration-fast) var(--ease-out);
}

.drawer-close:hover {
  background: #f1f5f9;
  color: var(--color-text);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.drawer-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Drawer form */
.drawer-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-form-intro {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.drawer-form-intro.compact {
  margin-top: 2px;
}

.drawer-form-intro strong {
  color: var(--color-text);
  font-size: 13px;
}

.drawer-form-intro span {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.55;
}

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

.field-grid .full {
  grid-column: 1 / -1;
}

.form-note {
  margin: -2px 2px 0;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.balance-summary {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%);
}

.balance-summary span {
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.balance-summary strong {
  color: var(--color-primary);
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.drawer-form .float-field input,
.drawer-form .float-field select {
  background: #f8fafc;
}

.drawer-form .float-field input:focus,
.drawer-form .float-field select:focus {
  background: #fff;
}

.model-picker {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.picker-head span {
  color: var(--color-text-muted);
  font-size: 12px;
}

.picker-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--color-text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-search {
  width: 100%;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  outline: none;
  padding: 0 10px;
}

.picker-search:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.picker-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.picker-option {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  text-align: left;
  transition: all var(--duration-fast) var(--ease-out);
}

.picker-option:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.picker-option.active {
  border-color: var(--color-primary);
  background: var(--color-primary-subtle);
}

.picker-option span {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-option small {
  color: var(--color-text-muted);
  font-size: 11px;
}

.picker-empty,
.picker-more {
  padding: 10px;
  color: var(--color-text-muted);
  font-size: 12px;
  text-align: center;
}

.route-picker-field {
  flex: 3 1 620px;
  min-width: 320px;
  display: grid;
  gap: 6px;
  align-self: flex-start;
}

.debug-surface .route-picker-field {
  flex: initial;
  min-width: 0;
  width: 100%;
}

.route-picker-field ~ .float-field.narrow {
  align-self: flex-start;
}

.route-picker-label {
  color: var(--color-primary);
  font-size: 11px;
  font-weight: 700;
}

.route-picker-selected {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-picker-search {
  width: 100%;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--color-text);
  font-size: 13px;
  outline: none;
  padding: 0 10px;
}

.route-picker-search:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.route-picker-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.route-option {
  display: grid;
  align-content: center;
  gap: 5px;
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  line-height: 1.25;
  text-align: left;
  transition: all var(--duration-fast) var(--ease-out);
}

.route-option:hover,
.route-option.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.route-option span,
.route-option small {
  display: block;
  min-width: 0;
  overflow: hidden;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-option span {
  font-size: 13px;
  font-weight: 700;
}

.route-option small {
  color: var(--color-text-muted);
  font-size: 11px;
}

/* Drawer confirmation */
.drawer-confirm {
  text-align: center;
  padding: 24px 0;
}

.drawer-confirm .confirm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.drawer-confirm .confirm-icon.danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.drawer-confirm .confirm-icon.warning-icon {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.drawer-confirm p {
  color: var(--color-text-secondary);
  font-size: 14px;
  margin-top: 8px;
  line-height: 1.6;
}

/* ═══════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════ */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  max-width: 420px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.3);
  animation: toastIn 0.3s var(--ease-out);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.toast-item.leaving {
  animation: toastOut 0.25s var(--ease-in-out) forwards;
}

.toast-item.success {
  border-left: 3px solid var(--color-success);
}

.toast-item.error {
  border-left: 3px solid var(--color-danger);
}

.toast-item.warning {
  border-left: 3px solid var(--color-warning);
}

.toast-item .toast-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-item .toast-msg {
  flex: 1;
  min-width: 0;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(60px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(60px);
  }
}

/* ═══════════════════════════════════════════
   Loading Skeleton
   ═══════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

/* ═══════════════════════════════════════════
   Button Loading
   ═══════════════════════════════════════════ */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ═══════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════ */
@media (max-width: 960px) {
  .sidebar {
    width: var(--sidebar-collapsed);
  }

  .sidebar .brand-text,
  .sidebar .nav-item span {
    opacity: 0;
    width: 0;
    overflow: hidden;
  }

  .sidebar .nav-item {
    justify-content: center;
    padding: 10px;
  }

  .sidebar .nav-item.active::before {
    display: none;
  }

  .sidebar .sidebar-toggle svg {
    transform: rotate(180deg);
  }

  .sidebar:not(.collapsed) {
    width: var(--sidebar-collapsed);
  }

  .sidebar.expanded-mobile {
    width: var(--sidebar-width);
  }

  .sidebar.expanded-mobile .brand-text,
  .sidebar.expanded-mobile .nav-item span {
    opacity: 1;
    width: auto;
    overflow: visible;
  }

  .sidebar.expanded-mobile .nav-item {
    justify-content: flex-start;
    padding: 10px 14px;
  }

  .sidebar.expanded-mobile .nav-item.active::before {
    display: block;
  }

  .sidebar.expanded-mobile .sidebar-toggle svg {
    transform: rotate(0deg);
  }

  .main-content {
    margin-left: var(--sidebar-collapsed);
    padding: 20px 16px 36px;
  }

  .test-result {
    grid-template-columns: 1fr;
  }

  .admin-section-nav {
    top: 88px;
  }

  .debug-surface .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .debug-surface .route-picker-field,
  .debug-surface .form-row .float-field.full,
  .debug-surface #runImageTest {
    grid-column: 1 / -1;
  }

  .metric-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 640px) {
  .main-content {
    padding: 16px 12px 28px;
  }

  .surface {
    padding: 16px;
  }

  .admin-toolbar {
    position: sticky;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .admin-top-actions {
    justify-content: flex-start;
  }

  .admin-section-nav {
    position: static;
    top: auto;
    margin: 0 0 14px;
  }

  .connect-card {
    padding: 20px 16px;
  }

  .float-field-group {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row .float-field,
  .form-row .float-field.narrow,
  .form-row .float-field.wide,
  .form-row .float-field.full {
    flex: 1 1 auto;
    min-width: 0;
  }

  .debug-surface .form-row,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .field-grid .full {
    grid-column: auto;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .metric-card {
    padding: 14px;
  }

  .metric-value {
    font-size: 18px;
  }

  .drawer {
    width: 100%;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

@media (max-width: 400px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
