:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --surface: #11151d;
  --surface-2: #171c26;
  --border: #222938;
  --text: #e9edf5;
  --muted: #8a94a8;
  --accent: #3b82f6;
  --primary: #2563eb;
  --mine: #1d4ed8;
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

.wrap {
  max-width: 1180px;
  height: 100dvh;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; }
.title { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: 0.02em; }
.brand-icon { display: block; flex: none; }
.auth-wordmark { display: block; max-width: 100%; height: auto; margin: 0 auto; }

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.live-dot.up { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15); }
.live-dot.down { background: var(--danger); }

.stats { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.stats::-webkit-scrollbar { display: none; }

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
  font-size: 12px;
}
.stat-label { color: var(--muted); }
.stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.good .stat-value { color: var(--ok); }
.score-btn { font: inherit; font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer; }
.score-btn:hover:not(:disabled) { border-color: var(--muted); }
.score-btn:disabled { opacity: .6; cursor: progress; }

.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.subtle-link, .subtle-btn {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  padding: 4px 6px;
  white-space: nowrap;
}
.subtle-link:hover, .subtle-btn:hover { color: var(--text); }

/* ---------- Auth ---------- */

.auth {
  width: 100%;
  max-width: 360px;
  margin: 48px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.email-form { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Goals ladder ---------- */

.goals { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.goals summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; cursor: pointer; }
.goal-current { font-weight: 600; }
.goals progress { flex: 1; min-width: 120px; height: 8px; accent-color: var(--ok); }
.goal-list { margin: 8px 0 0; padding-left: 20px; max-height: 40dvh; overflow-y: auto; word-break: break-word; }
.goal { margin-bottom: 8px; }
.goal.achieved strong { color: var(--ok); }
.goal.current strong { color: var(--accent); }

/* ---------- Workspace ---------- */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
}

.tabs { display: none; }

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-label { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.panel-meta { font-size: 12px; color: var(--muted); }

.scroll-box {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Feed entries */
.entry {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  word-break: break-word;
  font-size: 13px;
}
.entry-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; justify-content: space-between; gap: 8px; }
.entry.is-error { border-color: rgba(248, 113, 113, 0.45); }

/* ---------- Chat ---------- */

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.msg.mine { justify-content: flex-end; }

.avatar, .empty-mark {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #04120c;
  background: linear-gradient(135deg, #34d399, #3b82f6);
}

.bubble {
  max-width: min(85%, 640px);
  padding: 10px 13px 6px;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  word-break: break-word;
}
.msg.theirs .bubble { border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); border-color: var(--mine); border-bottom-right-radius: 6px; color: #fff; }
.bubble.is-error { border-color: rgba(248, 113, 113, 0.6); }

.plain { white-space: pre-wrap; }

.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md strong { font-weight: 650; }
.md code { font-size: 0.9em; padding: 1px 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.08); }
.md a { color: #93c5fd; word-break: break-all; }

.time { font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }
.msg.mine .time { color: rgba(255, 255, 255, 0.7); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid rgba(52, 211, 153, 0.45); color: var(--ok); background: rgba(52, 211, 153, 0.06); }
.chip.fail { border-color: rgba(248, 113, 113, 0.5); color: var(--danger); background: rgba(248, 113, 113, 0.06); }

.retry {
  margin: 2px 0 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.bubble.thinking { display: flex; align-items: center; gap: 8px; padding: 10px 13px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.7; } }

.empty { margin: auto; text-align: center; max-width: 420px; padding: 24px 8px; }
.empty .empty-mark { width: 44px; height: 44px; font-size: 20px; margin: 0 auto 10px; }
.empty h2 { margin: 0 0 6px; font-size: 18px; }

.suggestions {
  display: flex;
  gap: 8px;
  padding: 6px 12px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestion {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.suggestion:hover { border-color: var(--accent); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 160px;
  overflow-y: hidden;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
}
textarea:focus { outline: none; border-color: var(--accent); }

.send {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send:disabled { opacity: 0.45; cursor: not-allowed; }
.send:focus-visible, .tab:focus-visible, .suggestion:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Forms ---------- */

input[type="text"], input[type="email"], input[type="password"] {
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
}
input:focus { outline: none; border-color: var(--accent); }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.muted { color: var(--muted); margin: 0; }
.status-text { margin: 0; font-size: 13px; color: var(--muted); }
.status-text.error { color: var(--danger); }

/* ---------- Phone ---------- */

@media (max-width: 860px) {
  .wrap { padding: 10px 10px 0; gap: 8px; }
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding-bottom: 8px; }
  .stats { order: 3; flex-basis: 100%; }
  .subtle-link { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
  .tabs {
    display: flex;
    gap: 4px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
  }
  .tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 7px;
    border-radius: 9px;
    cursor: pointer;
  }
  .tab[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
  .workspace[data-tab="chat"] .activity-panel,
  .workspace[data-tab="activity"] .chat-panel { display: none; }
  .panel { border-radius: 12px 12px 0 0; border-bottom: none; }
  .chat-panel .panel-head { display: none; }
  .bubble { max-width: 88%; }
}

/* ---------- Motion ---------- */

/* Only elements that stay in the page are animated; chat and feed rows are rebuilt on every poll. */
@media (prefers-reduced-motion: no-preference) {
  .brand-icon, .auth-wordmark { animation: nexos-rise 0.45s ease-out both; }
  .auth, .panel { animation: nexos-rise 0.3s ease-out both; }
  .live-dot.up { animation: nexos-pulse 2.4s ease-in-out infinite; }
  .send, .btn, .suggestion { transition: transform 0.12s ease, border-color 0.12s ease; }
  .send:active:not(:disabled), .btn:active:not(:disabled), .suggestion:active { transform: scale(0.96); }
}
@keyframes nexos-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes nexos-pulse { 50% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.05); } }
/* ---------- Activity sections ---------- */

.feed-section {
  margin: 8px 2px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.feed-section:first-child { margin-top: 0; }
.feed-count { padding: 0 7px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); letter-spacing: 0; }
.entry.is-note { border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.04); }
.entry.state-succeeded .entry-meta span:first-child { color: var(--ok); }
.entry.state-running .entry-meta span:first-child,
.entry.state-reviewing .entry-meta span:first-child { color: #93c5fd; }
.entry.state-interrupted { opacity: 0.7; }
.panel-meta.warn { color: #fbbf24; }

/* ---------- Phone: scores as a compact grid, comfortable tap targets ---------- */

@media (max-width: 860px) {
  .stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; overflow: visible; }
  .stat {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    min-height: 42px;
    padding: 4px;
    border-radius: 10px;
    font-size: 11px;
  }
  .stat-label { font-size: 10.5px; }
  .stat-value { font-size: 14px; }
  .score-btn { font-size: 12px; }
  .subtle-btn { min-height: 40px; padding: 8px 10px; }
}

/* ---------- Update toast (shown just before the page reloads onto a new build) ---------- */
.update-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 1000;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

/* ---------- AgorOs loading screen, chat logo ---------- */

/* Shown until the first view is ready (minimal.js adds .done). If the script never runs, it fades on its own. */
.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.boot.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-mark { position: relative; width: 104px; height: 104px; display: grid; place-items: center; }
.boot-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(52, 211, 153, 0.15);
  border-top-color: var(--ok);
  border-right-color: var(--accent);
}
.boot-text { margin: 0; font-size: 14px; color: var(--muted); letter-spacing: 0.02em; }
.panel-logo { display: inline-block; vertical-align: -4px; margin-right: 7px; }
.avatar.logo { background: none; overflow: hidden; }
.avatar.logo img { display: block; width: 100%; height: 100%; }

@media (prefers-reduced-motion: no-preference) {
  .boot-ring { animation: nexos-spin 0.9s linear infinite; }
  .boot-mark img { animation: nexos-breathe 1.6s ease-in-out infinite; }
  .boot { animation: nexos-boot-timeout 0.35s ease 12s forwards; }
  .avatar.logo.is-thinking img { animation: nexos-breathe 1.2s ease-in-out infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .boot { animation: nexos-boot-timeout 0.01s linear 12s forwards; }
}
@keyframes nexos-spin { to { transform: rotate(360deg); } }
@keyframes nexos-breathe { 50% { transform: scale(0.9); opacity: 0.8; } }
@keyframes nexos-boot-timeout { to { opacity: 0; visibility: hidden; pointer-events: none; } }
