:root {
  color-scheme: light;
  --bg: #f7f5ee;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --ink: #202124;
  --muted: #70757a;
  --line: #ded9cf;
  --accent: #1967d2;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --shadow: 0 18px 48px rgba(32, 33, 36, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: #ece8de;
  padding: 18px;
  min-width: 0;
}

.brand-row,
.topbar,
.compact-row,
.control-pair {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row {
  justify-content: space-between;
}

.brand {
  font-weight: 760;
  font-size: 18px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary,
.ghost,
.icon-button {
  background: var(--panel-strong);
  color: var(--ink);
  border-color: var(--line);
}

.danger {
  background: #fff8f7;
  border-color: #f1c7c2;
  color: var(--danger);
}

.full {
  width: 100%;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-bottom: 16px;
}

.chat-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  display: grid;
  gap: 2px;
  min-height: 56px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.chat-item.active {
  background: var(--panel-strong);
  border-color: var(--line);
}

.chat-item-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100dvh;
}

.topbar {
  border-bottom: 1px solid var(--line);
  min-height: 68px;
  padding: 10px clamp(12px, 2vw, 22px);
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(10px);
}

.title-wrap {
  flex: 1;
  min-width: 0;
}

.title-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  font-weight: 760;
  outline: 0;
  padding: 0;
}

.settings-panel {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 14px clamp(12px, 2vw, 22px);
  display: grid;
  gap: 12px;
}

.field-row {
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: 0;
  padding: 11px 12px;
}

textarea {
  resize: none;
  line-height: 1.45;
}

.control-pair select {
  flex: 1;
  min-width: 0;
}

.messages {
  overflow: auto;
  padding: 22px clamp(12px, 3vw, 36px);
}

.empty-state {
  max-width: 620px;
  margin: 12vh auto 0;
  color: var(--muted);
  line-height: 1.6;
  text-align: center;
}

.message {
  display: flex;
  margin: 0 auto 16px;
  max-width: 880px;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: min(760px, 92%);
  padding: 12px 14px;
  background: var(--panel-strong);
  line-height: 1.58;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.user .bubble {
  background: #e7f0fe;
  border-color: #c4dafc;
}

.model .bubble {
  background: var(--panel-strong);
}

.error .bubble {
  background: #fff8f7;
  border-color: #f1c7c2;
  color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#promptInput {
  max-height: 180px;
}

.send-button {
  background: #188038;
  color: #ffffff;
  min-width: 72px;
}

.mobile-only {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 33, 36, 0.32);
  z-index: 20;
}

.modal {
  width: min(440px, 100%);
  background: var(--panel-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.modal p {
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 340px);
    transform: translateX(-105%);
    transition: transform 160ms ease;
    z-index: 10;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    min-height: 62px;
  }

  .ghost {
    padding: 0 10px;
  }

  .messages {
    padding: 14px 10px;
  }

  .bubble {
    max-width: 94%;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
  }

  .send-button {
    min-width: 64px;
    padding: 0 10px;
  }

  .control-pair,
  .compact-row {
    align-items: stretch;
    flex-direction: column;
  }
}
