:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ed;
  --line: #d8ddd7;
  --text: #1f2524;
  --muted: #66706d;
  --accent: #186a5e;
  --accent-2: #c85f38;
  --danger: #9f2f2f;
  --shadow: 0 14px 42px rgba(33, 41, 38, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(24, 106, 94, 0.08), transparent 42%),
    var(--bg);
  color: var(--text);
}

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

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

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

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

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  overflow-y: auto;
  padding: 18px;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.12;
}

.brand p,
.panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  background: rgba(24, 106, 94, 0.12);
  color: var(--accent);
}

.badge.bad {
  background: rgba(159, 47, 47, 0.12);
  color: var(--danger);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

label {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 106, 94, 0.14);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row button {
  flex: 1;
}

.status-panel dl {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
}

.status-panel dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

dt,
dd {
  margin: 0;
  font-size: 12px;
}

dt {
  color: var(--muted);
}

dd {
  font-weight: 700;
}

.meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 160ms ease;
}

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

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

.message {
  width: min(780px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: 0 8px 22px rgba(33, 41, 38, 0.06);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  border-color: rgba(24, 106, 94, 0.35);
  background: #f3faf7;
}

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

.role {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.empty {
  margin: auto;
  width: min(560px, 100%);
  color: var(--muted);
  text-align: center;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 86px;
  gap: 10px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  padding: 14px;
}

.composer textarea {
  min-height: 44px;
  max-height: 180px;
  resize: none;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, auto) minmax(0, 1fr);
  }

  .sidebar {
    max-height: 42vh;
    max-height: 42dvh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .messages {
    min-height: 0;
    padding: 16px;
  }
}

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

  .button-row {
    flex-direction: column;
  }
}
