:root {
  /* Surface layers */
  --porcelain: oklch(0.985 0.003 80);
  --linen:     oklch(0.975 0.004 80);
  --parchment: oklch(0.96 0.005 80);
  --sand:      oklch(0.92 0.006 80);
  --champagne: oklch(0.88 0.007 80);

  /* Ink & text */
  --ink:       oklch(0.13 0 0);
  --ink-soft:  oklch(0.38 0 0);
  --muted:     oklch(0.5 0 0);

  /* Lines & borders */
  --line:        oklch(0.88 0 0 / 0.92);
  --line-strong: oklch(0.75 0 0 / 0.92);

  /* Paper surfaces */
  --paper:        oklch(0.995 0 0 / 0.94);
  --paper-strong: oklch(0.99 0 0 / 0.97);

  /* Shadows */
  --shadow-lg: 0 30px 80px oklch(0 0 0 / 0.08),
               0 8px 24px oklch(0 0 0 / 0.04);
  --shadow-md: 0 18px 42px oklch(0 0 0 / 0.06),
               0 4px 12px oklch(0 0 0 / 0.03);
  --shadow-sm: 0 10px 24px oklch(0 0 0 / 0.05),
               0 2px 6px oklch(0 0 0 / 0.02);

  /* Radii */
  --radius-shell: 2rem;
  --radius-panel: 1.5rem;
  --radius-soft:  1.1rem;
  --radius-pill:  999px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, oklch(0.95 0.005 80), transparent 70%),
    var(--porcelain);
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ── Shell ── */

.shell {
  width: min(1240px, calc(100vw - 2rem));
  margin: 0 auto;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.75rem;
  padding: clamp(0.75rem, 1.5vw, 1.5rem) 0;
}

/* ── Top bar ── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.65rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-shell);
  background: white;
  box-shadow: var(--shadow-lg);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.brand-seal {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  color: white;
  background: var(--ink);
  box-shadow: 0 6px 16px oklch(0 0 0 / 0.12);
}

.topbar-brand-text {
  display: grid;
  gap: 0.05rem;
}

.topbar-title {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.topbar-subtitle {
  font-size: 0.72rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Workspace ── */

.workspace {
  display: grid;
  grid-template-columns: 1fr 0px;
  transition: grid-template-columns 350ms cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 0;
  overflow: hidden;
}

.workspace.debug-open {
  grid-template-columns: 1fr 420px;
}

/* ── Panels ── */

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-md);
  animation: reveal-up 340ms ease both;
}

.panel-chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.panel-chat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--ink);
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
}

.panel-debug {
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 150ms ease;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  padding: 1.2rem;
}

.workspace.debug-open .panel-debug {
  opacity: 1;
  transition: opacity 200ms ease 150ms;
  pointer-events: auto;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.panel h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 700;
  margin: 0;
  line-height: 1.05;
}

/* ── Conversation bar ── */

.conversation-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  background: var(--linen);
  border-radius: var(--radius-soft);
  border-bottom: 1px solid var(--line);
}

.conversation-bar strong {
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--ink-soft);
  word-break: break-all;
}

.conversation-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-shrink: 0;
}

/* ── Messages ── */

.messages {
  overflow: auto;
  min-height: 0;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  align-content: end;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}

.bubble {
  width: min(85%, 36rem);
  padding: 0.95rem 1.15rem;
  border-radius: 1.35rem 1.35rem 1.35rem 0.35rem;
  background: white;
  border: 1px solid var(--line);
  justify-self: start;
  box-shadow: 0 2px 8px oklch(0 0 0 / 0.04);
}

.bubble span {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.bubble.outgoing {
  justify-self: end;
  background: var(--ink);
  border-color: transparent;
  border-radius: 1.35rem 1.35rem 0.35rem 1.35rem;
  color: white;
  box-shadow: 0 4px 16px oklch(0 0 0 / 0.15);
}

.bubble.outgoing span {
  color: oklch(0.7 0 0);
}

.bubble p {
  margin: 0.5rem 0 0;
  line-height: 1.55;
}

.bubble-media {
  display: block;
  width: 100%;
  margin-top: 0.85rem;
  border-radius: 1rem;
  border: 1px solid var(--line);
  object-fit: cover;
}

.bubble-file,
.bubble-location {
  display: block;
  margin-top: 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: 1rem;
  background: white;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.bubble.outgoing .bubble-file,
.bubble.outgoing .bubble-location {
  background: oklch(0.2 0 0);
  border-color: oklch(0.3 0 0);
  color: white;
}

.bubble-location strong {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.bubble.outgoing .bubble-location strong {
  color: oklch(0.65 0 0);
}

.bubble-location p {
  margin-top: 0.45rem;
  word-break: break-word;
}

/* ── Typing indicator ── */

.typing-indicator {
  display: grid;
  grid-template-columns: repeat(3, 0.35rem);
  gap: 0.2rem;
  padding: 0.4rem 0;
}

.typing-indicator span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite;
}

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

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

@keyframes typing-bounce {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-0.35rem);
  }
}

/* ── Composer ── */

.composer {
  display: flex;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  background: white;
  border-radius: 0 0 var(--radius-panel) var(--radius-panel);
}

.composer textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-soft);
  background: var(--linen);
  padding: 0.75rem 1rem;
  resize: none;
  box-shadow: inset 0 1px 0 oklch(0 0 0 / 0.04);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
  min-height: 2.75rem;
  max-height: 6rem;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 4px oklch(0 0 0 / 0.06);
  background: white;
}

.composer button[type="submit"] {
  align-self: flex-end;
  padding: 0.75rem 1.1rem;
  font-weight: 800;
  font-size: 0.84rem;
  letter-spacing: -0.02em;
  box-shadow: 0 14px 28px oklch(0 0 0 / 0.12);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.composer button[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px oklch(0 0 0 / 0.16);
}

.composer button[type="submit"]:active {
  transform: translateY(0);
}

/* ── Debug panel ── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0 0 0.85rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.85rem;
}

.stats-grid div {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-soft);
  background: white;
  border: 1px solid var(--line);
}

.stats-grid span {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.stats-grid strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.5rem;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.debug-log {
  overflow: auto;
  min-height: 0;
  display: grid;
  gap: 0.65rem;
  flex: 1;
}

.debug-log::-webkit-scrollbar {
  width: 6px;
}

.debug-log::-webkit-scrollbar-track {
  background: transparent;
}

.debug-log::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}

.trace {
  padding: 0.85rem;
  border-radius: var(--radius-soft);
  background: var(--parchment);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}

.trace::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--ink);
}

.trace span {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.trace pre {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--ink-soft);
  background: white;
  padding: 0.6rem 0.75rem;
  border-radius: 0.65rem;
  border: 1px solid var(--line);
}

/* ── Buttons ── */

textarea,
button,
select {
  font: inherit;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-soft);
  background: white;
  padding: 0.9rem 1rem;
  resize: vertical;
}

button {
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: white;
  padding: 0.84rem 1.18rem;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: -0.02em;
  box-shadow: 0 14px 28px oklch(0 0 0 / 0.12);
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease, background 180ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px oklch(0 0 0 / 0.16);
}

button:active {
  transform: translateY(0);
}

button.ghost,
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.55rem 0.9rem;
}

button.ghost:hover {
  background: oklch(0.97 0 0);
  box-shadow: var(--shadow-sm);
  border-color: var(--line);
}

button.ghost.active {
  background: var(--ink);
  color: white;
  border-color: transparent;
}

button.ghost.active:hover {
  background: oklch(0.2 0 0);
}

/* ── Dashboard link ── */

.dashboard-link {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 0.55rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  background: white;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.dashboard-link:hover {
  background: oklch(0.97 0 0);
  box-shadow: var(--shadow-sm);
}

/* ── Debug backdrop (mobile) ── */

.debug-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.3);
  z-index: 15;
  backdrop-filter: blur(2px);
}

.workspace.debug-open ~ .debug-backdrop {
  display: none;
}

/* ── Utilities ── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Animations ── */

@keyframes reveal-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Prompt chips ── */

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
  align-items: center;
}

.prompt-chips-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}

.prompt-chip {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-pill);
  background: white;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
  box-shadow: none;
}

.prompt-chip:hover {
  border-color: var(--ink);
  background: var(--linen);
  transform: none;
  box-shadow: none;
}

/* ── Responsive ── */

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace.debug-open {
    grid-template-columns: 1fr;
  }

  .panel-debug {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 360px;
    max-width: 90vw;
    z-index: 20;
    border-radius: var(--radius-shell) 0 0 var(--radius-shell);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 350ms cubic-bezier(0.4, 0, 0.2, 1), opacity 200ms ease;
  }

  .workspace.debug-open .panel-debug {
    display: flex;
    transform: translateX(0);
    opacity: 1;
  }

  .workspace.debug-open ~ .debug-backdrop {
    display: block;
  }

  .topbar {
    gap: 0.65rem;
    padding: 0.55rem 0.85rem;
  }

  .topbar-subtitle {
    display: none;
  }

  .messages {
    max-height: none;
    min-height: 20rem;
  }
}

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