:root {
  --bg: #020202;
  --bg-strong: #080808;
  --surface: rgba(10, 10, 10, 0.95);
  --surface-strong: #141414;
  --surface-soft: rgba(255, 255, 255, 0.03);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5f5;
  --muted: #9b9b9b;
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.12);
  --amber: #d7d7d7;
  --amber-soft: rgba(255, 255, 255, 0.08);
  --danger: #d0d0d0;
  --danger-soft: rgba(255, 255, 255, 0.08);
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
  --radius: 26px;
  --radius-md: 20px;
  --radius-sm: 16px;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --body: "Avenir Next", "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.04), transparent 30%),
    linear-gradient(180deg, #020202 0%, #090909 100%);
  color: var(--text);
  font-family: var(--body);
}

body {
  min-height: 100vh;
}

#app {
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.82rem 1.15rem;
  background: var(--accent);
  color: #050505;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.45;
  transform: none;
  cursor: not-allowed;
}

.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.ghost--small {
  padding: 0.66rem 0.9rem;
}

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

a {
  color: var(--accent);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--text);
  padding: 0.95rem 1rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(255, 255, 255, 0.26);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}

.field--compact input {
  border-radius: 999px;
}

.shell {
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

.sidebar,
.topbar,
.chat-frame,
.panel,
.composer,
.hero-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.sidebar {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
  z-index: 20;
  padding: 1.15rem;
  display: grid;
  align-content: start;
  gap: 1rem;
  transform: translateX(-104%);
  transition: transform 220ms ease;
}

.shell--mobile-view-threads .sidebar {
  transform: translateX(0);
}

.main-pane {
  min-height: 100vh;
  height: 100vh;
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1rem 6.5rem;
  display: grid;
  align-content: start;
  gap: 1rem;
}

.shell--mobile-view-threads .main-pane {
  display: none;
}

.sidebar h1,
.topbar h2,
.hero-panel h1,
.chat-frame h3 {
  font-family: var(--display);
  font-weight: 600;
}

.sidebar__top,
.topbar,
.topbar__status,
.thread-card__head,
.request-card__header,
.item-card__row,
.turn__header,
.composer__actions,
.request-actions,
.sidebar-actions,
.chat-frame__header,
.chat-frame__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.sidebar__meta {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.9rem;
}

.sidebar-actions {
  flex-wrap: wrap;
}

.sidebar__mini-actions,
.sidebar__health {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.sidebar-health-card {
  width: 100%;
  display: grid;
  gap: 0.3rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.84rem;
}

.thread-list {
  display: grid;
  gap: 0.8rem;
  padding-bottom: 1.5rem;
}

.thread-card {
  text-align: left;
  display: grid;
  gap: 0.55rem;
  padding: 0.95rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid transparent;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.16);
}

.thread-card--selected {
  border-color: rgba(255, 255, 255, 0.22);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
}

.thread-card h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.thread-card__agent,
.thread-card__meta,
.request-copy,
.request-meta,
.bubble__label,
.terminal-meta,
.item-card p,
.empty-state p {
  color: var(--muted);
}

.thread-card__meta {
  display: grid;
  gap: 0.18rem;
  font-size: 0.8rem;
}

.thread-card__pending {
  justify-self: start;
  padding: 0.32rem 0.62rem;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.76rem;
  font-weight: 700;
}

.topbar,
.chat-frame,
.panel,
.composer {
  border-radius: var(--radius);
}

.topbar,
.chat-frame,
.panel,
.composer {
  padding: 1rem 1.1rem;
}

.topbar {
  position: sticky;
  top: 0.9rem;
  z-index: 10;
}

.topbar__title {
  min-width: 0;
}

.topbar__title h2 {
  line-height: 1.05;
}

.topbar__status {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mobile-nav {
  display: flex;
  gap: 0.55rem;
}

.mobile-nav button {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.mobile-nav button.is-active {
  background: var(--accent);
  color: #050505;
}

.chat-frame {
  display: grid;
  gap: 1rem;
  min-height: 24rem;
  min-width: 0;
  overflow-x: hidden;
}

.chat-frame__body {
  display: grid;
  gap: 0.95rem;
  min-width: 0;
  overflow-x: hidden;
}

.chat-frame__header {
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.chat-frame__meta {
  align-items: flex-start;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.88rem;
}

.chat-frame__sync {
  color: var(--muted);
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-frame__actions {
  display: flex;
  justify-content: flex-start;
}

.timeline,
.turn__items,
.requests-grid {
  display: grid;
  gap: 0.9rem;
}

.turn {
  display: grid;
  gap: 0.8rem;
}

.turn + .turn {
  padding-top: 1rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.turn__header h3 {
  font-size: 0.96rem;
}

.bubble,
.item-card,
.request-card,
.empty-state {
  border-radius: var(--radius-md);
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.bubble {
  display: grid;
  gap: 0.45rem;
  max-width: min(46rem, 100%);
  min-width: 0;
}

.bubble p,
.item-card p,
.empty-state p,
.request-copy {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.bubble--user {
  margin-left: auto;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
}

.bubble--agent {
  border-left: 4px solid rgba(255, 255, 255, 0.16);
}

.bubble--final {
  border-left-color: rgba(255, 255, 255, 0.24);
}

.bubble--optimistic {
  opacity: 0.78;
}

.bubble__label {
  font-size: 0.8rem;
  font-weight: 700;
}

.item-card__title {
  font-weight: 700;
}

.item-card pre,
.json-panel pre {
  margin-top: 0.7rem;
  overflow: auto;
  max-height: 12rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
}

.item-card--terminal {
  background: #060606;
  color: #f2f2f2;
}

.item-card--terminal .status-chip {
  background: rgba(255, 255, 255, 0.12);
  color: #f2f2f2;
}

.command-line {
  display: block;
  margin-top: 0.7rem;
  font-family: var(--mono);
  font-size: 0.84rem;
}

.agent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.agent-pill {
  min-width: 10rem;
  display: grid;
  gap: 0.22rem;
  padding: 0.8rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.request-form {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.request-actions {
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.meta-list {
  margin: 0.85rem 0 0;
  padding-left: 1.15rem;
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
}

.section-heading {
  margin-bottom: 0.9rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.72rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.status-chip--accent {
  background: rgba(255, 255, 255, 0.16);
}

.status-chip--warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-chip--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.composer {
  position: sticky;
  bottom: 1rem;
  padding: 0.85rem;
}

.composer--chat {
  position: static;
  bottom: auto;
  padding: 1rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
}

.jump-to-latest {
  position: sticky;
  bottom: 0.5rem;
  display: flex;
  justify-content: center;
  z-index: 8;
}

.jump-to-latest--hidden {
  display: none;
}

.jump-to-latest button {
  box-shadow: var(--shadow);
}

.composer__workspace {
  margin-bottom: 0.75rem;
}

.composer__actions {
  align-items: flex-end;
}

.composer__field {
  flex: 1;
}

.composer__field span {
  display: none;
}

.composer textarea {
  resize: vertical;
  min-height: 3.4rem;
  max-height: 10rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
}

.empty-state {
  display: grid;
  gap: 0.45rem;
}

.error-banner {
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.notice-banner {
  margin-top: 0.75rem;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.notice-banner--warn {
  background: var(--amber-soft);
  color: var(--amber);
}

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

.hero-panel {
  width: min(34rem, 100%);
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.1), transparent 38%),
    radial-gradient(circle at bottom left, rgba(255, 255, 255, 0.06), transparent 36%),
    var(--surface);
}

.hero-panel h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 0.95;
}

.login-form {
  display: grid;
  gap: 0.9rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 980px) {
  .shell {
    display: grid;
    grid-template-columns: 24rem minmax(0, 1fr);
    gap: 1rem;
    width: min(100%, 100rem);
    margin: 0 auto;
    padding: 1rem;
  }

  .sidebar {
    position: sticky;
    top: 1rem;
    height: calc(100vh - 2rem);
    width: auto;
    transform: none;
    border-radius: var(--radius);
  }

  .main-pane {
    min-height: auto;
    height: calc(100vh - 2rem);
    padding: 0;
  }

  .mobile-nav {
    display: none;
  }
}

@media (max-width: 979px) {
  html,
  body {
    background: #050505;
  }

  .sidebar,
  .topbar,
  .chat-frame,
  .panel,
  .composer,
  .hero-panel {
    backdrop-filter: none;
    box-shadow: none;
    background: #0a0a0a;
  }

  button,
  .thread-card {
    transition: none;
  }

  button:hover {
    transform: none;
  }

  .topbar {
    position: static;
    top: auto;
  }

  .topbar__status {
    justify-content: flex-start;
  }

  .composer {
    position: static;
    bottom: auto;
  }

  .composer__actions {
    flex-wrap: wrap;
  }

  .composer__field {
    width: 100%;
    flex-basis: 100%;
  }
}
