/* AeroScan portal — shared shell for Web Chat, Usage, Models */

:root {
  --bg0: #070b14;
  --bg1: #0f172a;
  --bg2: #1e293b;
  --bg3: #312e81;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #818cf8;
  --accent2: #a78bfa;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 10% -10%, rgba(99, 102, 241, 0.18), transparent 55%),
              radial-gradient(900px 600px at 90% 0%, rgba(139, 92, 246, 0.14), transparent 50%),
              linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg2) 75%, var(--bg3) 100%);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #c4b5fd; }

.hidden { display: none !important; }

.brand-logo {
  display: block;
  object-fit: contain;
}

.brand-logo-lg {
  width: 72px;
  height: 72px;
  margin: 0 auto;
}

.brand-logo-sm {
  width: 28px;
  height: 28px;
}

/* Connect */

.connect-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.connect-card {
  width: min(520px, 100%);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.connect-logo { text-align: center; margin-bottom: 0.35rem; }

.connect-card h1 {
  margin: 0 0 0.35rem;
  text-align: center;
  font-size: 1.65rem;
  color: #fff;
}

.connect-sub {
  text-align: center;
  color: var(--muted);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.key-input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.key-input:focus {
  outline: none;
  border-color: rgba(129, 140, 248, 0.55);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.connect-error {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.88rem;
}

.connect-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--glass-border);
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

/* Portal shell */

.portal-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.portal-topbar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.portal-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: 0.5rem;
}

.portal-nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.portal-nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.portal-nav a.active {
  color: #fff;
  background: rgba(99, 102, 241, 0.22);
}

.portal-topbar-spacer { flex: 1; }

.portal-user {
  font-size: 0.82rem;
  color: var(--dim);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-main {
  flex: 1;
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}

.page-head {
  margin-bottom: 1.5rem;
}

.page-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
  color: #fff;
}

.page-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.card-grid {
  display: grid;
  gap: 1rem;
}

.card-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .card-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .card-grid-2,
  .card-grid-3,
  .card-grid-4 { grid-template-columns: 1fr; }
  .portal-nav { display: none; }
}

.panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  backdrop-filter: blur(10px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}

.panel-sub {
  font-size: 0.82rem;
  color: var(--dim);
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-plan {
  background: rgba(99, 102, 241, 0.22);
  color: #c4b5fd;
}

.badge-success {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.badge-muted {
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.badge-locked {
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

/* Model feature chips (shared) */

.model-feature {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.model-feature-vision { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.model-feature-thinking { background: rgba(251, 191, 36, 0.12); color: var(--warn); }
.model-feature-tools { background: rgba(129, 140, 248, 0.15); color: #c4b5fd; }
.model-feature-design { background: rgba(167, 139, 250, 0.15); color: #ddd6fe; }
.model-feature-json { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; }
.model-feature-chat { background: rgba(148, 163, 184, 0.12); color: var(--muted); }

/* Toast notifications */

.portal-toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.portal-toast {
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  color: #fff;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: min(360px, calc(100vw - 2rem));
}

.portal-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.portal-toast-success {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(6, 78, 59, 0.92);
}

.portal-toast-warn {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(120, 53, 15, 0.92);
}

.portal-toast-error {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(127, 29, 29, 0.92);
}

.portal-toast-info {
  border-color: rgba(129, 140, 248, 0.35);
}

/* Settings form */

.settings-form {
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.settings-field { display: flex; flex-direction: column; gap: 0.35rem; }

.settings-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.settings-input:focus {
  outline: none;
  border-color: rgba(129, 140, 248, 0.55);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.settings-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.settings-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--dim);
  line-height: 1.4;
}

.settings-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}

.settings-toggle-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.settings-actions .btn-primary { width: auto; }

.settings-saved {
  font-size: 0.88rem;
  color: var(--success);
}

/* Screen reader only */
.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;
}

/* Mobile app navigation */
.portal-nav-toggle {
  display: none;
  flex-shrink: 0;
}

.portal-mobile-nav {
  position: fixed;
  inset: 0;
  z-index: 100010;
  pointer-events: none;
}

.portal-mobile-nav.open {
  pointer-events: auto;
}

.portal-mobile-nav-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.portal-mobile-nav.open .portal-mobile-nav-backdrop {
  opacity: 1;
}

.portal-mobile-nav-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 88vw);
  background: linear-gradient(180deg, #0f172a 0%, #070b14 100%);
  border-right: 1px solid var(--glass-border);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: 0.85rem;
  box-shadow: var(--shadow);
}

.portal-mobile-nav.open .portal-mobile-nav-panel {
  transform: translateX(0);
}

.portal-mobile-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.portal-mobile-nav-title {
  font-weight: 700;
  color: #fff;
}

.portal-mobile-nav-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.portal-mobile-nav-links {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.portal-mobile-nav-links a {
  display: block;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.portal-mobile-nav-links a:hover,
.portal-mobile-nav-links a.active {
  background: rgba(99, 102, 241, 0.18);
  color: #fff;
}

body.portal-mobile-nav-open {
  overflow: hidden;
}

@media (max-width: 900px) {
  .portal-nav-toggle {
    display: inline-flex;
  }
  .topbar-nav {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .portal-nav {
    display: none;
  }
}

/* Loading skeletons */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 25%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.06) 75%
  );
  background-size: 200% 100%;
  animation: portalSkeleton 1.2s ease-in-out infinite;
  border-radius: 8px;
}

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

.skeleton-card {
  height: 88px;
}

/* Studio gallery lightbox */
.studio-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100020;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.studio-lightbox.hidden {
  display: none;
}

.studio-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
}

.studio-lightbox-card {
  position: relative;
  max-width: min(920px, 96vw);
  max-height: 92vh;
  overflow: auto;
  background: #0f172a;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 1rem;
}

.studio-lightbox-media {
  max-width: 100%;
  max-height: 60vh;
  display: block;
  margin: 0 auto 0.75rem;
  border-radius: 8px;
}

.studio-lightbox-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton {
    animation: none;
    background: rgba(255, 255, 255, 0.08);
  }
}
