:root {
  --accent: #29D982; --accent2: #51a0ff; --bg: #000; --surface: #121212;
  --elev: #1f1f1f; --text: #fff; --muted: #a6a6a6; --weak: #f25252; --warn: #f3c733;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.55; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.logo { font-size: 40px; font-weight: 900; } .logo span { color: var(--accent); }
.logo.sm { font-size: 20px; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.login-box { max-width: 360px; } .login-box .muted { line-height: 1.6; }
#gbtn { display: flex; justify-content: center; margin: 20px 0; }

/* App shell */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: rgba(0,0,0,.85); backdrop-filter: blur(8px); border-bottom: 1px solid #1c1c1c; }
.topbar-extra { display: flex; gap: 8px; align-items: center; }
main { flex: 1; max-width: 760px; width: 100%; margin: 0 auto; padding: 16px 16px 90px; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: rgba(0,0,0,.92);
  backdrop-filter: blur(8px); border-top: 1px solid #1c1c1c; padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; text-align: center; color: var(--muted); font-size: 11px; padding: 8px 0; display: flex; flex-direction: column; gap: 2px; }
.tabbar a .ic { font-size: 20px; }
.tabbar a.active { color: var(--accent); }

/* Generic */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.btn { background: var(--accent); color: #000; font-weight: 700; border: none; border-radius: 12px; padding: 11px 18px; font-size: 15px; cursor: pointer; }
.btn.sec { background: var(--elev); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); padding: 6px 10px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
input, select, textarea { background: var(--elev); color: var(--text); border: 1px solid #2a2a2a; border-radius: 10px; padding: 10px 12px; font-size: 15px; font-family: inherit; width: 100%; }
label.fld { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--elev); font-size: 13px; margin: 0 6px 6px 0; cursor: pointer; }
.chip.on { background: var(--accent); color: #000; font-weight: 600; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; font-weight: 700; }
.flag-high, .flag-low { color: var(--weak); } .flag-attention { color: var(--warn); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.err { color: var(--weak); font-size: 13px; }
.muted-row { color: var(--muted); font-size: 13px; }
.divider { height: 1px; background: #1c1c1c; margin: 10px 0; }

/* Chat */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 58px - 64px); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 4px 2px 12px; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; margin: 10px 0; white-space: normal; }
.bubble.user { background: var(--accent); color: #000; margin-left: auto; white-space: pre-wrap; }
.bubble.ai { background: var(--surface); }
.bubble.ai table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 8px 0; }
.bubble.ai th, .bubble.ai td { border: 1px solid #2c2c2c; padding: 5px 8px; }
.bubble.ai th { background: var(--elev); }
.sources { color: var(--muted); font-size: 12px; margin: 4px 2px 0; }
.process { font-size: 12px; color: var(--muted); margin: 6px 0; }
.process summary { cursor: pointer; }
.suggest { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.suggest button { text-align: left; background: var(--elev); color: var(--text); border: none; border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.chat-input { display: flex; gap: 8px; padding: 8px 2px; align-items: flex-end; }
.chat-input textarea { resize: none; max-height: 120px; }
.asking { font-size: 12px; color: var(--muted); padding: 2px 2px 6px; }
.metric-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #1a1a1a; }
.metric-row:last-child { border-bottom: none; }
.list-item { padding: 12px 0; border-bottom: 1px solid #1a1a1a; cursor: pointer; }
.list-item:last-child { border-bottom: none; }

/* Toast */
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--elev);
  color: var(--text); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 100; box-shadow: 0 4px 20px rgba(0,0,0,.5); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
