/* Social Probe — mobile-first UI. Light/dark follows the system. */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #eef0f4;
  --border: #e2e4ea;
  --text: #17181c;
  --muted: #6b7280;
  --accent: #0a84ff;
  --accent-weak: rgba(10, 132, 255, .12);
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,.07);
  --radius: 14px;
  --tabbar-h: calc(58px + env(safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101014;
    --surface: #1a1b21;
    --surface2: #23242c;
    --border: #2e3039;
    --text: #f2f3f7;
    --muted: #9ca3af;
    --accent: #5ec8fa;
    --accent-weak: rgba(94, 200, 250, .14);
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---- layout ---------------------------------------------------------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.appbar .logo { width: 26px; height: 26px; border-radius: 7px; flex: none; }
.appbar h1 { font-size: 16px; font-weight: 700; letter-spacing: .02em; }
.appbar .sub { font-size: 11px; color: var(--muted); margin-top: -2px; }
.appbar .spacer { flex: 1; }
.statusdot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.statusdot.ok { background: var(--ok); }
.statusdot.bad { background: var(--bad); }

main.view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 14px calc(var(--tabbar-h) + 18px); }

/* bottom tab bar (mobile) */
nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 10.5px; min-height: 52px;
}
nav.tabbar button svg { width: 22px; height: 22px; }
nav.tabbar button.active { color: var(--accent); }
nav.tabbar button.desktop-only { display: none; }   /* 手機底欄維持 5 格 */

/* desktop: left rail */
@media (min-width: 900px) {
  #app { flex-direction: row; }
  nav.tabbar {
    position: sticky; top: 0; bottom: auto; height: 100dvh; width: 190px;
    display: flex; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--border); padding: 70px 10px 0;
    gap: 4px;
  }
  nav.tabbar button {
    flex-direction: row; gap: 10px; justify-content: flex-start;
    padding: 10px 14px; border-radius: 10px; font-size: 14px; min-height: 0;
  }
  nav.tabbar button.active { background: var(--accent-weak); }
  nav.tabbar button.desktop-only { display: flex; }
  main.view { padding-bottom: 40px; }
  .appbar { position: fixed; left: 0; right: 0; border-bottom: 0; background: transparent; backdrop-filter: none; pointer-events: none; }
  .appbar > * { pointer-events: auto; }
}

/* ---- components ------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.card .hint { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface2);
  font-weight: 600; font-size: 14px; cursor: pointer; user-select: none;
  transition: filter .12s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #08121a; } }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }

.input, textarea.input, select.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface2); outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.6; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

.seg { display: flex; background: var(--surface2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 7px 10px;
  border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-weak); color: var(--accent);
  padding: 5px 11px; border-radius: 99px; font-size: 13px; font-weight: 600;
}
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0; }

.filterbar { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.filterbar::-webkit-scrollbar { display: none; }
.filterbar .btn.small { flex: none; }
.filterbar .btn.small.active { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .filterbar .btn.small.active { color: #08121a; } }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; background: var(--surface2); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.badge.accent { background: var(--accent-weak); color: var(--accent); }

.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface2); border-radius: 12px; padding: 10px 6px; text-align: center; cursor: pointer; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11.5px; color: var(--muted); }

.list-item {
  padding: 12px 2px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }
.list-item .meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.list-item .excerpt { color: var(--muted); font-size: 13px; }
.list-item .text { font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }

.checkitem { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.checkitem:last-child { border-bottom: 0; }
.checkitem .ico { font-size: 16px; line-height: 1.4; }
.checkitem .body { flex: 1; }
.checkitem .body b { font-size: 14px; }
.checkitem .body p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.checkitem code {
  display: block; background: var(--surface2); border-radius: 8px; padding: 6px 9px;
  font-size: 12px; margin-top: 6px; overflow-x: auto; white-space: pre;
  font-family: ui-monospace, Consolas, monospace;
}

.empty { text-align: center; color: var(--muted); padding: 34px 12px; font-size: 14px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* job progress */
.jobcard { display: flex; align-items: center; gap: 12px; }
.spinner {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* modal — bottom sheet on mobile, dialog on desktop */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.modal {
  background: var(--surface); width: 100%; max-width: 620px;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  max-height: 88dvh; overflow-y: auto; animation: up .18s ease;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal h3 { font-size: 16px; margin-bottom: 10px; }
.modal .actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.modal .actions .btn { flex: 1; min-width: 110px; }
@keyframes up { from { transform: translateY(28px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.switch input { width: 42px; height: 25px; appearance: none; background: var(--surface2); border: 1px solid var(--border); border-radius: 99px; position: relative; transition: background .15s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(17px); }

/* toast */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 10px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  animation: up .2s ease; max-width: 88vw;
}
.toast.err { background: var(--bad); color: #fff; }

/* login */
.login { max-width: 380px; margin: 16vh auto 0; padding: 0 20px; text-align: center; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 14px; }
.login h1 { font-size: 20px; margin-bottom: 6px; }
.login p { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); flex: none; }
.kv b { text-align: right; word-break: break-all; font-weight: 600; }

.metricbar { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.metricbar b { color: var(--text); }

.skeleton { border-radius: 10px; background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%); background-size: 200% 100%; animation: shimmer 1.1s infinite; height: 58px; margin-bottom: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* guide (教學) */
.guide details { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; background: var(--surface); overflow: hidden; }
.guide summary { padding: 12px 14px; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "›"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.guide details[open] summary::after { transform: rotate(90deg); }
.guide .g-body { padding: 0 14px 14px; font-size: 14px; }
.guide .g-body p { margin-bottom: 8px; }
.guide .g-body ol, .guide .g-body ul { padding-left: 20px; margin-bottom: 8px; }
.guide .g-body li { margin-bottom: 5px; }
.guide .g-body code { background: var(--surface2); border-radius: 6px; padding: 1px 6px; font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; }

/* analysis flags */
.flag { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.flag:last-child { border-bottom: 0; }
.flag .f-ico { flex: none; font-size: 15px; }
.flag b { display: block; font-size: 14px; margin-bottom: 2px; }
.flag p { font-size: 13px; color: var(--muted); }
.stagebanner { border-radius: 12px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 12px; background: var(--accent-weak); }
