:root {
  --app-bg: #07111f;
  --app-bg-elevated: rgba(10, 20, 38, 0.76);
  --app-bg-soft: rgba(255, 255, 255, 0.04);
  --app-border: rgba(255, 255, 255, 0.08);
  --app-border-strong: rgba(255, 255, 255, 0.14);
  --app-text: #f4f7fb;
  --app-text-muted: #9dafc4;
  --app-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --app-radius: 28px;
  --app-radius-sm: 18px;
  --app-primary: #66a6ff;
  --app-primary-2: #8b7bff;
  --app-success-soft: rgba(61, 214, 140, 0.16);
  --app-user-soft: rgba(126, 167, 255, 0.15);
}

html,
body {
  height: 100%;
  min-height: 100%;
}

body.app-body,
body.auth-body {
  color: var(--app-text);
  background:
    radial-gradient(circle at top left, rgba(102, 166, 255, 0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(139, 123, 255, 0.16), transparent 24%),
    linear-gradient(180deg, #091221 0%, #07111f 42%, #040b15 100%);
}

body.app-body {
  display: flex;
  flex-direction: column;
  padding-bottom: 1rem;
}

a {
  text-decoration: none;
}

.app-shell {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 0 1rem 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page-panels {
  margin-top: 0.5rem;
}

.app-shell > .surface-panel.page-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem !important;
}

.app-shell > .surface-panel.page-panels > .card-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  backdrop-filter: blur(24px);
  background: rgba(7, 17, 31, 0.72);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar-inner {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.95rem;
  background: linear-gradient(135deg, rgba(102, 166, 255, 0.18), rgba(139, 123, 255, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand-subtitle,
.section-subtitle,
.muted-copy {
  color: var(--app-text-muted);
}

.topbar-brand {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: inherit;
}

.topbar-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 0.28rem;
  flex-shrink: 0;
}

.topbar-nav-link {
  padding: 0.38rem 1.05rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--app-text-muted);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.topbar-nav-link:hover {
  color: var(--app-text);
  background: rgba(255, 255, 255, 0.07);
}

.topbar-nav-link.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
  box-shadow: 0 2px 10px rgba(102, 166, 255, 0.25);
}

.topbar-actions {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.topbar-user {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--app-text-muted);
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user-link {
  text-decoration: none;
}

.topbar-user-link:hover,
.topbar-user-link:focus {
  color: var(--app-text);
}

.topbar-token {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(102, 166, 255, 0.14);
  color: #dbe8ff;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.topbar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--app-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.topbar-logout:hover {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
  color: #f87171;
}

.mobile-nav-menu {
  display: none;
}

.topbar-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--app-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.topbar-menu-toggle:hover,
.topbar-menu-toggle:focus {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  color: var(--app-text);
}

.mobile-nav-dropdown {
  background: rgba(10, 20, 38, 0.96);
  border: 1px solid var(--app-border);
  backdrop-filter: blur(18px);
  border-radius: 0.9rem;
  padding: 0.35rem;
  min-width: 11.5rem;
}

.mobile-nav-dropdown .dropdown-item {
  border-radius: 0.65rem;
  color: var(--app-text);
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
}

.mobile-nav-dropdown .dropdown-item:hover,
.mobile-nav-dropdown .dropdown-item:focus {
  background: rgba(255, 255, 255, 0.08);
  color: var(--app-text);
}

.mobile-nav-dropdown .dropdown-item.active,
.mobile-nav-dropdown .dropdown-item:active {
  background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
  color: #fff;
}

.surface-card,
.surface-panel,
.hero-card,
.auth-card,
.composer-card,
.modal-content {
  background: var(--app-bg-elevated) !important;
  border: 1px solid var(--app-border) !important;
  backdrop-filter: blur(22px);
  box-shadow: var(--app-shadow);
}

.surface-card,
.surface-panel,
.hero-card,
.auth-card,
.composer-card {
  border-radius: var(--app-radius) !important;
}

.hero-card {
  overflow: hidden;
  position: relative;
}

.hero-card::after {
  content: "";
  position: absolute;
  inset: auto -10% -45% auto;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(102, 166, 255, 0.2), transparent 68%);
  pointer-events: none;
}

.hero-stat {
  min-width: 8rem;
  padding: 1rem;
  border-radius: 1.2rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.hero-stat-label {
  color: var(--app-text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-stat-value {
  font-size: 1.05rem;
  font-weight: 700;
}

.surface-panel .card-header,
.surface-card .card-header {
  background: transparent !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
  padding: 1rem 1.25rem;
}

.surface-panel .card-body,
.surface-card .card-body {
  padding: 1.1rem 1.2rem;
}

.app-btn-primary {
  background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
  border: 0;
  box-shadow: 0 14px 28px rgba(102, 166, 255, 0.2);
}

.app-btn-primary:hover,
.app-btn-primary:focus {
  background: linear-gradient(135deg, #78b0ff, #9b8cff);
}

.app-badge {
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08) !important;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.glass-input,
.glass-select,
.glass-textarea,
.glass-file {
  background: rgba(255, 255, 255, 0.04) !important;
  border: 1px solid rgba(255, 255, 255, 0.09) !important;
  color: var(--app-text) !important;
  border-radius: 1rem !important;
  min-height: 3rem;
}

.glass-input:focus,
.glass-select:focus,
.glass-textarea:focus,
.glass-file:focus {
  box-shadow: 0 0 0 0.25rem rgba(102, 166, 255, 0.18) !important;
  border-color: rgba(102, 166, 255, 0.65) !important;
}

.glass-textarea {
  min-height: 3.5rem;
  resize: none;
}

.chat-shell {
  display: grid;
  gap: 1rem;
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 48svh;
  max-height: calc(100svh - 23rem);
  overflow-y: auto;
  padding: 0.35rem 0.1rem 0.35rem 0;
  overscroll-behavior: contain;
}

.chat-empty {
  display: grid;
  place-items: center;
  min-height: 14rem;
  padding: 1.25rem;
  border-radius: 1.4rem;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  color: var(--app-text-muted);
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
}

.chat-msg {
  max-width: min(100%, 52rem);
  padding: 1rem 1rem 0.95rem;
  border-radius: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  line-height: 1.55;
  word-break: break-word;
}

.chat-user {
  align-self: flex-end;
  background: var(--app-user-soft);
  border-bottom-right-radius: 0.5rem;
}

.chat-assistant {
  align-self: flex-start;
  background: var(--app-success-soft);
  border-bottom-left-radius: 0.5rem;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
  color: var(--app-text-muted);
  font-size: 0.84rem;
}

.chat-role-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.75;
}

.markdown-content > :last-child {
  margin-bottom: 0;
}

.markdown-content p,
.markdown-content ul,
.markdown-content ol,
.markdown-content pre,
.markdown-content blockquote,
.markdown-content table {
  margin-bottom: 0.9rem;
}

.markdown-content ul,
.markdown-content ol {
  padding-left: 1.25rem;
}

.markdown-content a {
  color: #97c2ff;
  text-decoration: underline;
}

.markdown-content code {
  padding: 0.12rem 0.38rem;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.08);
  color: #d8e7ff;
}

.markdown-content pre {
  padding: 0.95rem 1rem;
  border-radius: 1rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
}

.markdown-content pre code {
  background: transparent;
  padding: 0;
}

.markdown-content blockquote {
  padding: 0.8rem 1rem;
  margin-left: 0;
  border-left: 3px solid rgba(102, 166, 255, 0.6);
  background: rgba(255, 255, 255, 0.03);
  color: #dce8f7;
}

.composer-card {
  position: sticky;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 15;
  padding: 0.9rem;
}

.composer-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.composer-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.analysis-list {
  max-height: min(62svh, 42rem);
  overflow-y: auto;
}

.analysis-item {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.06) !important;
  padding: 1rem 1.1rem;
}

.plan-card {
  border-radius: 1.25rem !important;
}

.plan-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.plan-price {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
}

/* JSON Viewer ───────────────────────────────────────────────────────────── */
.json-viewer-modal {
  background: #0b1624;
}

.json-viewer-body {
  overflow-x: auto;
}

.json-section {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.json-section:first-child {
  border-top: none;
}

.json-section-title {
  padding: 0.65rem 1.25rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--app-primary);
  opacity: 0.8;
}

.json-pre {
  margin: 0;
  padding: 0.5rem 1.25rem 1.1rem;
  font-size: 0.82rem;
  line-height: 1.65;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  color: #c9d8f0;
  background: transparent;
  border: none;
  white-space: pre;
  overflow-x: auto;
}

.json-key    { color: #79b8ff; }
.json-str    { color: #85e89d; }
.json-num    { color: #ffab70; }
.json-bool   { color: #b392f0; }
.json-null   { color: #959da5; font-style: italic; }
.json-bracket { color: #c9d8f0; opacity: 0.6; }
.json-colon  { color: #c9d8f0; opacity: 0.4; margin: 0 0.2em; }
.json-comma  { color: #c9d8f0; opacity: 0.35; }

.mobile-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1040;
  padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom));
  background: rgba(7, 17, 31, 0.86);
  backdrop-filter: blur(28px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-tabbar-inner {
  width: min(100%, 520px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.mobile-tabbar .btn {
  min-height: 3.25rem;
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  min-height: 100svh;
  padding: 1rem;
  display: grid;
  align-items: center;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1rem;
}

.auth-hero,
.auth-card {
  padding: 1.4rem;
}

.auth-hero {
  position: relative;
  overflow: hidden;
}

.auth-kicker {
  display: inline-flex;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--app-text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.auth-feature {
  padding: 0.95rem 1rem;
  border-radius: 1.2rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.auth-card {
  max-width: 480px;
  width: 100%;
  margin-left: auto;
}

.alert.app-alert {
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

#alertContainer {
  font-size: 0;
  line-height: 0;
}

#alertContainer:empty {
  display: none;
}

#alertContainer .alert {
  font-size: 0.875rem;
  line-height: 1.5;
}

.text-soft {
  color: var(--app-text-muted) !important;
}

@media (min-width: 992px) {
  .mobile-tabbar {
    display: none;
  }
}

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

  .topbar-user,
  .topbar-logout-desktop {
    display: none;
  }

  .topbar-token {
    font-size: 0.74rem;
    padding: 0.32rem 0.6rem;
  }

  .mobile-nav-menu {
    display: block;
  }

  .chat-box {
    min-height: 0;
    max-height: calc(100svh - 20rem);
  }
}

@media (max-width: 767.98px) {
  .topbar-inner,
  .app-shell {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .page-panels {
    margin-top: 0.4rem;
  }

  .topbar-user {
    display: none;
  }

  .hero-card .card-body,
  .surface-card .card-body,
  .surface-panel .card-body {
    padding: 1rem;
  }

  .chat-msg {
    max-width: 100%;
    padding: 0.95rem;
  }

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

  .composer-actions {
    justify-content: stretch;
  }

  .composer-actions .btn {
    width: 100%;
  }

  .analysis-list {
    max-height: none;
  }

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

  .auth-hero {
    min-height: 0;
  }

  .auth-card {
    max-width: none;
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }
}
