/* ─── Theme Tokens ─── */

[data-theme="dark"] {
  --bg: #0c0c0c;
  --bg-raised: #161616;
  --bg-inset: #111111;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8e8e8;
  --text-secondary: #888888;
  --text-tertiary: #555555;
  --accent: #d4423a;
  --accent-soft: rgba(212, 66, 58, 0.12);
  --accent-text: #ef6f68;
  --surface-input: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --pill-ok-bg: rgba(72, 187, 120, 0.12);
  --pill-ok-text: #68d391;
  --pill-bad-bg: rgba(245, 101, 101, 0.12);
  --pill-bad-text: #fc8181;
  --code-bg: #1a1a1a;
  --code-text: #c4c4c4;
  --msg-user-border: rgba(212, 66, 58, 0.3);
  --msg-assistant-border: rgba(255, 255, 255, 0.12);
  --toggle-track: #2a2a2a;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 8px 30px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg: #f5f4f0;
  --bg-raised: #ffffff;
  --bg-inset: #eae9e4;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #1a1a1a;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --accent: #c4362e;
  --accent-soft: rgba(196, 54, 46, 0.08);
  --accent-text: #b5302a;
  --surface-input: rgba(0, 0, 0, 0.03);
  --surface-hover: rgba(0, 0, 0, 0.04);
  --pill-ok-bg: rgba(56, 161, 105, 0.1);
  --pill-ok-text: #276749;
  --pill-bad-bg: rgba(229, 62, 62, 0.1);
  --pill-bad-text: #c53030;
  --code-bg: #f0efea;
  --code-text: #3a3a3a;
  --msg-user-border: rgba(196, 54, 46, 0.25);
  --msg-assistant-border: rgba(0, 0, 0, 0.08);
  --toggle-track: #d4d3ce;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-elevated: 0 8px 30px rgba(0, 0, 0, 0.08);
}

/* ─── Reset & Base ─── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  font-size: clamp(20px, 2.5vw, 26px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 0;
}

h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 0;
}

h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ─── Layout ─── */

.layout {
  position: relative;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1px;
  min-height: 100vh;
  background: var(--border);
}

.panel {
  padding: 32px;
  background: var(--bg);
  transition: background 0.3s ease;
}

.panel-chat {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 24px;
  height: 100vh;
  overflow: hidden;
}

.panel-debug {
  background: var(--bg-raised);
  overflow-y: auto;
}

/* ─── Header Bar ─── */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.top-bar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ─── Theme Toggle ─── */

.theme-toggle {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--toggle-track);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
}

.theme-toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] .theme-toggle::after {
  transform: translateX(24px);
}

.theme-toggle-label {
  font-size: 14px;
  line-height: 1;
  user-select: none;
}

/* ─── Config Card ─── */

.config-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  transition: background 0.3s ease, border-color 0.3s ease;
}

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

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

.checkbox-field {
  align-content: start;
}

.field > span {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.03em;
}

/* ─── Form Controls ─── */

input, select, textarea, button {
  font-family: inherit;
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--surface-input);
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

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

select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--text-tertiary) 50%) calc(100% - 18px) calc(50% - 3px) / 7px 7px no-repeat,
    linear-gradient(135deg, var(--text-tertiary) 50%, transparent 50%) calc(100% - 13px) calc(50% - 3px) / 7px 7px no-repeat,
    var(--surface-input);
  padding-right: 38px;
}

/* ─── Toggle Switch (for checkboxes) ─── */

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--surface-input);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.toggle:hover {
  border-color: var(--border-strong);
}

/* ─── Buttons ─── */

button {
  border: 0;
  border-radius: 6px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, opacity 0.15s ease;
}

button[type="submit"] {
  background: var(--accent);
  color: #fff;
}

button[type="submit"]:hover:not(:disabled) {
  opacity: 0.88;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}

button.secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

button:disabled {
  opacity: 0.4;
  cursor: wait;
}

.server-state, .composer-actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* ─── Advanced Config ─── */

.advanced-config {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.advanced-config summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  list-style: none;
  transition: color 0.15s ease;
}

.advanced-config summary:hover {
  color: var(--text);
}

.advanced-config summary::-webkit-details-marker {
  display: none;
}

.advanced-config summary::after {
  content: "+";
  float: right;
  font-family: var(--font-mono, monospace);
  color: var(--accent);
}

.advanced-config[open] summary::after {
  content: "\2212";
}

.advanced-grid {
  margin-top: 14px;
}

/* ─── Pills ─── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
}

.pill-muted {
  background: var(--surface-input);
  color: var(--text-secondary);
}

.pill-outline {
  border: 1px solid var(--border-strong);
  color: var(--text-tertiary);
}

.pill-ok {
  background: var(--pill-ok-bg);
  color: var(--pill-ok-text);
}

.pill-bad {
  background: var(--pill-bad-bg);
  color: var(--pill-bad-text);
}

/* ─── Chat Log ─── */

.chat-log {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  min-height: 260px;
  padding-right: 8px;
}

.message {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-raised);
  animation: fade-in 0.3s ease both;
  transition: background 0.3s ease;
}

.message-user {
  border-left: 3px solid var(--accent);
}

.message-assistant {
  border-left: 3px solid var(--text-tertiary);
}

.message-progress {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}

.message-progress-complete {
  opacity: 0.75;
}

.message-system {
  border-style: dashed;
  border-left: 3px solid var(--text-tertiary);
}

.message-meta {
  margin-bottom: 6px;
  color: var(--text-tertiary);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

.message-body {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.7;
}

/* ─── Progress ─── */

.progress-title {
  margin-bottom: 8px;
  color: var(--accent-text);
  font-weight: 600;
  font-size: 12px;
}

.progress-log {
  display: grid;
  gap: 4px;
}

.progress-line {
  color: var(--text-secondary);
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 11px;
}

/* ─── Composer ─── */

.composer {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  transition: background 0.3s ease, border-color 0.3s ease;
}

/* ─── Debug Panel ─── */

.debug-header {
  animation: fade-in 0.5s ease both;
}

.summary-cards {
  margin: 20px 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  transition: background 0.3s ease;
}

.summary-card-label {
  display: block;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.summary-card-value {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.log-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.code-block {
  margin: 0;
  padding: 14px 16px;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 11.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 360px;
  overflow-y: auto;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ─── Animations ─── */

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Responsive ─── */

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

@media (max-width: 720px) {
  .panel {
    padding: 20px;
  }

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