:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #128c7e;
  --accent-dark: #0e6f64;
  --assistant-bubble: #ffffff;
  --user-bubble: #dcf8c6;
  --tool-bubble: #f0f0f0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  /* charts */
  --chart-accent: #128c7e;
  --chart-fill: rgba(18, 140, 126, 0.18);
  --chart-grid: #e6e8eb;
  --chart-text: #6b7280;
  --tile-accent: #128c7e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --panel: #161b22;
    --text: #e6edf3;
    --muted: #9198a1;
    --border: #2a2f37;
    --accent: #25d366;
    --accent-dark: #1fae56;
    --assistant-bubble: #1f2530;
    --user-bubble: #044c3f;
    --tool-bubble: #1a1f28;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    --chart-accent: #25d366;
    --chart-fill: rgba(37, 211, 102, 0.16);
    --chart-grid: #2a2f37;
    --chart-text: #9198a1;
    --tile-accent: #25d366;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1120px;
  margin: 0 auto;
  background: var(--bg);
}

.app-header {
  padding: 0.9rem 1.25rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 2;
}

.header-title h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.15rem 0 0;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Views ---------- */
.view {
  display: none;
  flex: 1;
  min-height: 0;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* ---------- Dashboard ---------- */
.dash-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.25rem 2rem;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: var(--card-shadow);
}

.tile .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.tile .label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.tile .value .accent {
  color: var(--tile-accent);
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--card-shadow);
  min-width: 0;
}

.card.span-2 {
  grid-column: span 2;
}

.card h3 {
  margin: 0 0 0.7rem;
  font-size: 0.98rem;
  font-weight: 700;
}

.card h3 .sub {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 0.35rem;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap.tall {
  height: 420px;
}

.dash-footer {
  margin-top: 1.1rem;
  text-align: center;
}

@media (max-width: 720px) {
  .cards {
    grid-template-columns: 1fr;
  }
  .card.span-2 {
    grid-column: span 1;
  }
}

/* ---------- Chat ---------- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.message {
  display: flex;
  max-width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant,
.message.tool {
  justify-content: flex-start;
}

.bubble {
  max-width: 75%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}

.message.assistant .bubble {
  background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.tool .bubble {
  background: var(--tool-bubble);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  border: 1px dashed var(--border);
  max-width: 90%;
}

.message.error .bubble {
  background: #fde2e1;
  color: #8a1f1f;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(127, 127, 127, 0.15);
  padding: 0.1em 0.3em;
  border-radius: 4px;
  font-size: 0.9em;
}

.bubble strong {
  font-weight: 700;
}

/* Suggestion chips under the intro message */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1.25rem 0.6rem;
}

.suggestions .chip {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.suggestions .chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tool-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tool-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

.composer {
  display: flex;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

#message-input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

#message-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#send-button {
  padding: 0.7rem 1.3rem;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

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

#send-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
