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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #242424;
  --border: #2a2a2a;
  --text: #e4e4e4;
  --text-muted: #888;
  --accent: #6c63ff;
  --accent-hover: #5a52d9;
  --user-bg: #6c63ff;
  --agent-bg: #1e1e1e;
  --tool-bg: #1a1f2e;
  --radius: 12px;
  --logo-invert: 0;
  --placeholder-color: #555;
  --scrollbar-thumb: #333;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-hover: #eaeaea;
  --border: #ddd;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #6c63ff;
  --accent-hover: #5a52d9;
  --user-bg: #6c63ff;
  --agent-bg: #ffffff;
  --tool-bg: #eef0f8;
  --logo-invert: 1;
  --placeholder-color: #999;
  --scrollbar-thumb: #ccc;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 960px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

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

.logo {
  height: 56px;
  width: auto;
  flex-shrink: 0;
}

.logo svg {
  height: 100%;
  width: auto;
  display: block;
}

/* Unclassed paths = subtitle text: adapt to theme */
.logo svg path:not([class]) {
  fill: #ffffff;
}

[data-theme="light"] .logo svg path:not([class]) {
  fill: #1a1a1a;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

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

#theme-toggle {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#theme-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

#new-chat {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

#new-chat:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ── Chat area ──────────────────────────────── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}

.welcome-logo img {
  height: 64px;
  width: auto;
  margin-bottom: 16px;
  opacity: 0.8;
}

.placeholder-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome h2 {
  font-size: 1.2rem;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome p {
  margin-bottom: 8px;
}

.welcome .hint {
  font-size: 0.85rem;
  font-style: italic;
  color: #666;
}

/* ── Messages ───────────────────────────────── */
.msg {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.agent {
  align-self: flex-start;
  background: var(--agent-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.status {
  align-self: center;
  background: none;
  border: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

/* streaming cursor */
.msg.agent.streaming::after {
  content: "▊";
  animation: blink 0.7s steps(2) infinite;
}

@keyframes blink {
  0% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Loading greet ──────────────────────────── */
.loading-greet {
  margin: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.dot-pulse {
  display: inline-flex;
  gap: 4px;
}

.dot-pulse::before,
.dot-pulse::after,
.dot-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.dot-pulse::before,
.dot-pulse::after {
  content: "";
  display: inline-block;
}

.dot-pulse::before {
  animation-delay: -0.3s;
}

.dot-pulse::after {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Input bar ──────────────────────────────── */
.input-bar {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-bar textarea {
  flex: 1;
  resize: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
}

.input-bar textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.input-bar textarea::placeholder {
  color: var(--placeholder-color);
}

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0 20px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

#send-btn:hover {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* scrollbar */
.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* ── Gauge Panel ────────────────────────────── */
.gauge-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.gauge-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.gauge-toggle:hover {
  background: var(--surface-hover);
  transform: scale(1.08);
}

.gauge-panel-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: opacity 0.2s, transform 0.2s;
  max-height: 80vh;
  overflow-y: auto;
}

.gauge-panel.collapsed .gauge-panel-body {
  opacity: 0;
  transform: translateX(10px) scale(0.95);
  pointer-events: none;
  position: absolute;
  visibility: hidden;
}

#gpu-gauges {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gauge-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.gauge-column-header {
  font-size: 0.65rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: center;
}

.gauge-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.gauge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.gauge {
  width: 90px;
  height: 60px;
}

.gauge-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s;
}

.gauge-fill.gauge-usage {
  stroke: var(--accent);
}

.gauge-fill.gauge-temp {
  stroke: #ff6b35;
}

.gauge-fill.gauge-vram {
  stroke: #f59e0b;
}

.gauge-fill.gauge-tokens {
  stroke: #10b981;
}

.gauge-value {
  fill: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-anchor: middle;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.gauge-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* GPU unavailable dim state */
.gauge-container.unavailable {
  opacity: 0.35;
}

.gauge-container.unavailable .gauge-label::after {
  content: " (n/a)";
  font-style: italic;
}
