/* elio.ai mobile chat. Mobile first; tokens flip for dark mode. */
:root {
  --bg: #ffffff;
  --surface: #f3f4f6;
  --surface-strong: #e9ebef;
  --text: #16181d;
  --text-muted: #5f6672;
  --border: #e3e5ea;
  --border-strong: #c9cdd4;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e7effc;
  --danger: #c2372f;
  --radius: 18px;
  --app-h: 100dvh;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #23262d;
    --surface-strong: #2c3038;
    --text: #eceef2;
    --text-muted: #a2a8b3;
    --border: #2f333b;
    --border-strong: #464b55;
    --accent: #5b8ff0;
    --accent-text: #0d1117;
    --accent-soft: #1f2b44;
    --danger: #ff7b72;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  /* Google Fonts (base.html); the system fonts after them cover a slow or blocked font load. */
  font: 16px/1.55 "Noto Sans", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
/* Only 400 / 500 / 600 are loaded: keep bold at 600 instead of the default 700. */
strong, b, th { font-weight: 600; }
/* Line icons. Skips the Google button: GIS draws its G logo as an inline svg, and a stroke here outlines it. */
svg:where(:not(.google-button *)) { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app {
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-weight: 600; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.topbar-actions form { margin: 0; }

.avatar {
  flex: none;
  display: block;
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface);
}
.avatar-lg { width: 64px; height: 64px; margin: 0 auto; }

.btn-ghost, .btn-icon {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px;
  border: 0; border-radius: 18px;
  background: transparent;
  padding: 0 12px;
  font-size: 14px;
}
.btn-icon { width: 36px; padding: 0; justify-content: center; color: var(--text-muted); }
.btn-ghost:active, .btn-icon:active { background: var(--surface); }
@media (hover: hover) {
  .btn-ghost:hover, .btn-icon:hover { background: var(--surface); }
}

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
}

.welcome { text-align: center; padding: 15vh 16px 0; color: var(--text-muted); }
.welcome h1 { font-size: 20px; color: var(--text); margin: 14px 0 6px; font-weight: 600; }
.welcome p { margin: 0; font-size: 15px; }

/* ── Messages ───────────────────────────────────────────────────────────── */
.row { display: flex; gap: 8px; margin: 0 0 14px; }
.row-user { justify-content: flex-end; }
.row-bot .avatar { margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: calc(100% - 40px); }
.row-user .stack { align-items: flex-end; max-width: 85%; }

.bubble {
  padding: 9px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  overflow-wrap: anywhere;
  font-size: 15px;
}
.row-bot .bubble { border-top-left-radius: 6px; }
.row-user .bubble {
  background: var(--accent);
  color: var(--accent-text);
  border-top-right-radius: 6px;
  white-space: pre-wrap;
}
.row-user.pending .bubble { opacity: .75; }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child, .bubble pre:last-child { margin-bottom: 0; }
.bubble .md-h { font-weight: 600; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble a { color: var(--accent); word-break: break-all; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-strong); padding: 1px 5px; border-radius: 5px; }
.bubble pre { margin: 0 0 8px; padding: 10px; background: var(--surface-strong); border-radius: 10px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: 0 0 8px; padding-left: 10px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.bubble hr { border: 0; border-top: 1px solid var(--border-strong); margin: 10px 0; }
.bubble img { display: block; max-width: 100%; border-radius: 10px; margin: 6px 0; }

.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; width: 100%; }
.images a { display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface); }
.images img { width: 100%; height: 100%; object-fit: cover; display: block; }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 13px 14px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.notice { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--danger); }
.notice button, .notice a { border: 1px solid var(--border-strong); border-radius: 14px; background: var(--bg); padding: 3px 12px; font-size: 13px; color: var(--text); text-decoration: none; }

/* ── Composer ───────────────────────────────────────────────────────────── */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 21px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;   /* ≥ 16px keeps iOS from zooming in on focus */
  line-height: 1.45;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.btn-send {
  flex: none;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-send[aria-busy="true"] { opacity: .5; }

/* ── Table card (Markdown tables, product comparisons) ───────────────────── */
/* One column per item, straight on the page (no box): each cell is "label over
   value" with its own divider, so rows line up across items. */
.tcard {
  --col-w: 150px;
  --col-gap: 16px;
  width: 100%;
}
/* In a reply, the card also takes the avatar's column (32px + 8px gap): full width, like the text bubbles' row. */
.row-bot .stack > .tcard { width: calc(100% + 40px); margin-left: -40px; }
.tcard-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 2px 0 10px;
}
.tcard-title { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.tcard-pos { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.tcard-nav { display: flex; gap: 6px; flex: none; }
@media (hover: none) { .tcard-nav { display: none; } }   /* phones: swipe */
.tcard-nav button {
  width: 30px; height: 30px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: 50%;
  background: var(--bg);
  transition: opacity .15s;
}
.tcard-nav button svg { width: 16px; height: 16px; }
.tcard-nav button.at-edge { opacity: .35; }

.tcard-scroll {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.tcard-scroll::-webkit-scrollbar { display: none; }
.tcard table { border-collapse: collapse; border-spacing: 0; line-height: 1.45; }
.tcard th, .tcard td {
  width: var(--col-w); min-width: var(--col-w); max-width: var(--col-w);
  padding: 0 var(--col-gap) 0 0;      /* the gap sits inside the column, after its dividers */
  text-align: left; vertical-align: top;
  overflow-wrap: anywhere;
  scroll-snap-align: start;
}
/* The scroll end is a snap point too, or mandatory snapping can't reach the last column. */
.tcard th:last-child, .tcard td:last-child { scroll-snap-align: end; padding-right: 0; }

/* Dividers belong to the cell (so a row's lines sit at one height even when one
   value wraps more), and stop short of the gap between items. */
.tcard th, .tcard td { position: relative; }
.tcard th::after, .tcard td::after {
  content: '';
  position: absolute; left: 0; right: var(--col-gap); bottom: 0;
  border-bottom: 1px solid var(--border);
}
.tcard th::after { border-bottom-color: var(--border-strong); }
.tcard th:last-child::after, .tcard td:last-child::after { right: 0; }
.tcard tr:last-child td::after { display: none; }

.tcard-name {
  font-size: 16px; font-weight: 600; line-height: 1.35;
  padding-bottom: 12px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.tcard-cell { padding: 12px 0; }
.tcard-label { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.tcard-value { font-size: 15px; }

.tcard-dots { display: flex; justify-content: center; gap: 4px; padding: 4px 0 2px; }
.tcard-dots span { height: 4px; width: 4px; border-radius: 2px; background: var(--border-strong); transition: width .2s, background .2s; }
.tcard-dots span.on { width: 14px; background: var(--text-muted); }

/* A table whose items all fit: no navigation chrome. */
.tcard.fits .tcard-nav, .tcard.fits .tcard-pos, .tcard.fits .tcard-dots { display: none; }
.tcard.fits.untitled .tcard-head { display: none; }
.tcard.fits th, .tcard.fits td { scroll-snap-align: none; }

@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: .6; }
}

/* ── Login ──────────────────────────────────────────────────────────────── */
.login {
  min-height: var(--app-h);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 16px 0 6px; }
.login-card p { margin: 0; color: var(--text-muted); font-size: 15px; }
.google-button { display: flex; justify-content: center; min-height: 44px; margin: 28px 0 12px; }
.login-error { color: var(--danger) !important; margin-bottom: 8px !important; }
.login-hint { font-size: 13px !important; margin-top: 20px !important; }
