:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface-hover: #efeff1;
  --border: #e5e5e6;
  --text: #1a1a1a;
  --text-muted: #6e6e80;
  --text-faint: #a4a4b2;
  --accent: #111111;
  --accent-contrast: #ffffff;
  --focus: #5b8def;
  --error: #d0453a;
  --error-bg: #fdf1f0;

  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px;
}

.app {
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: 0 1px 2px rgba(16, 16, 20, 0.04), 0 8px 24px rgba(16, 16, 20, 0.04);
}

/* Header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-mark {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1a1a1a 0%, #4a4a52 100%);
}

.app-mark--lg {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  margin-bottom: 4px;
}

.app-title {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.app-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

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

.provider-label #provider-name {
  color: var(--text);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.status[data-state="sending"] {
  color: #9a6b00;
  background: #fff6e0;
}

.status[data-state="ready"] {
  color: #1a7a4c;
  background: #e9f8f0;
}

.status[data-state="error"] {
  color: var(--error);
  background: var(--error-bg);
}

#settings-toggle {
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

#settings-toggle:hover,
#settings-toggle[aria-expanded="true"] {
  color: var(--text);
  background: var(--surface-hover);
}

/* Settings panel */

.config {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.config[hidden] {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field--slider {
  grid-column: 1 / -1;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.field label span {
  font-family: var(--font-mono);
  color: var(--text);
}

.field input[type="text"],
.field input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.field input[type="text"]:focus,
.field input[type="password"]:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.15);
}

.field input[type="range"] {
  accent-color: var(--accent);
}

/* Message log */

.log {
  flex: 1;
  min-height: 360px;
  max-height: 520px;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.log-empty {
  color: var(--text-faint);
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.log-empty p {
  margin: 2px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.log-empty-sub {
  color: var(--text-faint) !important;
  font-size: 13px !important;
}

.log-entry {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
}

.log-entry--user {
  align-self: flex-end;
  align-items: flex-end;
}

.log-entry--assistant,
.log-entry--error {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 100%;
}

.log-entry-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.log-entry-role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.log-entry-latency {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.log-entry-body {
  font-size: 14.5px;
  line-height: 1.55;
}

.log-entry--user .log-entry-body {
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border-bottom-right-radius: 4px;
}

.log-entry--assistant .log-entry-body {
  color: var(--text);
  padding: 0 2px;
}

.log-entry--error .log-entry-body {
  color: var(--error);
  background: var(--error-bg);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
}

.log-entry-body p {
  margin: 0 0 8px;
}

.log-entry-body p:last-child {
  margin-bottom: 0;
}

.log-entry-body code {
  font-family: var(--font-mono);
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}

.log-entry--user .log-entry-body code {
  background: rgba(0, 0, 0, 0.06);
}

.log-entry-body pre {
  background: #1a1a1e;
  color: #eaeaef;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 8px;
}

.log-entry-body pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.log-entry-body ul,
.log-entry-body ol {
  margin: 0 0 8px;
  padding-left: 20px;
}

.log-entry-body a {
  color: var(--focus);
}

/* Composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 12px 18px;
  max-height: 140px;
}

.composer textarea:focus {
  outline: none;
  background: var(--bg);
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.15);
}

.composer button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.composer button:hover:not(:disabled) {
  opacity: 0.85;
}

.composer button:active:not(:disabled) {
  transform: scale(0.94);
}

.composer button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.app-footer {
  padding: 10px 20px;
  font-size: 11.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  text-align: center;
}

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

  .log-entry {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .composer button {
    transition: none;
  }
}
