:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17222c;
  --muted: #5d6b78;
  --brand: #0a7c66;
  --brand-contrast: #ffffff;
  --user: #0a7c66;
  --assistant: #e8edf2;
  --border: #d9e0e6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #eef4fa 0%, #f4f6f8 100%);
}

.app {
  max-width: 760px;
  margin: 0 auto;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(244, 246, 248, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1rem;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.settings {
  background: var(--panel);
  margin: 0.5rem 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid;
  gap: 0.6rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}

label.inline-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

input:not([type="checkbox"]),
textarea,
button {
  font: inherit;
}

input:not([type="checkbox"]),
textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  background: var(--brand);
  color: var(--brand-contrast);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
}

.history-panel {
  gap: 0.5rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-list {
  display: grid;
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
}

.history-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
}

.history-item-prompt {
  font-size: 0.85rem;
  line-height: 1.3;
}

.history-item-meta {
  margin-top: 0.2rem;
  font-size: 0.74rem;
  color: var(--muted);
}

.history-empty {
  font-size: 0.83rem;
  color: var(--muted);
}

.chat {
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.message {
  display: grid;
  gap: 0.3rem;
}

.role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.text {
  width: fit-content;
  max-width: min(90%, 700px);
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  white-space: pre-wrap;
  line-height: 1.35;
}

.message.user {
  align-items: end;
}

.message.user .text {
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .text,
.message.system .text {
  background: var(--assistant);
  border-bottom-left-radius: 4px;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 0.6rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.composer textarea {
  min-height: 2.6rem;
  max-height: 8rem;
  resize: none;
}

@media (min-width: 768px) {
  .topbar h1 {
    font-size: 1.1rem;
  }

  .composer {
    padding: 0.75rem;
  }
}
