:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #27312d;
  background: #f5f3ed;
  --canvas: #f5f3ed;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --line: #dedbd2;
  --line-strong: #c8c4b9;
  --muted: #6d746f;
  --accent: #2f6b55;
  --accent-strong: #24523f;
  --accent-soft: #e3eee8;
  --danger: #9e453f;
  --shadow: 0 12px 36px rgba(45, 54, 49, 0.13);
  --topbar-height: 68px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 0;
  background: var(--canvas);
}

button,
input,
textarea {
  font: inherit;
}

button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: inherit;
  background: var(--surface-strong);
  cursor: pointer;
}

button:hover {
  border-color: #9ba39e;
  background: #faf9f5;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(47, 107, 85, 0.28);
  outline-offset: 2px;
}

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

h1 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.55rem, 2.7vw, 2.15rem);
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: 1.2rem;
}

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

.skip:focus {
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  width: auto;
  height: auto;
  clip: auto;
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  color: #fff;
  background: var(--accent-strong);
}

.topbar {
  position: relative;
  z-index: 20;
  height: var(--topbar-height);
  padding: calc(8px + env(safe-area-inset-top)) 18px 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 243, 237, 0.96);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-weight: 720;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--accent-strong);
  font-family: Georgia, serif;
  font-size: 1.1rem;
}

.view-switcher {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #ebe9e2;
}

.view-switcher button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.view-switcher button[aria-pressed="true"] {
  color: #27312d;
  background: var(--surface-strong);
  box-shadow: 0 1px 4px rgba(45, 54, 49, 0.12);
}

.icon-button {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  justify-self: end;
  border-color: transparent;
  background: transparent;
  font-size: 1.2rem;
}

.mobile-only {
  display: none;
}

.layout {
  height: calc(100dvh - var(--topbar-height));
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-width: 0;
}

#sidebar {
  min-width: 0;
  padding: 18px 14px max(18px, env(safe-area-inset-bottom));
  overflow: hidden auto;
  border-right: 1px solid var(--line);
  background: #efede7;
}

.primary-button {
  min-height: 46px;
  padding: 0 16px;
  border-color: var(--accent-strong);
  color: #fff;
  background: var(--accent-strong);
  font-weight: 700;
}

.primary-button:hover {
  border-color: #183f30;
  color: #fff;
  background: #183f30;
}

#new-idea {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
}

.search-field {
  min-height: 44px;
  margin-top: 14px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-strong);
  color: var(--muted);
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 107, 85, 0.13);
}

.search-field input {
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 0;
  outline: 0;
  color: #27312d;
  background: transparent;
}

.toggle {
  min-height: 44px;
  margin: 5px 2px 6px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.84rem;
  cursor: pointer;
}

.toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.section-label {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

#session-list {
  display: grid;
  gap: 4px;
}

.session-row {
  width: 100%;
  min-width: 0;
  min-height: 66px;
  padding: 9px 10px;
  border-color: transparent;
  display: block;
  text-align: left;
  background: transparent;
}

.session-row:hover {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.62);
}

.session-row.is-active {
  background: var(--surface-strong);
  box-shadow: 0 1px 4px rgba(45, 54, 49, 0.08);
}

.session-title-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.session-title-line strong,
.session-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-title-line strong {
  font-size: 0.92rem;
  font-weight: 680;
}

.session-preview {
  margin-top: 4px;
  display: block;
  color: var(--muted);
  font-size: 0.79rem;
}

.pin-dot {
  color: var(--accent);
  font-size: 0.6rem;
}

main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.empty-state {
  width: min(560px, calc(100% - 36px));
  height: 100%;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-state p {
  max-width: 46ch;
  margin-bottom: 1.5rem;
  color: var(--muted);
  line-height: 1.6;
}

.empty-symbol {
  width: 58px;
  height: 58px;
  margin-bottom: 18px;
  display: grid;
  place-items: center;
  border: 1px solid #b8c9c0;
  border-radius: 18px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 1.5rem;
}

#chat-view {
  width: min(900px, 100%);
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conversation-heading {
  min-height: 86px;
  padding: 18px clamp(18px, 4vw, 42px) 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #ece9e2;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 780;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.conversation-heading h1 {
  max-width: 24ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
}

.run-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

#thread {
  flex: 1 1 auto;
  min-height: 0;
  padding: 22px clamp(18px, 4vw, 42px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.message {
  max-width: min(75ch, 88%);
  margin: 0 0 18px;
  display: grid;
  gap: 6px;
}

.message.user {
  margin-left: auto;
}

.message-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 720;
}

.message.user .message-label {
  text-align: right;
}

.message-content {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 5px;
  background: var(--surface-strong);
  line-height: 1.58;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .message-content {
  border-color: #cad9d1;
  border-radius: 16px 16px 5px 16px;
  background: var(--accent-soft);
}

.message.tool .message-content {
  color: var(--muted);
  background: #f3f1eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

.message.is-streaming .message-content::after {
  content: "";
  width: 6px;
  height: 1em;
  margin-left: 3px;
  display: inline-block;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 0.9s steps(1) infinite;
}

.message.is-error .message-content {
  border-color: #d9aaa6;
  color: var(--danger);
  background: #fff8f7;
}

#composer {
  flex: 0 0 auto;
  margin: 0 clamp(18px, 4vw, 42px);
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom)) 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface-strong);
  box-shadow: 0 8px 26px rgba(45, 54, 49, 0.1);
  margin-bottom: 14px;
}

#composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 107, 85, 0.12), 0 8px 26px rgba(45, 54, 49, 0.1);
}

#message {
  flex: 1;
  min-width: 0;
  max-height: 150px;
  padding: 7px 0;
  resize: none;
  border: 0;
  outline: 0;
  color: inherit;
  background: transparent;
  line-height: 1.45;
}

.composer-actions {
  flex: 0 0 auto;
}

.send-button,
.stop-button {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--accent-strong);
  font-size: 1.25rem;
  font-weight: 760;
}

.stop-button {
  background: var(--danger);
  font-size: 0.85rem;
}

#ideas {
  height: 100%;
  padding: clamp(24px, 5vw, 54px);
  overflow: hidden auto;
}

.ideas-heading {
  max-width: 1120px;
  margin: 0 auto 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.ideas-section {
  max-width: 1120px;
  margin: 0 auto 38px;
}

.idea-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 360px));
  gap: 14px;
}

.idea-card {
  min-width: 0;
  min-height: 190px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface-strong);
  box-shadow: 0 3px 12px rgba(45, 54, 49, 0.04);
}

.idea-card h3 {
  margin: 16px 0 8px;
  font-size: 1.04rem;
}

.idea-card p {
  color: var(--muted);
  line-height: 1.48;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.idea-meta {
  min-height: 24px;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.source-chip,
.status-chip {
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #efede7;
  font-size: 0.7rem;
  font-weight: 680;
}

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

.idea-card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quiet-button {
  padding: 0 13px;
  border-color: var(--line);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 680;
}

#context {
  position: fixed;
  z-index: 40;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  width: min(360px, 92vw);
  padding: 22px 20px max(22px, env(safe-area-inset-bottom));
  overflow: hidden auto;
  border-left: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.context-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

#session-facts {
  margin: 24px 0;
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 12px;
  font-size: 0.86rem;
}

#session-facts dt {
  color: var(--muted);
}

#session-facts dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 620;
}

.session-actions {
  padding-top: 18px;
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--line);
}

.context-action {
  width: 100%;
  padding: 0 14px;
  text-align: left;
  background: transparent;
}

.toast {
  position: fixed;
  z-index: 80;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 15px;
  border-radius: 12px;
  color: #fff;
  background: #27312d;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
}

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

.empty-list {
  padding: 14px 8px;
  font-size: 0.85rem;
}

#drawer-scrim {
  position: fixed;
  z-index: 29;
  inset: var(--topbar-height) 0 0;
  background: rgba(26, 31, 28, 0.25);
}

@keyframes blink {
  50% { opacity: 0; }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: calc(62px + env(safe-area-inset-top));
  }

  .topbar {
    height: var(--topbar-height);
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .mobile-only {
    display: grid;
    justify-self: start;
  }

  .brand {
    justify-self: center;
  }

  .brand-mark,
  .brand span:last-child {
    display: none;
  }

  .view-switcher {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  .view-switcher button {
    min-height: 44px;
    padding: 0 12px;
  }

  .layout {
    display: block;
    height: calc(100dvh - var(--topbar-height));
  }

  #sidebar {
    position: fixed;
    z-index: 30;
    top: var(--topbar-height);
    bottom: 0;
    left: 0;
    width: min(88vw, 330px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  body.drawer-open #sidebar {
    transform: translateX(0);
  }

  main,
  #chat-view,
  #ideas {
    height: 100%;
  }

  .conversation-heading {
    min-height: 74px;
    padding: 12px 16px 10px;
  }

  .conversation-heading h1 {
    max-width: 18ch;
    font-size: 1.12rem;
  }

  #thread {
    padding: 18px 14px;
  }

  .message {
    max-width: 92%;
  }

  .message-content {
    padding: 11px 13px;
  }

  #composer {
    margin: 0 10px;
    margin-bottom: max(8px, env(safe-area-inset-bottom));
  }

  #ideas {
    padding: 22px 14px max(26px, env(safe-area-inset-bottom));
  }

  .ideas-heading {
    margin-bottom: 25px;
  }

  .ideas-heading .primary-button {
    padding: 0 12px;
    font-size: 0.82rem;
  }

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

  #context {
    top: var(--topbar-height);
    width: min(92vw, 350px);
  }
}

@media (max-width: 420px) {
  .view-switcher button {
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .conversation-heading .run-status {
    display: none;
  }

  .empty-state {
    width: calc(100% - 28px);
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .conversation-heading {
    min-height: 56px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  #thread {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  #composer {
    margin-bottom: max(5px, env(safe-area-inset-bottom));
  }
}

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