:root {
  --ink: #152024;
  --muted: #68777b;
  --paper: #f2f4f1;
  --surface: #ffffff;
  --line: #d8dfdc;
  --teal: #0f766e;
  --teal-dark: #0a5852;
  --coral: #d65d4e;
  --gold: #c99a34;
  --danger: #b5423e;
  --shadow: 0 12px 30px rgba(21, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  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;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 5vw, 72px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: max-content;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.05rem;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.model-badge,
.voice-picker,
.toggle-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.model-badge {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.model-badge.warn {
  border-color: rgba(201, 154, 52, 0.45);
  color: var(--gold);
}

.voice-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-picker select {
  min-width: 150px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.toggle-label input {
  accent-color: var(--teal);
}

.secondary-button,
.primary-button,
.speak-button {
  border: 0;
  border-radius: 6px;
  font-weight: 800;
  transition: background 150ms ease, opacity 150ms ease, transform 150ms ease;
}

.secondary-button,
.speak-button {
  background: #e9eeeb;
  color: var(--ink);
}

.secondary-button {
  min-height: 38px;
  padding: 0 12px;
}

.secondary-button:hover,
.speak-button:hover {
  background: #dfe7e3;
}

.primary-button {
  min-height: 44px;
  padding: 0 20px;
  background: var(--teal);
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
  transform: translateY(-1px);
}

.chat-shell {
  width: min(100%, 1020px);
  margin: 0 auto;
  padding: 32px clamp(18px, 4vw, 34px) 26px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 18px;
}

.chat-log {
  min-height: 420px;
  max-height: calc(100vh - 245px);
  overflow-y: auto;
  padding: 8px 4px 18px;
}

.message {
  width: min(78%, 720px);
  margin-bottom: 20px;
}

.message-user {
  margin-left: auto;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.75rem;
}

.message-assistant .message-meta {
  justify-content: flex-start;
}

.speak-button {
  padding: 4px 8px;
  font-size: 0.72rem;
}

.message-body {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-user .message-body {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 88px;
  max-height: 220px;
  padding: 12px;
  border: 0;
  outline: none;
  resize: vertical;
  background: transparent;
  color: var(--ink);
  line-height: 1.6;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.status {
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.8rem;
}

.status.warn {
  color: var(--gold);
}

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

.status.busy {
  color: var(--teal);
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .toolbar {
    justify-content: flex-start;
    width: 100%;
  }

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

  .message {
    width: 92%;
  }

  .chat-shell {
    padding-top: 22px;
  }
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(100%, 380px);
  display: grid;
  gap: 26px;
}

.login-shell .brand {
  justify-content: center;
}

.login-card {
  display: grid;
  gap: 16px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.login-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.login-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.login-field input {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
}

.login-field input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: var(--teal);
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(181, 66, 62, 0.4);
  border-radius: 6px;
  background: rgba(181, 66, 62, 0.08);
  color: var(--danger);
  font-size: 0.84rem;
}

.logout-form {
  display: flex;
  margin: 0;
}
