:root {
  color-scheme: dark;
  --bg: #0a0e13;
  --panel: #111821;
  --panel-2: #0e151d;
  --panel-3: #16212d;
  --text: #e6edf5;
  --muted: #8b98a8;
  --line: #223041;
  --line-soft: #1a2532;
  --accent: #6ee7b7;
  --accent-ink: #052e24;
  --danger: #fb7185;
  --warn: #fbbf24;
  --info: #93c5fd;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(110, 231, 183, 0.08), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(147, 197, 253, 0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 18px;
  letter-spacing: -0.01em;
}

h3 {
  margin: 22px 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h4 {
  margin: 16px 0 6px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

code,
pre,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

/* Boot */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Login */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px;
  background: linear-gradient(180deg, rgba(22, 33, 45, 0.9), rgba(17, 24, 33, 0.95));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 26px;
  font-weight: 800;
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

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

.status.ok {
  color: var(--accent);
}

/* App shell */

.app {
  height: 100dvh;
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 10px;
}

.topbar-title h1 {
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(139, 152, 168, 0.12);
}

.dot.online {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(110, 231, 183, 0.14);
}

.dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.14);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 18px;
}

.icon-btn:active {
  transform: translateY(1px);
}

.main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view {
  height: 100%;
  overflow: auto;
  padding: 0 18px 20px;
  animation: fade-in 0.16s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-view {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 10px;
}

.session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 2px 18px;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(86%, 720px);
  padding: 10px 13px;
  border-radius: 16px;
  animation: bubble-in 0.16s ease-out;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-user {
  align-self: flex-end;
  background: #12352c;
  border: 1px solid #1f5a49;
  border-bottom-right-radius: 6px;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg-role {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-tool {
  align-self: stretch;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.msg-tool summary {
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.msg-tool pre {
  max-height: 240px;
  overflow: auto;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text);
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 6px 2px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.welcome {
  margin: auto;
  max-width: 520px;
  padding: 24px 8px;
  text-align: center;
}

.welcome .brand-mark {
  margin: 0 auto 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
}

.chip:active {
  border-color: var(--accent);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10, 14, 19, 0.5), var(--bg) 30%);
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.composer textarea:focus {
  border-color: #3a566f;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.1);
}

.send {
  width: 48px;
  height: 44px;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 800;
}

/* Nav */

.nav {
  display: flex;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(10, 14, 19, 0.96);
  backdrop-filter: blur(12px);
}

.nav-btn {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.nav-btn span:first-child {
  font-size: 18px;
  line-height: 1;
}

.nav-btn.active {
  color: var(--text);
  background: var(--panel-2);
}

.badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 24px);
  min-width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #2b0710;
  font-size: 10px;
  font-weight: 800;
}

/* Sections and cards */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 14px;
}

.section-head h2 {
  font-size: 20px;
}

.card,
.panel,
.approval-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.approval-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.approval-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.approval-card h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  text-transform: none;
  letter-spacing: -0.01em;
}

.approval-summary {
  color: var(--text);
}

.approval-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.approval-actions {
  display: flex;
  gap: 8px;
  padding-top: 2px;
}

.approval-actions .btn {
  flex: 1;
}

.payload {
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

.payload summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}

.payload pre {
  max-height: 220px;
  overflow: auto;
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.risk-high {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.risk-medium {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
}

.risk-low {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.35);
  background: rgba(110, 231, 183, 0.08);
}

.status-live,
.status-preview {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.35);
}

.status-building,
.status-spec,
.status-discovery {
  color: var(--info);
  border-color: rgba(147, 197, 253, 0.35);
}

.status-archived,
.status-paused {
  color: var(--muted);
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.project-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.project-top h3 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  text-transform: none;
  letter-spacing: -0.01em;
}

.project-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.budget {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.budget-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

progress {
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  appearance: none;
  background: var(--panel-3);
}

progress::-webkit-progress-bar {
  background: var(--panel-3);
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  border-radius: 999px;
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--accent), #38bdf8);
}

.project-actions {
  display: flex;
  gap: 8px;
}

.project-actions .btn {
  flex: 1;
}

.empty {
  padding: 34px 12px;
  color: var(--muted);
  text-align: center;
}

.panel {
  overflow: auto;
}

.panel pre {
  font-size: 12px;
  color: var(--text);
}

.stat {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.stat.small strong {
  font-size: 14px;
  color: var(--text);
}

/* Buttons and fields */

.btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 650;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: #3a566f;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.1);
}

/* Sheet */

.sheet,
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop,
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82dvh;
  overflow: auto;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(calc(100% - 32px), 420px);
  max-height: 86dvh;
  overflow: auto;
  transform: translate(-50%, -50%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.session-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
}

.session-row.active {
  border-color: rgba(110, 231, 183, 0.4);
}

.session-row span {
  color: var(--muted);
  font-size: 12px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(calc(100% - 32px), 480px);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-3);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-color: rgba(251, 113, 133, 0.4);
}

/* Desktop */

@media (min-width: 900px) {
  .app {
    height: 100vh;
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "nav topbar"
      "nav main";
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .topbar {
    grid-area: topbar;
    padding: 22px 26px 12px;
  }

  .main {
    grid-area: main;
  }

  .view {
    padding: 0 26px 24px;
  }

  .nav {
    grid-area: nav;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 22px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
    background: rgba(14, 21, 29, 0.6);
    backdrop-filter: none;
  }

  .nav-btn {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 11px 14px;
    font-size: 13px;
  }

  .nav-btn span:first-child {
    width: 22px;
    font-size: 17px;
    text-align: center;
  }

  .badge {
    position: static;
    margin-left: auto;
  }

  .sheet-panel {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(calc(100% - 48px), 520px);
    max-height: 80vh;
    transform: translate(-50%, -50%);
    border: 1px solid var(--line);
    border-radius: 20px;
  }

  .toast {
    bottom: 28px;
  }

  .msg {
    max-width: min(76%, 760px);
  }
}

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