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

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e8eaee;
  --text: #1f2430;
  --muted: #8a90a0;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --accent-soft: #fff3ea;
  --blue: #3b82f6;
  --red: #ef4444;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.05);
  --radius: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-size: 15px;
}

#pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
#pin-overlay[hidden] { display: none; }
.pin-card {
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 48px;
  text-align: center;
  max-width: 360px;
  width: calc(100% - 48px);
}
.pin-mark {
  width: 52px; height: 52px; border-radius: 14px;
  font-size: 1.5rem; margin: 0 auto 16px;
}
.pin-card h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 6px; }
.pin-card p { color: var(--muted); font-size: 0.88rem; margin-bottom: 20px; }
#pin-input {
  width: 100%;
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.5em;
  padding: 12px 0 12px 0.5em;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
}
#pin-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#pin-error { color: #b42318; font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent);
  color: #fff; font-weight: 700; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center;
}
header h1 { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }

main#chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg { max-width: 880px; width: 100%; margin: 0 auto; }

.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 18px;
  margin-left: auto;
  max-width: 75%;
  width: fit-content;
  box-shadow: var(--shadow);
  font-weight: 500;
}

.msg.assistant .bubble {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.status {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
th, td { padding: 9px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-soft); }
td:not(:first-child) { font-variant-numeric: tabular-nums; }
.row-note { color: var(--muted); font-size: 0.78rem; margin: 6px 2px; }

.chart-wrap {
  margin: 12px 0;
  max-height: 340px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.view-toggle {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-family: inherit;
  margin: 6px 0;
}
.view-toggle:hover { background: #ffe8d8; }

.answer { line-height: 1.6; margin-top: 6px; }
.answer p { margin: 0 0 10px; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 6px 0 10px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer strong { font-weight: 600; }
.answer h1, .answer h2, .answer h3, .answer h4 {
  font-size: 0.95rem; font-weight: 600; margin: 12px 0 6px;
}
.answer code {
  background: var(--bg); border-radius: 5px; padding: 1px 6px;
  font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 0.82rem;
}
.answer table { margin: 8px 0; }
.answer table th, .answer table td { border: 1px solid var(--border); padding: 5px 10px; }
.error {
  color: #b42318;
  background: #fef3f2;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

#examples {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 0 24px 12px;
}
.example {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  color: var(--muted);
  box-shadow: var(--shadow);
  transition: all 0.12s ease;
}
.example:hover { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }

footer { padding: 12px 24px 22px; background: var(--bg); }
#ask-form { display: flex; gap: 10px; max-width: 880px; margin: 0 auto; }
#question {
  flex: 1;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
#question::placeholder { color: var(--muted); }
#question:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#send {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 26px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.35);
  transition: background 0.12s ease;
}
#send:hover { background: var(--accent-dark); }
#send:disabled { opacity: 0.5; cursor: wait; }
