/* Apple-minimalist: SF system stack, generous whitespace, restrained palette, subtle depth. */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 30px rgba(0, 0, 0, 0.05);
  --radius: 18px;
  --maxw: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --surface: #1c1c1e; --text: #f5f5f7; --muted: #98989d;
    --line: rgba(255, 255, 255, 0.1); --accent: #2997ff; --accent-soft: rgba(41, 151, 255, 0.14);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 10px 40px rgba(0, 0, 0, 0.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.muted { color: var(--muted); font-weight: 400; }
.err { color: #ff3b30; }

/* ── Gate ── */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 48px 40px; width: min(380px, 92vw); text-align: center;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.gate .mark { font-size: 42px; }
.gate h1 { font-size: 34px; letter-spacing: -0.02em; margin: 12px 0 2px; font-weight: 600; }
.gate form { margin-top: 26px; display: grid; gap: 12px; }
input {
  font: inherit; padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
button {
  font: inherit; font-weight: 500; padding: 13px 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; cursor: pointer; transition: transform 0.12s ease, filter 0.2s;
}
button:hover { filter: brightness(1.05); }
button:active { transform: scale(0.98); }

/* ── App shell ── */
main { max-width: var(--maxw); margin: 0 auto; padding: 22px clamp(16px, 4vw, 40px) 64px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 2px 22px; }
.brand { font-size: 21px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ── Stat tiles ── */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.tile .k { font-size: clamp(24px, 3vw, 32px); font-weight: 600; letter-spacing: -0.02em; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── Chart grid ── */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.chart-wrap { position: relative; height: 260px; }
.card.wide .chart-wrap { height: 300px; }

/* ── Chat ── */
.chat { margin-top: 16px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; padding: 4px 2px 14px; }
.bubble { padding: 11px 15px; border-radius: 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; animation: rise 0.35s cubic-bezier(0.16,1,0.3,1); }
.bubble.u { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.a { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.a a { color: var(--accent); }
.chat-form { display: flex; gap: 10px; }
.chat-form input { flex: 1; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { font-size: 13px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; transition: color 0.2s, border-color 0.2s; }
.chip:hover { color: var(--text); border-color: var(--accent); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }

.foot { margin-top: 30px; text-align: center; font-size: 12.5px; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%,60%,100% { opacity: 0.3; } 30% { opacity: 1; } }
@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
