:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: #fffaf0;
  --surface-strong: #ffffff;
  --ink: #182026;
  --muted: #66717a;
  --line: #ded7c8;
  --teal: #0f766e;
  --teal-dark: #0b5f59;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 20px 45px rgba(24, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(183, 121, 31, 0.12), transparent 32%),
    var(--bg);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.sidebar,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: block;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 272px;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
}

.brand h1,
.chat-header h2,
.control-group h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.25;
}

.brand p,
.control-group p,
.eyebrow {
  margin: 4px 0 0;
  color: var(--muted);
}

.control-group {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.control-group h2 {
  margin-bottom: 10px;
  font-size: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin-bottom: 0;
}

.control-group.small {
  margin-top: auto;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-strong);
}

.access-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
}

.access-row .secondary-button {
  margin-top: 0;
}

#access-code {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-strong);
  color: var(--ink);
  outline: none;
}

#access-code:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.mode-button {
  min-height: 42px;
  border: 0;
  border-inline-start: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.mode-button:first-child {
  border-inline-start: 0;
}

.mode-button.active {
  background: var(--teal);
  color: white;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.icon-button:hover {
  background: var(--teal-dark);
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-inline-end: 2px;
}

.chat-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
}

.chat-open-button,
.chat-delete-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
}

.chat-open-button {
  min-width: 0;
  padding: 8px 10px;
  text-align: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-delete-button {
  padding: 0;
  color: var(--muted);
  font-size: 20px;
}

.chat-list-item.active .chat-open-button {
  border-color: rgba(15, 118, 110, 0.4);
  background: #e6f3f1;
  color: var(--teal-dark);
  font-weight: 700;
}

.chat-open-button:hover,
.chat-delete-button:hover {
  filter: brightness(0.98);
}

.chat-delete-button:hover {
  color: var(--red);
}

.secondary-button {
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
}

.secondary-button:hover,
.mode-button:hover {
  filter: brightness(0.98);
}

.secondary-button.danger {
  color: var(--red);
}

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

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

.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-title-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 8px;
}

.eyebrow {
  font-size: 13px;
}

.chat-header h2 {
  margin-top: 2px;
  font-size: 24px;
  line-height: 1.25;
}

.model-badge {
  max-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
}

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

.message.assistant {
  align-self: flex-start;
  background: var(--surface-strong);
}

.message.user {
  align-self: flex-end;
  background: #e6f3f1;
  border-color: rgba(15, 118, 110, 0.24);
}

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

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface-strong);
  color: var(--ink);
  line-height: 1.55;
  outline: none;
}

textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

#send-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-weight: 800;
}

#send-button:hover {
  background: var(--teal-dark);
}

#send-button:disabled {
  cursor: not-allowed;
  background: #98b9b5;
}

.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: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 20px, 720px);
    margin: 10px auto;
  }

  .sidebar {
    order: 2;
  }

  .chat-list {
    max-height: 180px;
  }

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

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

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

  .model-badge {
    max-width: 100%;
  }
}

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

  #send-button {
    width: 100%;
  }

  .message {
    width: 100%;
  }
}
