:root {
  --bg: #070b14;
  --surface: #0f1624;
  --panel: #141c2c;
  --border: #243049;
  --text: #e8eef7;
  --muted: #8fa3bd;
  --accent: #3dd6c6;
  --accent-dim: rgba(61, 214, 198, 0.14);
  --danger: #ff6b7a;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --tap: 44px;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #122038, transparent),
    radial-gradient(900px 500px at 100% 0%, #0d2430, transparent), var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

a { color: var(--accent); }
img, iframe, video { max-width: 100%; height: auto; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--accent-dim);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
  word-break: break-word;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
}

/* Mobile topbar — hidden on desktop */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  padding: 0.5rem 1rem;
  background: rgba(10, 14, 24, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.mobile-brand strong {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-sm {
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.menu-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.menu-toggle:hover,
.menu-toggle:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.menu-toggle-bars,
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
  position: relative;
}
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.menu-toggle-bars::before { top: -6px; }
.menu-toggle-bars::after { top: 6px; }

body.nav-open .menu-toggle-bars { background: transparent; }
body.nav-open .menu-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}
body.nav-open .menu-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  background: rgba(10, 14, 24, 0.92);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.25rem 0.35rem;
}
.logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(145deg, var(--accent), #2a9fd8);
  color: #041018;
  flex-shrink: 0;
}
.nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  min-height: var(--tap);
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover { background: var(--accent-dim); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.sidebar-foot { margin-top: auto; padding: 0.5rem; }

.main {
  padding: 1.75rem 2rem 3rem;
  max-width: 1100px;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}
.view { display: none; }
.view.active { display: block; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  letter-spacing: -0.02em;
  line-height: 1.25;
  word-wrap: break-word;
}
.lede { margin: 0; color: var(--muted); max-width: 42rem; font-size: 0.98rem; }
.row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.card, .panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  min-width: 0;
}
.card h2 { margin: 0 0 0.5rem; font-size: 1.1rem; color: var(--accent); }
.card p { margin: 0; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { margin: 0.35rem 0 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  min-height: var(--tap);
  width: 100%;
  max-width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(61, 214, 198, 0.35);
  border-color: var(--accent);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  min-height: var(--tap);
  font: inherit;
  cursor: pointer;
  align-self: flex-start;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: linear-gradient(145deg, #2fc4b4, #2496c7);
  border-color: transparent;
  color: #041018;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.split {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  min-height: 420px;
  width: 100%;
}
#view-site .split { grid-template-columns: minmax(260px, 320px) 1fr; }

.thread-list { overflow: auto; max-height: 70vh; padding: 0.5rem; }
.thread-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: var(--tap);
  padding: 0.65rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  -webkit-tap-highlight-color: transparent;
}
.thread-item:hover, .thread-item.active { background: var(--accent-dim); color: var(--text); }

.chat-pane { display: flex; flex-direction: column; min-height: 70vh; min-width: 0; }
.messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.25rem 0 1rem;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: min(85%, 36rem);
  padding: 0.75rem 0.95rem;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.bubble.user {
  align-self: flex-end;
  background: #1a3350;
  border: 1px solid #2a4a6e;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: end;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}
.image-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.image-card img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; background: #000; }
.image-card figcaption {
  padding: 0.65rem 0.8rem;
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-word;
}

.preview-frame {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.pill {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}
.pill.warn { background: rgba(255, 107, 122, 0.15); color: var(--danger); }
.status-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  overflow: auto;
  font-size: 0.85rem;
  max-height: 280px;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}
.checklist { margin: 0; padding-left: 1.2rem; color: var(--muted); }
.checklist li { margin: 0.4rem 0; }

.turnstile-placeholder {
  margin-top: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.02);
}

/* Tablet / narrow desktop */
@media (max-width: 960px) {
  .split,
  #view-site .split {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .thread-list {
    max-height: 180px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .thread-item {
    flex: 0 0 auto;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-pane { min-height: 55vh; }
  .preview-frame { min-height: 360px; }
}

/* Phone: hamburger drawer nav */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .mobile-topbar {
    display: flex;
    grid-column: 1;
    grid-row: 1;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar-backdrop[hidden] {
    display: none;
  }
  body.nav-open .sidebar-backdrop[hidden] {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 86vw);
    height: 100vh;
    height: 100dvh;
    padding-top: calc(1.25rem + var(--safe-top));
    padding-bottom: calc(1rem + var(--safe-bottom));
    padding-left: calc(1rem + var(--safe-left));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--border);
    box-shadow: none;
  }
  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  .main {
    grid-column: 1;
    grid-row: 2;
    padding: 1.1rem 1rem calc(2rem + var(--safe-bottom));
    max-width: 100%;
  }

  .page-header.row {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header.row .btn {
    width: 100%;
    text-align: center;
  }

  .composer {
    grid-template-columns: 1fr;
  }
  .composer .btn {
    width: 100%;
    justify-self: stretch;
  }

  .btn {
    width: auto;
    max-width: 100%;
  }
  .stack > .btn.primary,
  form .btn.primary {
    width: 100%;
    text-align: center;
  }

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

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

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

@media (max-width: 480px) {
  body { font-size: 15px; }
  .page-header h1 { font-size: 1.3rem; }
  .lede { font-size: 0.92rem; }
  .card, .panel { padding: 1rem; }
  .bubble { max-width: 92%; }
  .preview-frame { min-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* Mobile chat thread strip — avoid ugly clipped scrollbar */
@media (max-width: 860px) {
  .thread-list {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding: 0.35rem 0.25rem 0.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .thread-list::-webkit-scrollbar { height: 4px; }
  .thread-item {
    flex: 0 0 auto;
    max-width: 11rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Contact / disclaimer / footer */
.contact-line {
  margin-top: 0.65rem !important;
  font-size: 0.9rem;
  color: var(--text) !important;
}
.disclaimer-inline {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}
.site-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.footer-disclaimer {
  margin: 0 0 0.5rem;
  max-width: 48rem;
}
.turnstile-slot {
  margin-top: 0.5rem;
  min-height: 2.5rem;
}
.turnstile-live {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.02);
  overflow: auto;
}
