:root {
  --bg: #f4f6f9; --surface: #fff; --ink: #0f172a; --ink-2: #334155; --muted: #64748b;
  --border: #e2e8f0; --border-2: #cbd5e1;
  --accent: #0e7c66; --accent-600: #0b6653; --accent-soft: #e3f4ef;
  --info: #2563eb; --info-soft: #e8f0fe; --violet: #6d4ae0; --violet-soft: #efeafd;
  --danger: #d1382b; --danger-soft: #fdeceb; --warn: #b7791f; --warn-soft: #fdf3e0;
  --radius: 16px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 2px 8px rgba(15,23,42,.05);
  --shadow-lg: 0 16px 40px rgba(15,23,42,.18);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top bar ---------- */
.topbar { background: rgba(255,255,255,.86); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #12a085, var(--accent-600)); color: #fff; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(14,124,102,.35); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.nav { display: flex; gap: 4px; }
.nav-btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 550; font-size: 14px; transition: background .15s, color .15s; }
.nav-btn:hover { background: var(--bg); color: var(--ink); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Page ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.025em; }
.page-head p { color: var(--muted); margin-top: 2px; max-width: 62ch; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card-head h2 { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.hi { width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.hi .ic { width: 16px; height: 16px; }
.hi.violet { background: var(--violet-soft); color: var(--violet); }
.hi.info { background: var(--info-soft); color: var(--info); }
.hi.warn { background: var(--warn-soft); color: var(--warn); }
.hi.bad { background: var(--danger-soft); color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 16px; }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.pill.live .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; }
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(14,124,102,.3); }
.btn-primary:hover { background: var(--accent-600); }
.btn-primary:disabled:hover { background: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #f3c7c3; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #b52e22; }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; padding: 12px 18px; }
.icon-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: #fff; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: .4; cursor: default; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; background: var(--surface); box-shadow: var(--shadow); }
.stat .hi { width: 38px; height: 38px; border-radius: 11px; }
.stat .hi .ic { width: 19px; height: 19px; }
.stat .l { color: var(--muted); font-size: 13px; line-height: 1.2; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat.plain { display: block; box-shadow: none; }

.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: #fbfcfd; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }
.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.bar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #12a085, var(--accent)); border-radius: 999px; transition: width .5s ease; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.avatar .ic { width: 26px; height: 26px; stroke-width: 2.2; }
.avatar.warn { background: var(--warn-soft); color: var(--warn); }
.banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; margin-bottom: 16px; border-radius: 12px; background: var(--warn-soft); color: #7a5314; border: 1px solid #f3e2bd; }
.banner a { color: inherit; font-weight: 700; }
.skeleton { background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 37%, #eef1f5 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 10px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Dialog + toasts */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog::backdrop { background: rgba(15,23,42,.45); backdrop-filter: blur(2px); }
dialog form { padding: 24px; }
dialog h3 { font-size: 18px; letter-spacing: -0.01em; }
dialog p { color: var(--muted); margin-top: 6px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.opts { margin-top: 16px; display: grid; gap: 8px; }
.opt-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.opt-row:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt-row input { margin-top: 4px; accent-color: var(--accent); }
.opt-row strong { display: block; font-size: 14.5px; }
.opt-row small { color: var(--muted); font-size: 13px; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; }
.toast { padding: 11px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); animation: tin .25s ease; }
.toast.bad { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .3s; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive: bottom tab bar on phones ---------- */
@media (max-width: 720px) {
  .topbar-inner { padding: 10px 16px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--border); padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .nav-btn { flex-direction: column; gap: 3px; font-size: 11.5px; padding: 6px 2px; border-radius: 10px; text-align: center; }
  .nav-btn .ic { width: 21px; height: 21px; }
  .page { padding: 20px 16px calc(92px + env(safe-area-inset-bottom, 0px)); }
  .page-head h1 { font-size: 22px; }
  .card { padding: 18px; }
  #toasts { left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-row h2 { font-size: 21px; letter-spacing: -0.02em; }
.metas { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.msgbox { display: flex; gap: 18px; margin-top: 20px; align-items: flex-start; flex-wrap: wrap; }
.msgcol { flex: 1; min-width: 240px; }
.lbl { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.msg { white-space: pre-wrap; white-space: pre-wrap; padding: 12px 14px; background: var(--bg); border-radius: 12px; font-size: 14px; max-height: 200px; overflow: auto; }
#d-img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.small-empty { padding: 28px 16px; }
.replies { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; max-height: 520px; overflow: auto; }
.replies li { display: flex; gap: 12px; }
.av { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--violet-soft); color: var(--violet); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.rb { min-width: 0; flex: 1; }
.rt { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.rt .when { margin-left: auto; }
.reply { margin-top: 6px; background: var(--bg); border-radius: 4px 12px 12px 12px; padding: 9px 12px; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.orig { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; color: var(--muted); font-size: 13px; }
.orig .ic { width: 14px; height: 14px; margin-top: 2px; }
.results td { vertical-align: top; }
.cel.msg { white-space: pre-wrap; max-width: 280px; min-width: 150px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; word-break: break-word; cursor: pointer; font-size: 14px; }
.clamp.open { display: block; }
.reply-text { color: var(--violet); }
.nowrap { white-space: nowrap; }
@media (max-width: 720px) { #d-img { width: 90px; height: 90px; } }

.chip { display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--ink-2); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tag { font-size: 11.5px; padding: 1px 8px; margin-left: 6px; vertical-align: 1px; }
