:root {
  --ink: #17201c;
  --muted: #5c6b64;
  --line: #d7dfdb;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --pine: #285345;
  --sea: #2e6f8f;
  --coral: #c8584a;
  --gold: #d4a33f;
  --brand-contrast: #f7f8f5;
  --wash: rgba(255, 255, 255, 0.88);
  --stripe: rgba(40, 83, 69, 0.06);
  --body-gradient-a: rgba(46, 111, 143, 0.16);
  --body-gradient-b: rgba(200, 88, 74, 0.12);
  --soft-panel: rgba(255, 255, 255, 0.84);
  --strong-panel: rgba(255, 255, 255, 0.96);
  --input-panel: rgba(255, 255, 255, 0.92);
  --code-bg: rgba(23, 32, 28, 0.08);
  --scroll-thumb: rgba(46, 111, 143, 0.38);
  --scroll-thumb-hover: rgba(40, 83, 69, 0.58);
  --brand-ring: rgba(255, 255, 255, 0.36);
  --subtle-fill: rgba(255, 255, 255, 0.72);
  --active-fill: rgba(46, 111, 143, 0.1);
  --suggestion-border: rgba(46, 111, 143, 0.22);
  --user-text: #ffffff;
  --danger: #a33b31;
  --danger-soft: rgba(163, 59, 49, 0.12);
  --danger-soft-strong: rgba(163, 59, 49, 0.2);
  --shadow: 0 18px 60px rgba(23, 32, 28, 0.14);
}

:root[data-theme="dark"] {
  --ink: #edf4ef;
  --muted: #a9b8b0;
  --line: #33443d;
  --paper: #111816;
  --panel: #19231f;
  --pine: #78b79d;
  --sea: #72b7d6;
  --coral: #e08678;
  --gold: #e2bd61;
  --brand-contrast: #101613;
  --wash: rgba(17, 24, 22, 0.9);
  --stripe: rgba(120, 183, 157, 0.07);
  --body-gradient-a: rgba(46, 111, 143, 0.2);
  --body-gradient-b: rgba(200, 88, 74, 0.12);
  --soft-panel: rgba(25, 35, 31, 0.86);
  --strong-panel: rgba(31, 43, 38, 0.98);
  --input-panel: rgba(25, 35, 31, 0.94);
  --code-bg: rgba(237, 244, 239, 0.1);
  --scroll-thumb: rgba(114, 183, 214, 0.42);
  --scroll-thumb-hover: rgba(120, 183, 157, 0.66);
  --brand-ring: rgba(16, 22, 19, 0.36);
  --subtle-fill: rgba(25, 35, 31, 0.72);
  --active-fill: rgba(114, 183, 214, 0.16);
  --suggestion-border: rgba(114, 183, 214, 0.3);
  --user-text: #07110e;
  --danger: #ff9a8d;
  --danger-soft: rgba(255, 154, 141, 0.14);
  --danger-soft-strong: rgba(255, 154, 141, 0.22);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, var(--body-gradient-a), var(--body-gradient-b)),
    var(--paper);
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sidebar,
.messages {
  scrollbar-color: rgba(46, 111, 143, 0.45) transparent;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  width: 10px;
}

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

.sidebar::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  min-height: 48px;
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--scroll-thumb);
  background-clip: content-box;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  background-clip: content-box;
}

.sidebar::-webkit-scrollbar-corner,
.messages::-webkit-scrollbar-corner {
  background: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px 10px minmax(0, 1fr);
  height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 220ms ease;
}

.app-shell.resizing {
  cursor: col-resize;
  user-select: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  min-height: 100dvh;
  min-width: 0;
  padding: 24px;
  background:
    linear-gradient(var(--wash), var(--wash)),
    repeating-linear-gradient(45deg, transparent 0 22px, var(--stripe) 22px 24px);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(0);
  opacity: 1;
  transition:
    transform 220ms ease,
    opacity 180ms ease,
    box-shadow 180ms ease;
}

.sidebar-overlay {
  display: none;
}

.sidebar-panel-button {
  display: inline-grid;
}

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

.sidebar-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border-radius: 8px;
  background: var(--pine);
  box-shadow: inset 0 0 0 1px var(--brand-ring);
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span {
  content: "";
  position: absolute;
  display: block;
}

.brand-mark::before {
  inset: 11px 17px;
  border: 2px solid var(--brand-contrast);
  transform: rotate(28deg);
}

.brand-mark::after {
  width: 28px;
  height: 2px;
  left: 13px;
  top: 26px;
  background: var(--gold);
  transform: rotate(-25deg);
}

.brand-mark span {
  width: 7px;
  height: 7px;
  right: 11px;
  bottom: 11px;
  border-radius: 50%;
  background: var(--coral);
}

.sidebar-content {
  min-width: 0;
}

.sidebar-resizer {
  width: 10px;
  min-width: 10px;
  padding: 0;
  border: 0;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
  transition:
    opacity 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.sidebar-resizer:hover,
.app-shell.resizing .sidebar-resizer {
  border-left-color: rgba(46, 111, 143, 0.32);
  border-right-color: rgba(46, 111, 143, 0.32);
  background: rgba(46, 111, 143, 0.08);
}

.sidebar-collapsed .sidebar {
  transform: translateX(calc(-100% - 24px));
  opacity: 0.2;
  pointer-events: none;
}

.sidebar-collapsed .sidebar-resizer {
  opacity: 0;
  pointer-events: none;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 3px 0 0;
  line-height: 1.05;
}

h1 {
  font-size: 1.8rem;
}

h2 {
  font-size: 1.4rem;
}

.status-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.status-panel p {
  margin: 3px 0 0;
  font-size: 0.82rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sign-out-button {
  min-height: 36px;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--line));
  border-radius: 8px;
  background: var(--danger-soft);
}

.sign-out-button:hover {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  background: var(--danger-soft-strong);
}

.sidebar-meta {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
  overflow: hidden;
}

.sidebar-meta-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  border: 0;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: left;
}

.sidebar-meta-toggle:hover {
  background: var(--strong-panel);
}

.sidebar-meta-toggle svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: currentColor;
}

.sidebar-meta-panel {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
  border-top: 1px solid var(--line);
}

.sidebar-meta-panel > div:first-child {
  padding-top: 12px;
}

.status-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}

.status-dot.ok {
  color: #1f8a52;
  background: #1f8a52;
}

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

.theme-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-top: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--subtle-fill);
}

.theme-control button {
  min-height: 30px;
  color: var(--muted);
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
}

.theme-control button.active {
  color: var(--ink);
  background: var(--strong-panel);
  box-shadow: 0 1px 0 rgba(23, 32, 28, 0.08);
}

.chat-history-panel {
  display: grid;
  gap: 18px;
  min-height: 0;
}

.new-chat-button,
.chat-history-item {
  width: 100%;
  min-height: 42px;
  color: var(--pine);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.new-chat-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.new-chat-button:hover,
.chat-history-item:hover {
  border-color: var(--sea);
  background: var(--strong-panel);
}

.chat-history {
  display: grid;
  gap: 8px;
  min-height: 0;
}

.chat-history .label {
  margin-bottom: 2px;
}

.chat-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 6px;
  align-items: stretch;
}

.chat-history-item {
  display: grid;
  gap: 3px;
  padding: 9px 11px;
  text-align: left;
}

.chat-history-row.active .chat-history-item {
  border-color: rgba(46, 111, 143, 0.46);
  background: var(--active-fill);
}

.chat-history-item span {
  overflow: hidden;
  color: var(--ink);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-item small {
  color: var(--muted);
  font-size: 0.74rem;
}

.delete-chat-button {
  display: grid;
  place-items: center;
  width: 38px;
  min-height: 42px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft-panel);
}

.delete-chat-button:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--strong-panel);
}

.delete-chat-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  overflow: hidden;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 0 18px;
}

.chat-toolbar-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.icon-button,
.composer button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.icon-button svg,
.composer svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 980px;
  width: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 18px 2px;
  overflow-y: auto;
}

.message {
  width: min(760px, 100%);
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 rgba(23, 32, 28, 0.05);
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
}

.message.user {
  align-self: flex-end;
  color: #fff;
  color: var(--user-text);
  background: var(--sea);
}

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

.message :first-child {
  margin-top: 0;
}

.message :last-child {
  margin-bottom: 0;
}

.message p {
  margin: 0 0 10px;
}

.message h3,
.message h4,
.message h5 {
  margin: 12px 0 6px;
  line-height: 1.18;
}

.message ul {
  margin: 6px 0 10px;
  padding-left: 22px;
}

.message li + li {
  margin-top: 4px;
}

.message code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--code-bg);
}

.composer-wrap {
  display: grid;
  gap: 10px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 0 4px;
}

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

.suggested-prompts button {
  min-height: 38px;
  padding: 8px 10px;
  color: var(--pine);
  border: 1px solid var(--suggestion-border);
  border-radius: 8px;
  background: var(--soft-panel);
  box-shadow: 0 1px 0 rgba(23, 32, 28, 0.04);
}

.suggested-prompts button:hover {
  border-color: var(--sea);
  background: var(--strong-panel);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 50px;
  resize: none;
  padding: 14px 15px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--input-panel);
  box-shadow: var(--shadow);
}

.composer textarea:focus {
  border-color: var(--sea);
}

.composer button {
  color: #fff;
  border-color: var(--pine);
  background: var(--pine);
}

.composer button:disabled,
.suggested-prompts button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.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;
}

@media (max-width: 780px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    position: relative;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    grid-template-columns: 1fr !important;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr !important;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(88vw, 360px);
    height: 100dvh;
    min-height: 100dvh;
    max-height: none;
    padding: 20px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 18px 60px rgba(23, 32, 28, 0.22);
    transform: translateX(0);
    transition: transform 180ms ease;
  }

  .sidebar-resizer {
    display: none;
  }

  .sidebar-collapsed .sidebar {
    display: flex;
    opacity: 1;
    pointer-events: auto;
    transform: translateX(calc(-100% - 12px));
  }

  .sidebar-collapsed .chat-panel::before {
    content: none;
  }

  .chat-panel {
    height: 100dvh;
    min-height: 100dvh;
    padding: 14px 14px calc(12px + env(safe-area-inset-bottom));
  }

  .chat-toolbar {
    padding: 2px 0 12px;
  }

  .chat-toolbar-main {
    width: 100%;
    align-items: center;
    gap: 10px;
  }

  .chat-toolbar .eyebrow {
    font-size: 0.7rem;
  }

  .chat-toolbar h2 {
    font-size: 1.2rem;
    line-height: 1.12;
  }

  .sidebar-panel-button {
    display: inline-grid;
    flex: 0 0 44px;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(17, 24, 22, 0.32);
  }

  .messages {
    gap: 10px;
    padding: 8px 0 10px;
  }

  .message {
    width: 100%;
    padding: 12px 14px;
    line-height: 1.42;
  }

  .composer-wrap {
    gap: 8px;
    padding: 8px 0 0;
  }

  .suggested-prompts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .suggested-prompts button {
    min-height: 36px;
    padding: 8px 9px;
    font-size: 0.82rem;
  }

  .composer {
    gap: 8px;
  }

  .composer textarea {
    min-height: 46px;
    max-height: 140px;
    padding: 12px 13px;
  }

  .composer button {
    width: 42px;
    height: 42px;
  }

  .chat-history-panel {
    gap: 14px;
  }

  .status-panel {
    gap: 10px;
  }

  .theme-control {
    gap: 3px;
  }

  .theme-control button {
    min-height: 32px;
    font-size: 0.74rem;
  }
}

@media (max-width: 520px) {
  .suggested-prompts {
    grid-template-columns: 1fr;
  }

  .chat-toolbar {
    align-items: flex-start;
  }

  .sidebar {
    width: min(92vw, 360px);
    padding: 16px;
  }

  .brand-lockup {
    gap: 10px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .chat-history-row {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  .delete-chat-button {
    width: 36px;
    min-height: 40px;
  }
}
