:root {
  --bg: #f3f2ee;
  --surface: rgba(255, 255, 251, 0.86);
  --surface-strong: #ffffff;
  --surface-muted: #f5f3ee;
  --surface-muted-strong: #eeebe4;
  --line: rgba(24, 24, 20, 0.08);
  --line-strong: rgba(24, 24, 20, 0.16);
  --text: #171714;
  --muted: #666257;
  --accent: #171714;
  --accent-soft: #e9e5dc;
  --success: #11805f;
  --warn: #a13d3d;
  --code-bg: rgba(23, 23, 20, 0.06);
  --shadow: 0 20px 70px rgba(20, 18, 14, 0.08);
  --message-font-scale: 0.94;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  --sans: "SF Pro Display", "Avenir Next", "Neue Haas Grotesk Text Pro", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.92), transparent 38%),
    radial-gradient(circle at 12% 18%, rgba(17, 128, 95, 0.08), transparent 22%),
    linear-gradient(180deg, #f7f6f2 0%, #f2f0ea 48%, #ece9e1 100%);
}

body.modal-open {
  overflow: hidden;
}

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

button {
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(23, 23, 20, 0.22);
  box-shadow: 0 0 0 3px rgba(23, 23, 20, 0.06);
}

code {
  padding: 0.16em 0.3em;
  border-radius: 6px;
  background: var(--code-bg);
  font-family: var(--mono);
}

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  height: 100vh;
  padding: 12px;
}

.chat-frame {
  height: calc(100vh - 24px);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 10px;
}

.app-header-copy {
  min-width: 0;
}

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

.chat-brand > img {
  margin-top: 1px;
}

.title {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 600;
}

.status-line,
.thread-summary,
.hint,
.empty-copy,
.meta {
  color: var(--muted);
}

.status-line {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.45;
}

.thread-summary {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-summary.hidden {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-btn {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.header-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.header-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 14px 6px;
}

.header-strip-links {
  display: none;
}

.mode-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition:
    transform 0.18s ease,
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.mode-link:hover {
  transform: translateY(-1px);
  color: var(--text);
}

#advancedModeLinkMobile {
  display: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #bab5ab;
}

.dot.live {
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(17, 128, 95, 0.12);
}

.banner {
  flex: 1;
  min-width: min(100%, 240px);
  max-width: min(100%, 520px);
  max-height: 3.8em;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(161, 61, 61, 0.18);
  background: rgba(252, 234, 231, 0.92);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

.banner.hidden {
  display: none;
}

.state-confirmation {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  max-width: min(92vw, 560px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(17, 128, 95, 0.24);
  border-radius: 14px;
  background: rgba(225, 248, 237, 0.96);
  box-shadow: 0 12px 34px rgba(21, 92, 69, 0.16);
  color: #0f6f51;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  pointer-events: none;
}

.state-confirmation.hidden {
  display: none;
}

.mobile-nav {
  display: flex;
  gap: 8px;
  padding: 0 14px 10px;
}

.mobile-nav-btn,
.mobile-nav-link {
  flex: 1 1 0;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.chat-frame[data-mobile-view="threads"],
.chat-frame[data-mobile-view="experiments"],
.chat-frame[data-mobile-view="settings"] {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.chat-frame[data-mobile-view="threads"] .mobile-nav,
.chat-frame[data-mobile-view="threads"] .panel-rail,
.chat-frame[data-mobile-view="threads"] .messages,
.chat-frame[data-mobile-view="threads"] .composer-wrap,
.chat-frame[data-mobile-view="settings"] .mobile-nav,
.chat-frame[data-mobile-view="settings"] .panel-rail,
.chat-frame[data-mobile-view="settings"] .messages,
.chat-frame[data-mobile-view="settings"] .composer-wrap,
.chat-frame[data-mobile-view="experiments"] .mobile-nav,
.chat-frame[data-mobile-view="experiments"] .panel-rail,
.chat-frame[data-mobile-view="experiments"] .messages,
.chat-frame[data-mobile-view="experiments"] .composer-wrap {
  display: none;
}

.chat-frame[data-mobile-view="threads"] .mobile-threads-view,
.chat-frame[data-mobile-view="settings"] .mobile-settings-view,
.chat-frame[data-mobile-view="experiments"] .mobile-experiments-view {
  display: flex;
  grid-row: 4;
  min-height: 0;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 251, 0.98);
}

.chat-frame[data-mobile-view="threads"] .mobile-screen-body,
.chat-frame[data-mobile-view="settings"] .mobile-screen-body,
.chat-frame[data-mobile-view="experiments"] .mobile-screen-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.mobile-threads-view {
  display: none;
}

.mobile-experiments-view {
  display: none;
}

.mobile-settings-view {
  display: none;
}

.subtle-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.settings-scope-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  align-self: flex-start;
}

.settings-scope-btn {
  min-height: 36px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-scope-btn.active {
  background: var(--accent);
  color: #fffdf8;
}

[data-settings-scope-section] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

[data-settings-scope-section][hidden] {
  display: none;
}
