:root {
  color-scheme: light;
  --paper: #f7f7f4;
  --ink: #171412;
  --muted: #69645d;
  --line: #d7d0c7;
  --surface: #ffffff;
  --chili: #cf382d;
  --chili-dark: #8e211b;
  --teal: #006f78;
  --gold: #f0b429;
  --lime: #c5d84a;
  --shadow: 0 18px 50px rgba(23, 20, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(207, 56, 45, 0.08), transparent 28%),
    linear-gradient(180deg, var(--paper), #ecebe5);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.side-panel,
.chat-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  border-radius: 8px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--lime);
  color: var(--ink);
  font-weight: 900;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1;
}

.control-group {
  display: grid;
  gap: 10px;
}

.control-group h2 {
  font-size: 0.95rem;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.topic-chip,
.segmented button,
.ghost-button,
.send-button,
.utility-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.topic-chip {
  padding: 0 10px;
}

.topic-chip.wide {
  grid-column: 1 / -1;
}

.topic-chip.is-active,
.segmented button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  padding: 0 8px;
  font-size: 0.88rem;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 86px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.chat-header h2 {
  font-size: 1.35rem;
}

.ghost-button {
  min-width: 84px;
  padding: 0 14px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 20px;
}

.message {
  width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.user-message {
  align-self: flex-end;
  border-color: rgba(0, 111, 120, 0.35);
  background: #e9fbfc;
}

.assistant-message {
  align-self: flex-start;
}

.loading-message {
  border-color: rgba(207, 56, 45, 0.35);
}

.message-meta {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.message-body {
  padding: 14px;
}

.message-body p {
  margin: 0;
  line-height: 1.55;
}

.message-body p + p {
  margin-top: 10px;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 14px;
}

.utility-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.utility-button:hover,
.ghost-button:hover,
.topic-chip:hover,
.segmented button:hover {
  border-color: var(--ink);
}

.mom-safe {
  display: none;
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid rgba(0, 111, 120, 0.22);
  border-radius: 8px;
  background: #eefbfa;
  color: #17484d;
  line-height: 1.5;
}

.mom-safe.is-visible {
  display: block;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

textarea {
  width: 100%;
  min-height: 84px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.45;
}

textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(240, 180, 41, 0.75);
  outline-offset: 2px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#charCount {
  color: var(--muted);
  font-size: 0.86rem;
}

.send-button {
  min-width: 112px;
  padding: 0 18px;
  border-color: var(--chili-dark);
  background: var(--chili);
  color: #fff;
}

.send-button:hover {
  background: var(--chili-dark);
}

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

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 10px;
  }

  .side-panel {
    gap: 16px;
  }

  .brand-lockup {
    padding-bottom: 12px;
  }

  .topic-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topic-chip.wide {
    grid-column: auto;
  }

  .chat-panel {
    min-height: 68vh;
  }
}

@media (max-width: 520px) {
  .topic-grid,
  .segmented {
    grid-template-columns: 1fr;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .ghost-button,
  .send-button {
    width: 100%;
  }

  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
