/* ChaiNotify dashboard v1.1 — one design system (dark, amber accent). */

:root {
  --bg: #0b0c10;
  --bg-glow: rgba(232, 176, 75, .07);
  --surface: #13151b;
  --surface-2: #181b22;
  --surface-3: #20242c;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .13);
  --text: #eceef2;
  --text-2: #b8bdc7;
  --muted: #7f8795;
  --faint: #5c6370;
  --accent: #e8b04b;
  --accent-ink: #1b1406;
  --accent-soft: rgba(232, 176, 75, .14);
  --ok: #4cc38a;
  --ok-soft: rgba(76, 195, 138, .15);
  --warn: #f0b429;
  --warn-soft: rgba(240, 180, 41, .13);
  --danger: #ef5b5f;
  --danger-soft: rgba(239, 91, 95, .14);
  --info-soft: rgba(120, 140, 170, .12);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 10px 30px rgba(0, 0, 0, .25);
  --font: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --user-font-scale: 1;
  --message-gap: 14px;
  --chat-color: transparent;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: auto; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(1200px 500px at 50% -120px, var(--bg-glow), transparent 70%), var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.icon-btn, .soft-btn, .primary-btn, .tab, .login-btn, .group-menu-btn, .lightbox-btn, .toast-action {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
  -webkit-user-select: none;
  user-select: none;
}
.icon-btn:active, .soft-btn:active, .primary-btn:active, .tab:active { transform: scale(.97); }
.icon-btn {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 0 13px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.alert { border-color: rgba(239, 91, 95, .55); color: #ffb4b6; background: var(--danger-soft); }
.btn-icon { font-size: 15px; line-height: 1; opacity: .9; }
.close-btn { padding: 0; width: 40px; justify-content: center; }
.soft-btn {
  min-height: 38px; padding: 0 13px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.soft-btn:hover { background: var(--surface-3); color: var(--text); }
.soft-btn.danger { color: #ff9b9e; }
.soft-btn.danger:hover { background: var(--danger-soft); border-color: rgba(239, 91, 95, .4); }
.toggle-btn.active { background: var(--accent-soft); border-color: rgba(232, 176, 75, .45); color: var(--accent); }
.primary-btn {
  width: 100%; min-height: 44px; padding: 0 16px;
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  font-size: 14px; font-weight: 800;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn.compact { width: auto; min-height: 36px; font-size: 13px; }
.full-btn { width: 100%; margin-top: 10px; }

/* ---------- boot & login ---------- */
.boot-screen { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 16px; color: var(--muted); }
.boot-screen.boot-error p { color: #ffb4b6; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%);
  padding: 34px 28px 26px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow);
  text-align: center;
}
.mark, .brand-mark {
  display: grid; place-items: center;
  background: linear-gradient(145deg, #f3c56b, #d38f2c);
  color: var(--accent-ink); font-weight: 900;
}
.mark { width: 58px; height: 58px; margin: 0 auto 18px; border-radius: 18px; font-size: 26px; box-shadow: 0 8px 26px rgba(232, 176, 75, .25); }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.login-card h1 { margin: 6px 0 4px; font-size: 30px; letter-spacing: -.02em; }
.desc { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
#loginForm { display: grid; gap: 10px; text-align: left; }
#loginForm label { color: var(--text-2); font-size: 13px; font-weight: 600; }
#code {
  height: 52px; padding: 0 16px;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: 22px; letter-spacing: .3em; text-align: center;
}
#code:focus { border-color: var(--accent); outline: none; }
.login-btn { min-height: 50px; background: var(--accent); border-color: transparent; color: var(--accent-ink); font-size: 16px; font-weight: 800; }
.login-msg { min-height: 20px; margin: 0; color: #ffb4b6; font-size: 13px; text-align: center; }
.login-foot { margin-top: 18px; display: flex; justify-content: center; align-items: center; gap: 8px; color: var(--faint); font-size: 12px; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* ---------- app shell ---------- */
.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 18px calc(26px + var(--safe-bottom));
  font-size: calc(15px * var(--user-font-scale));
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin: 0 -18px 12px; padding: 10px 18px;
  background: rgba(11, 12, 16, .82);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: none; border-radius: 12px; font-size: 18px; }
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -.01em; }
.status-chip { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.status-dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.header-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.metric-chip {
  min-height: 40px; padding: 0 12px;
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.metric-chip b { font-size: 13px; font-variant-numeric: tabular-nums; }
.metric-chip span { color: var(--faint); font-size: 10px; }

/* ---------- health banner ---------- */
.health-banner { display: grid; gap: 8px; margin-bottom: 12px; }
.health-issue {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid transparent; font-size: 14px; font-weight: 600; line-height: 1.45;
}
.health-issue::before { content: ""; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; flex: none; background: currentColor; }
.health-issue.error { background: var(--danger-soft); border-color: rgba(239, 91, 95, .35); color: #ffb4b6; }
.health-issue.warn { background: var(--warn-soft); border-color: rgba(240, 180, 41, .3); color: #f6d38b; }
.health-issue.info { background: var(--info-soft); border-color: var(--line); color: var(--text-2); font-weight: 500; }

/* ---------- metrics & filters ---------- */
.live-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.live-metrics > div {
  padding: 9px 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.live-metrics span { display: block; color: var(--faint); font-size: 11px; }
.live-metrics b { display: block; margin-top: 2px; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.filter-bar { display: grid; gap: 6px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  min-height: 36px; padding: 0 13px;
  background: transparent; border-color: transparent; color: var(--muted);
  font-size: 14px; font-weight: 650; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { background: var(--text); color: #111318; }
.tab > span:not(.unread-badge) {
  min-width: 22px; padding: 1px 7px; border-radius: 99px;
  background: rgba(255, 255, 255, .07); font-size: 12px; text-align: center;
}
.tab.active > span:not(.unread-badge) { background: rgba(0, 0, 0, .1); }
.chat-tabs .tab { min-height: 32px; font-size: 13px; }
.chat-tab.pinned::before { content: "📌"; font-size: 11px; }
.chat-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; font-style: normal; }
.unread-badge {
  min-width: 20px; padding: 1px 6px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; text-align: center;
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 10px 0 14px; padding: 10px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.source-state { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 13px; }
.source-state span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.mini-dot.ok { background: var(--ok); }
.mini-dot.off { background: var(--danger); }
.toolbar-buttons { display: flex; gap: 6px; flex: none; }

/* ---------- message cards ---------- */
.notification-list { display: flex; flex-direction: column; gap: var(--message-gap); }
.group-card {
  position: relative;
  display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 12px;
  padding: 14px 16px 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: card-in .22s ease-out;
}
.group-card::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--chat-color);
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.avatar-wrap { width: 42px; height: 42px; }
.avatar-img, .avatar-fallback { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.avatar-fallback { display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-weight: 800; }
.group-main { min-width: 0; }
.group-head { display: flex; align-items: center; gap: 8px; min-width: 0; margin-bottom: 4px; }
.sender { font-weight: 750; font-size: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.platform-pill {
  flex: none; padding: 1px 7px; border-radius: 99px;
  background: var(--surface-3); color: var(--muted); font-size: 11px; font-weight: 700;
}
.chat-label { min-width: 0; color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-menu-btn {
  margin-left: auto; flex: none;
  width: 34px; height: 30px;
  background: transparent; border-color: transparent; color: var(--muted);
  font-size: 18px; line-height: 1;
}
.group-menu-btn:hover { background: var(--surface-3); color: var(--text); }
.message-stack { display: flex; flex-direction: column; }
.message-divider { height: 1px; margin: 8px 0; background: var(--line); }
.message-row { display: flex; align-items: flex-end; gap: 10px; border-radius: 12px; }
.message-row.important { margin: 2px -8px; padding: 8px; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.message-row.inbox .message-body::before {
  content: "收件匣"; display: inline-block; margin-bottom: 4px; padding: 1px 7px; border-radius: 99px;
  background: var(--info-soft); color: var(--text-2); font-size: 11px; font-weight: 700;
}
.message-body { flex: 1; min-width: 0; }
.important-badge {
  display: inline-block; margin-bottom: 4px; padding: 1px 8px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 800;
}
.message { margin: 0; font-size: 1.02em; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.deleted .message { color: var(--faint); text-decoration: line-through; }
.message-row.deleted .media-wrap, .message-row.deleted .ig-share-card { display: none; }
.edited-pill { color: var(--faint); font-size: .75em; font-weight: 500; }
.time { flex: none; color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }

.reply-preview {
  margin-bottom: 6px; padding: 7px 10px;
  border-left: 3px solid var(--line-strong); border-radius: 0 10px 10px 0;
  background: rgba(255, 255, 255, .03);
}
.reply-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.reply-content { display: flex; align-items: center; gap: 8px; min-width: 0; }
.reply-thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; flex: none; }
.reply-thumb-reel { height: 52px; }
.reply-text { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.media-wrap { margin-top: 8px; }
.image-preview {
  display: block; max-width: min(100%, 420px); max-height: 420px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: zoom-in; object-fit: contain;
}
video.image-preview, .video-preview { cursor: default; width: min(100%, 420px); }
.image-preview[data-media-type="sticker"], .image-preview[data-media-type="gif"], .image-preview[data-media-type="emoji"] {
  max-width: 160px; max-height: 160px; background: transparent; border: 0;
}
.media-error { color: var(--muted); font-size: 13px; }
.media-retry {
  margin-top: 6px; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 13px;
}

.ig-share-card, .embed-card {
  display: flex; align-items: stretch; gap: 12px;
  max-width: 460px; margin-top: 8px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none;
}
.ig-share-card { align-items: center; }
.ig-share-card:hover, .embed-card[href]:hover { border-color: var(--line-strong); }
.ig-share-icon { width: 34px; height: 34px; display: grid; place-items: center; flex: none; border-radius: 10px; background: var(--surface-3); color: var(--accent); }
.ig-share-copy { display: grid; min-width: 0; }
.ig-share-copy b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ig-share-copy small { color: var(--muted); font-size: 12px; }
.embed-card { border-left: 3px solid var(--accent); }
.embed-copy { flex: 1; min-width: 0; display: grid; gap: 2px; }
.embed-provider { color: var(--muted); font-size: 11px; font-weight: 700; }
.embed-title { color: var(--text); font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.embed-description { color: var(--text-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.embed-thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: none; }
.file-list { display: grid; gap: 6px; margin-top: 8px; max-width: 460px; }
.file-chip {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); text-decoration: none;
}
.file-chip b { min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip b::before { content: "📎 "; }
.file-chip small { color: var(--muted); font-size: 12px; flex: none; }
.audio-player { display: block; width: min(100%, 360px); height: 40px; margin-top: 8px; }
.poll-card { display: grid; gap: 6px; max-width: 420px; margin-top: 8px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.poll-card b { font-size: 14px; }
.poll-card span { padding: 6px 10px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); font-size: 13px; }
.forward-label { margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }

.reaction-strip { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; }
.reaction-emoji-img { width: 18px; height: 18px; object-fit: contain; }
.reaction-count { color: var(--text-2); font-size: 12px; font-weight: 700; }

.bottom-anchor { height: 1px; }
.jump-latest {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); z-index: 30;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.jump-latest span { min-width: 22px; padding: 1px 7px; border-radius: 99px; background: rgba(0, 0, 0, .15); font-size: 12px; }

.empty-state { display: grid; justify-items: center; gap: 6px; padding: 60px 20px; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 6px 0 0; color: var(--text-2); font-size: 18px; }
.empty-state p { margin: 0; max-width: 360px; font-size: 14px; }
.empty-icon { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); font-size: 28px; }

footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--line);
  color: var(--faint); font-size: 12px;
}
footer > div { display: flex; align-items: center; gap: 8px; }

/* ---------- overlays ---------- */
.flash-overlay { position: fixed; inset: 0; z-index: 90; pointer-events: none; opacity: 0; background: rgba(255, 255, 255, .12); }
.flash-overlay.important { background: rgba(232, 176, 75, .3); }
.flash-overlay.show { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
body.dimmed .app-shell { filter: brightness(.45); transition: filter .6s ease; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); z-index: 95;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 32px); padding: 10px 12px 10px 16px;
  background: #f2f3f5; color: #111318; border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .5);
  font-size: 14px; font-weight: 600;
}
.toast-action { min-height: 32px; padding: 0 12px; background: #111318; color: #fff; border: 0; font-weight: 800; }

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .92);
  padding: calc(16px + var(--safe-top)) 16px calc(76px + var(--safe-bottom));
  touch-action: pinch-zoom;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox-bar {
  position: absolute; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 6px; border-radius: 16px; background: rgba(30, 32, 38, .9); color: #fff;
}
.lightbox-bar span { min-width: 48px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.lightbox-btn { min-width: 42px; min-height: 40px; padding: 0 12px; display: grid; place-items: center; background: transparent; border-color: transparent; color: #fff; font-size: 15px; text-decoration: none; }
.lightbox-btn:hover { background: rgba(255, 255, 255, .1); }

.group-menu {
  position: fixed; z-index: 70; min-width: 230px; padding: 6px;
  display: flex; flex-direction: column;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.group-menu > button {
  border: 0; border-radius: 10px; background: transparent;
  padding: 11px 12px; text-align: left; font-size: 14px; color: var(--text);
}
.group-menu > button:hover { background: var(--surface-3); }
.menu-palette { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 4px 0; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); padding: 0; }
.swatch.active { border-color: var(--text); }

/* ---------- drawers ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.side-drawer {
  position: fixed; z-index: 50; top: 0; right: 0;
  width: min(440px, 100%); height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .4);
  animation: drawer-in .2s ease-out;
}
.wide-drawer { width: min(640px, 100%); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(16px + var(--safe-top)) 18px 14px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.drawer-scroll { flex: 1; overflow: auto; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
.drawer-foot { padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); }
.drawer-links { display: flex; gap: 8px; justify-content: space-between; margin: 4px 0 8px; }

.setting-group { margin-bottom: 12px; padding: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.setting-group h3 { margin: 0 0 10px; font-size: 14px; }
.setting-group label { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; color: var(--text-2); font-size: 13px; }
.setting-group input[type="number"], .setting-group input[type="text"], .setting-group input[type="time"], .setting-group select, .setting-group textarea,
.search-form input, .search-form select, .stats-range select {
  width: 100%; min-height: 40px; padding: 8px 11px;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 14px;
}
.setting-group textarea { min-height: 90px; resize: vertical; }
.setting-group input[type="range"] { width: 100%; accent-color: var(--accent); }
.switch-line { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 12px; }
.switch-line input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 44px; height: 26px; margin: 0; border-radius: 99px;
  background: var(--surface-3); border: 1px solid var(--line-strong); position: relative; cursor: pointer;
  transition: background .15s ease;
}
.switch-line input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #cfd3da; transition: transform .15s ease, background .15s ease;
}
.switch-line input[type="checkbox"]:checked { background: var(--accent); border-color: transparent; }
.switch-line input[type="checkbox"]:checked::after { transform: translateX(18px); background: #fff; }
.setting-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.setting-subhead { margin: 16px 0 4px; color: var(--text-2); font-size: 13px; }
.time-row, .button-pair, .search-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.time-row label { margin: 6px 0; }
.button-pair { margin-top: 8px; }
.topic-box { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.topic-box code { flex: 1; min-width: 0; padding: 9px 11px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted-list { display: grid; gap: 6px; }
.muted-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); font-size: 13px; }
.muted-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.debug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.debug-box { min-width: 0; padding: 9px 11px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.debug-box span { display: block; color: var(--faint); font-size: 11px; }
.debug-box b { display: block; margin-top: 2px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.collector-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.collector-summary div { padding: 9px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.collector-summary span { display: block; color: var(--faint); font-size: 11px; }
.collector-summary b { display: block; margin-top: 2px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collector-tab { display: grid; gap: 6px; margin-bottom: 10px; padding: 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.collector-tab b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collector-tab-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.collector-tab-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.state-chip { padding: 2px 8px; border-radius: 99px; font-size: 11px; font-style: normal; font-weight: 800; }
.state-chip.ok { background: var(--ok-soft); color: #8fe0b7; }
.state-chip.warn { background: var(--warn-soft); color: #f6d38b; }
.state-chip.error { background: var(--danger-soft); color: #ffb4b6; }
.collector-empty { color: var(--muted); font-size: 14px; }
.collector-extra { display: grid; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.collector-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--text-2); }

.search-form { display: grid; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.search-form .primary-btn { min-height: 40px; }
.search-results { gap: 10px; }
.search-results .group-menu-btn { display: none; }

.summary-output {
  min-height: 60px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  white-space: pre-wrap; line-height: 1.7; font-size: 15px; color: var(--text);
}
.summary-output:empty { display: none; }

.stats-range { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: var(--text-2); font-size: 13px; }
.stats-range select { width: auto; }
.stats-body { display: grid; gap: 12px; color: var(--muted); }
.stats-section { padding: 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.stats-section h3 { margin: 0 0 10px; color: var(--text); font-size: 14px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 38%) 1fr 44px; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.bar-row span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row i { display: block; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-row b { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.bar-row em { font-style: normal; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.hour-chart { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); align-items: end; gap: 3px; height: 120px; }
.hour-chart div { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.hour-chart b { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--accent); opacity: .85; }
.hour-chart span { height: 14px; color: var(--faint); font-size: 10px; }

/* ---------- phones ---------- */
@media (max-width: 720px) {
  body { font-size: 14px; }
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .topbar { margin: 0 -12px 10px; padding: 8px 12px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
  .brand-copy h1 { font-size: 16px; }
  .btn-label, .metric-chip { display: none; }
  .icon-btn { min-height: 38px; padding: 0; width: 38px; justify-content: center; }
  .btn-icon { font-size: 17px; }
  .header-actions { gap: 5px; flex-wrap: nowrap; }
  .live-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-buttons { overflow-x: auto; scrollbar-width: none; }
  .toolbar-buttons .soft-btn { flex: 1 0 auto; }
  .group-card { grid-template-columns: 34px minmax(0, 1fr); gap: 10px; padding: 12px; border-radius: 16px; }
  .avatar-wrap, .avatar-img, .avatar-fallback { width: 34px; height: 34px; }
  .image-preview { max-height: 320px; }
  .embed-thumb { width: 56px; height: 56px; }
  .debug-grid, .collector-summary { grid-template-columns: 1fr 1fr; }
  .bar-row { grid-template-columns: minmax(0, 42%) 1fr 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .group-card, .side-drawer { animation: none; }
  .flash-overlay.show { animation-duration: .01s; }
}
