/* ============================================
   CAPFORM - Complete Design System
   Source of truth: DESIGN.md
   ============================================ */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- Design Tokens (Section 2 of DESIGN.md) ---------- */
:root {
  /* Base dark mode */
  --bg-base: #0a0a0a;
  --bg-surface: #111111;
  --bg-elevated: #1a1a1a;
  --bg-border: #222222;
  --bg-subtle: #2a2a2a;

  /* Text - high contrast */
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #52525b;
  --text-inverse: #0a0a0a;

  /* Brand accent */
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --accent-subtle: #052e16;
  --accent-text: #4ade80;

  /* Semantic */
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-info: #3b82f6;
  --color-success: #22c55e;

  /* Semantic subtle backgrounds */
  --bg-danger: #1c0a0a;
  --bg-warning: #1c1200;
  --bg-info: #0a0f1c;
  --bg-success: #052e16;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 28px;
  --text-2xl: 36px;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Spacing (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  /* Layout */
  --sidebar-width: 220px;
  --sidebar-collapsed: 52px;
  --topbar-height: 52px;
  --content-max-width: 1200px;
  --content-padding: 24px;

  /* Component tokens */
  --input-bg: var(--bg-elevated);
  --input-border: var(--bg-border);
  --input-focus: var(--accent);
  --input-height: 36px;

  --card-bg: var(--bg-surface);
  --card-border: var(--bg-border);
  --card-radius: var(--radius-lg);
  --card-padding: 20px 24px;
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
  color: inherit;
}

input,
textarea,
select {
  font-family: inherit;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--bg-border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-subtle);
}

/* ==========================================================
   LAYOUT SHELL
   ========================================================== */

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Prevent layout shift: reserve space even when empty */
  min-height: 100vh;
}

.sidebar-header {
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--bg-border);
  flex-shrink: 0;
}

.logo-mark {
  width: 22px;
  height: 22px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-2);
}

.nav-section {
  margin-bottom: var(--space-4);
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-2) var(--space-3) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px var(--space-3);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  margin-bottom: 1px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.nav-item i {
  width: 16px;
  text-align: center;
  font-size: 14px;
  color: var(--text-tertiary);
  transition: color 0.15s;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item:hover i {
  color: var(--text-secondary);
}

/* Active state per DESIGN.md: accent left border + bg-elevated */
.nav-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
}

.nav-item.active i {
  color: var(--accent);
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-subtle);
  color: var(--accent-text);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--bg-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Sidebar Credit Card Widget */
.sidebar-credit-card {
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.credit-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
}

.credit-widget-balance {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.credit-widget-bar {
  height: 4px;
  background: var(--bg-subtle);
  border-radius: 2px;
  overflow: hidden;
}

.credit-widget-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.credit-widget-fill.warning {
  background: var(--color-warning);
}

.credit-widget-fill.danger {
  background: var(--color-danger);
}

.credit-topup-btn {
  width: 100%;
  padding: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  color: var(--text-secondary);
  transition: all 0.2s;
}

.credit-topup-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--bg-subtle);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-user:hover {
  background: var(--bg-elevated);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.user-meta {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Main Area ---------- */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  padding: 0 var(--content-padding);
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-base);
  flex-shrink: 0;
  /* Prevent height collapse during load */
  min-height: var(--topbar-height);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.breadcrumb a {
  color: var(--text-tertiary);
}

.breadcrumb a:hover {
  color: var(--text-secondary);
}

.breadcrumb .sep {
  font-size: 9px;
}

.breadcrumb .current {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.mobile-toggle {
  display: none;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 16px;
}

.mobile-toggle:hover {
  background: var(--bg-elevated);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  width: 200px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.search-trigger:hover {
  border-color: var(--bg-subtle);
}

.search-trigger kbd {
  margin-left: auto;
  font-family: inherit;
  font-size: 10px;
  color: var(--text-tertiary);
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--bg-border);
}

.topbar-icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  transition: background 0.15s;
}

.topbar-icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ---------- Content ---------- */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--content-padding);
}

.content-max {
  max-width: var(--content-max-width);
}

/* ==========================================================
   COMMON COMPONENTS
   ========================================================== */

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  gap: var(--space-4);
}

.page-title h1 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.page-title p {
  color: var(--text-secondary);
  font-size: var(--text-base);
  margin-top: 2px;
}

.page-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--accent);
  color: #000;
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--bg-subtle);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-elevated);
}

.btn-ghost {
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

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

.btn-danger:hover {
  opacity: 0.9;
}

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
}

.card-flush {
  padding: 0;
  overflow: hidden;
}

/* ---------- Stat Cards ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
}

.stat-trend {
  font-size: var(--text-xs);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-trend.up {
  color: var(--color-success);
}

.stat-trend.down {
  color: var(--color-danger);
}

/* ---------- Data Table ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--bg-border);
  white-space: nowrap;
}

.data-table td {
  padding: 14px var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--bg-border);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background 0.1s;
  cursor: pointer;
}

.data-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

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

.td-primary {
  color: var(--text-primary) !important;
  font-weight: var(--weight-medium);
}

.td-mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green {
  background: rgba(34, 197, 94, 0.12);
  color: #4ade80;
}

.badge-blue {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
}

.badge-purple {
  background: rgba(168, 85, 247, 0.12);
  color: #c084fc;
}

.badge-amber {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

.badge-red {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.badge-gray {
  background: rgba(161, 161, 170, 0.1);
  color: #a1a1aa;
}

/* ==========================================================
   SUBMISSION CARDS
   ========================================================== */

.submission-cards-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.submission-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  transition: transform 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.submission-card:hover {
  border-color: var(--bg-subtle);
  background: var(--bg-elevated);
}

.sc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.sc-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.sc-icon {
  width: 42px;
  height: 42px;
  background: var(--bg-base);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 18px;
}

.sc-title-info {
  display: flex;
  flex-direction: column;
}

.sc-session-id {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

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

.sc-meta span::before {
  content: "•";
  margin-right: 8px;
  color: var(--bg-border);
}

.sc-meta span:first-child::before {
  display: none;
}

.sc-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px 20px;
}

.sc-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sc-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
}

.sc-value {
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-all;
  line-height: 1.4;
}

.animate-pulse-live {
  animation: pulse-live 2.5s infinite;
}

@keyframes pulse-live {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

.card-update-flash {
  animation: flash-bg 1.5s ease-out;
}

@keyframes flash-bg {
  0% { background: var(--accent-subtle); }
  100% { background: transparent; }
}

/* Pulsing dot for "processing" status */
.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

/* ---------- Visibility Control ---------- */
body:not(.shell-ready) .content-area {
  opacity: 0;
}

body.shell-ready .content-area {
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* ---------- Additional Components ---------- */
.credits-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.credits-table th {
  text-align: left;
  padding: 12px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--bg-border);
}

.credits-table td {
  padding: 12px;
  border-bottom: 1px solid var(--bg-border);
}

/* ---------- Inputs & Form Fields ---------- */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-input {
  width: 100%;
  height: var(--input-height);
  padding: 0 var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--input-focus);
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

.form-input[readonly] {
  background: var(--bg-base);
  color: var(--text-tertiary);
  cursor: default;
}

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

.input-row {
  display: flex;
  gap: var(--space-2);
}

.input-row .form-input {
  flex: 1;
}

.form-textarea {
  width: 100%;
  padding: var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s;
}

.form-textarea:focus {
  border-color: var(--input-focus);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-subtle);
  border-radius: 10px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked+.toggle-slider {
  background: var(--accent);
}

.toggle input:checked+.toggle-slider::before {
  transform: translateX(16px);
}

/* ---------- Tab Bar (Horizontal pills) ---------- */
.tab-bar {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--bg-border);
  margin-bottom: var(--space-6);
}

.tab-item {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
  white-space: nowrap;
}

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

.tab-item.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab-content {
  min-height: 50dvh;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
}

.empty-state i {
  font-size: 40px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-5);
  opacity: 0.5;
}

.empty-state h3 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
}

.empty-state p {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  max-width: 320px;
  margin-bottom: var(--space-5);
}

/* ---------- Usage Meter ---------- */
.usage-meter {
  margin-bottom: var(--space-6);
}

.usage-meter-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-2);
}

.usage-meter-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.usage-meter-value {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.usage-meter-bar {
  height: 6px;
  background: var(--bg-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--space-1);
}

.usage-meter-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 1s ease;
}

.usage-meter-fill.warning {
  background: var(--color-warning);
}

.usage-meter-fill.danger {
  background: var(--color-danger);
}

.usage-meter-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ---------- Endpoint Display ---------- */
.endpoint-box {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--bg-base);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.endpoint-box .method {
  color: var(--accent-text);
  font-weight: 600;
}

.endpoint-box .url {
  flex: 1;
}

.endpoint-box .actions {
  display: flex;
  gap: var(--space-1);
  margin-left: auto;
}

/* ---------- Credential Card ---------- */
.cred-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
}

.cred-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

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

.cred-info .cred-name {
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
}

.cred-info .cred-detail {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.cred-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Connection status */
.status-connected {
  color: var(--color-success);
}

.status-disconnected {
  color: var(--text-tertiary);
}

/* ---------- Selection Cards (Form type selection) ---------- */
.type-cards {
  display: grid;
  gap: var(--space-4);
}

.type-cards.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.type-cards.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* ---------- Top-up Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-overlay.visible {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  position: relative;
}

.modal-header {
  padding: var(--space-5);
  border-bottom: 1px solid var(--bg-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: var(--text-md);
  font-weight: 600;
}

.modal-body {
  padding: var(--space-5);
}

.modal-footer {
  padding: var(--space-4) var(--space-5);
  background: var(--bg-base);
  border-top: 1px solid var(--bg-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.modal-close {
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.pricing-card {
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.pricing-card:hover {
  background: var(--bg-elevated);
  border-color: var(--bg-subtle);
}

.pricing-card.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.pricing-amount {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.pricing-credits {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
}

.type-card {
  padding: var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.type-card:hover {
  border-color: var(--bg-subtle);
}

.type-card.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.type-card i {
  font-size: 20px;
  margin-bottom: var(--space-3);
}

.type-card h3 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.type-card p {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  line-height: 1.5;
}

.type-card .best-for {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  min-width: 280px;
  max-width: 400px;
}

.toast-success i {
  color: var(--color-success);
}

.toast-error i {
  color: var(--color-danger);
}

.toast-warning i {
  color: var(--color-warning);
}

.toast-info i {
  color: var(--color-info);
}

/* ---------- Command Palette ---------- */
.cmd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
}

.cmd-overlay.visible {
  display: flex;
}

.cmd-box {
  width: 560px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--bg-border);
}

.cmd-input-wrap i {
  color: var(--text-tertiary);
  font-size: 16px;
}

.cmd-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: var(--text-base);
  outline: none;
}

.cmd-input::placeholder {
  color: var(--text-tertiary);
}

.cmd-results {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-2);
}

.cmd-group-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-3);
}

.cmd-result {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.1s;
}

.cmd-result:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.cmd-result i {
  width: 16px;
  text-align: center;
  color: var(--text-tertiary);
}

.cmd-footer {
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--bg-border);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  display: flex;
  gap: var(--space-4);
}

.cmd-footer kbd {
  font-family: inherit;
  font-size: 10px;
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--bg-border);
}

/* ---------- Submission Drawer ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 8000;
  display: none;
}

.drawer-overlay.visible {
  display: block;
}

.drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 480px;
  background: var(--bg-surface);
  border-left: 1px solid var(--bg-border);
  z-index: 8001;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

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

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5);
  border-bottom: 1px solid var(--bg-border);
}

.drawer-header h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.drawer-section {
  margin-bottom: var(--space-6);
}

.drawer-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--bg-border);
}

.drawer-field {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
}

.drawer-field-label {
  color: var(--text-tertiary);
}

.drawer-field-value {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
  text-align: right;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
}

.workflow-step i {
  font-size: 12px;
}

.workflow-step .step-time {
  margin-left: auto;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ---------- Skeleton Loading ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-subtle) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-shine {
  to {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 200px;
  margin-bottom: 8px;
}

.skeleton-stat {
  height: 32px;
  width: 100px;
}

/* ---------- Danger Zone ---------- */
.danger-zone {
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  background: var(--bg-danger);
}

.danger-zone h3 {
  color: var(--color-danger);
  margin-bottom: var(--space-2);
}

.danger-zone p {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

/* ---------- Sections separator ---------- */
.section-separator {
  margin: var(--space-6) 0;
}

.section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-4);
}

.section-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

/* ---------- Grid Helpers ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

/* ---------- Heatmap Bars ---------- */
.heatmap-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.heatmap-label {
  width: 120px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.heatmap-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-border);
  border-radius: 4px;
  overflow: hidden;
}

.heatmap-fill {
  height: 100%;
  border-radius: 4px;
}

.heatmap-value {
  width: 60px;
  text-align: right;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ---------- Animation helpers ---------- */
.animate-in {
  opacity: 0;
  transform: translateY(8px);
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 200;
  }

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

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    display: none;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .mobile-toggle {
    display: flex;
  }

  .search-trigger {
    width: auto;
  }

  .search-trigger span {
    display: none;
  }

  .search-trigger kbd {
    display: none;
  }
}

@media (max-width: 640px) {
  .content-area {
    padding: var(--space-4);
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .stat-row {
    grid-template-columns: 1fr;
  }

  .type-cards.cols-2,
  .type-cards.cols-3 {
    grid-template-columns: 1fr;
  }

  .drawer {
    width: 100%;
  }
}

/* ==========================================================
   UTILITIES & ANIMATIONS
   ========================================================== */

/* ---------- Shimmer (Skeleton Loading) ---------- */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

.shimmer {
  display: inline-block;
  width: var(--s-w, 100%);
  height: var(--s-h, 1em);
  background: linear-gradient(90deg,
      var(--bg-elevated) 25%,
      var(--bg-subtle) 50%,
      var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--s-r, var(--radius-sm));
  vertical-align: middle;
}

/* Common Shimmer Shapes */
.shimmer-text {
  --s-h: 0.8em;
  margin: 0.1em 0;
}

.shimmer-title {
  --s-h: 1.5em;
  --s-w: 60%;
  margin-bottom: var(--space-4);
}

.shimmer-circle {
  --s-w: 40px;
  --s-h: 40px;
  --s-r: 50%;
}

.shimmer-card {
  --s-h: 120px;
  width: 100%;
  --s-r: var(--radius-lg);
}

.shimmer-badge {
  --s-w: 60px;
  --s-h: 18px;
  --s-r: 10px;
}