:root {
  color-scheme: light;
  --bg: #efe5d2;
  --surface: rgba(255, 250, 242, 0.88);
  --surface-strong: #fffaf2;
  --surface-soft: rgba(255, 255, 255, 0.72);
  --ink: #1b262c;
  --muted: #68777c;
  --line: rgba(27, 38, 44, 0.11);
  --accent: #0f766e;
  --accent-strong: #0c5f59;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --warn: #c2410c;
  --warn-soft: rgba(194, 65, 12, 0.1);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.1);
  --shadow: 0 18px 48px rgba(21, 30, 35, 0.12);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 22%),
    radial-gradient(circle at top right, rgba(194, 65, 12, 0.11), transparent 18%),
    linear-gradient(180deg, #fbf6eb 0%, #ece0ce 100%);
}

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

button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:active {
  transform: scale(0.98);
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  padding: 12px 14px;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

summary {
  cursor: pointer;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

.app-shell {
  width: min(840px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 14px 0 calc(28px + env(safe-area-inset-bottom));
}

.hero-card,
.panel,
.status-card,
.tab-bar {
  backdrop-filter: blur(18px);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-card,
.panel {
  border-radius: var(--radius-xl);
}

.hero-card,
.panel,
.status-card {
  padding: 16px;
}

.hero-card,
.status-band,
.tab-bar,
.panel,
.control-grid {
  margin-bottom: 12px;
}

.hero-top,
.panel-head,
.panel-actions,
.status-band,
.auth-row,
.session-row,
.approval-actions,
.composer-actions,
.control-grid,
.field-grid,
.quota-grid,
.thread-tools,
.thread-create-actions,
.tab-bar {
  display: flex;
  gap: 10px;
}

.hero-top,
.panel-head,
.session-row {
  align-items: center;
  justify-content: space-between;
}

.eyebrow,
.label {
  display: block;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 6vw, 3rem);
  line-height: 0.98;
  letter-spacing: -0.05em;
}

h2 {
  font-size: 1.03rem;
}

.connection-pill,
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-weight: 700;
}

.connection-pill {
  padding: 8px 12px;
  background: rgba(27, 38, 44, 0.08);
  color: var(--muted);
  font-size: 0.82rem;
}

.connection-pill.online {
  background: var(--accent-soft);
  color: var(--accent);
}

.fold-card,
.subfold {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.62);
}

.fold-summary,
.subfold > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.fold-summary strong,
.fold-summary .label {
  line-height: 1.2;
}

.fold-hint,
.panel-note,
.activity-note,
.quota-note,
#quota-time,
.session-note,
.thread-section-head small {
  color: var(--muted);
  font-size: 0.88rem;
}

.fold-body,
.subfold-body {
  padding: 0 14px 14px;
}

.auth-row,
.session-row {
  margin-top: 10px;
}

.auth-row input {
  flex: 1;
}

.tab-bar {
  padding: 6px;
  border-radius: 18px;
}

.tab-button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
}

.tab-button.active {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.95), rgba(20, 105, 119, 0.92));
  color: #fff;
}

.status-card {
  flex: 1;
  border-radius: 20px;
}

.status-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.status-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.status-card.focus {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.95), rgba(20, 105, 119, 0.92));
  color: #fff;
}

.status-card.focus .label,
.status-card.focus small {
  color: rgba(255, 255, 255, 0.82);
}

.panel-head {
  margin-bottom: 12px;
}

.panel-head.compact {
  margin-bottom: 10px;
}

.panel-actions {
  flex-shrink: 0;
}

.secondary {
  background: rgba(27, 38, 44, 0.07);
  color: var(--ink);
  padding: 10px 14px;
}

.primary-action,
#save-token,
#apply-control-button,
#thread-create-submit {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
}

#logout-button,
#thread-create-cancel,
#thread-archive-button,
#thread-create-toggle,
#restart-button,
#quota-refresh-button,
#refresh-button,
#continue-button {
  padding: 10px 14px;
}

.control-grid {
  align-items: stretch;
}

.control-card,
.quota-card {
  flex: 1;
}

.field-grid,
.quota-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.control-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.pending-panel {
  border-color: rgba(194, 65, 12, 0.2);
  background: linear-gradient(180deg, rgba(255, 246, 236, 0.95), rgba(255, 250, 242, 0.9));
}

.pill {
  padding: 6px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
}

.pill.urgent {
  background: var(--warn-soft);
  color: var(--warn);
}

.approval-box,
.error-banner {
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.approval-box {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(194, 65, 12, 0.14);
}

.error-banner {
  margin-bottom: 12px;
  background: var(--danger-soft);
  border: 1px solid rgba(185, 28, 28, 0.18);
  color: var(--danger);
}

.approval-form {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.approve {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  padding: 11px 14px;
}

.reject {
  background: rgba(185, 28, 28, 0.1);
  color: var(--danger);
  padding: 11px 14px;
}

.thread-fold-body {
  display: grid;
  gap: 12px;
}

.thread-section {
  display: grid;
  gap: 10px;
}

.thread-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.thread-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thread-chip {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  text-align: left;
}

.thread-chip strong,
.thread-chip small {
  display: block;
  white-space: normal;
}

.thread-chip strong {
  font-size: 0.92rem;
}

.thread-chip small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.74rem;
}

.thread-chip[data-active="true"] {
  background: var(--accent-soft);
  border-color: rgba(15, 118, 110, 0.22);
}

.thread-chip.codex-thread[data-current="true"] {
  box-shadow: inset 0 0 0 1px rgba(194, 65, 12, 0.18);
}

.thread-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 10px 0;
}

.message-list,
.event-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.message-list {
  display: grid;
  gap: 10px;
  max-height: 54vh;
  overflow-y: auto;
  padding-right: 2px;
}

.message-item {
  display: flex;
}

.message-item.role-operator {
  justify-content: flex-end;
}

.bubble {
  width: min(100%, 520px);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--line);
}

.message-item.role-operator .bubble {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.95), rgba(20, 105, 119, 0.92));
  color: #fff;
}

.message-item.role-operator .bubble span {
  color: rgba(255, 255, 255, 0.82);
}

.bubble-meta,
.event-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.bubble-meta span,
.event-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

.composer {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.composer-actions {
  justify-content: flex-end;
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-item {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  padding: 12px 14px;
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100vw - 18px);
    padding-top: 10px;
  }

  .hero-card,
  .panel,
  .status-card {
    padding: 14px;
  }

  .status-band,
  .control-grid,
  .auth-row,
  .session-row,
  .panel-actions,
  .approval-actions {
    flex-direction: column;
  }

  .field-grid,
  .quota-grid {
    grid-template-columns: 1fr;
  }

  .panel-actions {
    width: 100%;
  }

  .panel-actions > button,
  .approval-actions > button,
  .composer-actions > button {
    width: 100%;
  }

  .composer-actions {
    display: block;
  }
}
