:root {
  --sidebar-w: 248px;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e6e9f0;
  --text: #1c2333;
  --muted: #6b7486;
  --primary: #2a7de1;
  --primary-soft: #e8f1fc;
  --sidebar-bg: #141a2a;
  --sidebar-text: #aab3c5;
  --sidebar-active: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  transition: transform .2s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 14px;
  color: #fff; font-weight: 600; font-size: 15px;
}
.brand-icon { font-size: 22px; color: #3fa1ff; }
.nav-section { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: #6c768b; padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500;
}
.nav-item i { font-size: 16px; width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer {
  display: flex; align-items: center; gap: 6px;
  padding: 12px; border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip { display: flex; align-items: center; gap: 10px; flex: 1; padding: 6px 8px; border-radius: 8px; color: var(--sidebar-text); min-width: 0; }
.user-chip:hover, .user-chip.active { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: #2a7de1; color: #fff; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #8b95a9; }
.btn-icon {
  background: transparent; border: 0; color: inherit;
  width: 36px; height: 36px; border-radius: 8px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(0,0,0,.06); }
.sidebar .btn-icon:hover { background: rgba(255,255,255,.08); color: #fff; }

/* Main */
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1020;
}
.page-title { font-size: 18px; font-weight: 600; margin: 0; }
.channel-select { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.channel-select .form-select { min-width: 180px; }
.content { padding: 24px 28px 40px; flex: 1; }

/* Cards */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; padding: 14px 18px; }
.card-body { padding: 18px; }

.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); height: 100%;
}
.stat-link { display: block; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
.stat-link:hover { color: inherit; text-decoration: none; border-color: #b9d3f5; box-shadow: 0 4px 14px rgba(42,125,225,.12); transform: translateY(-1px); }
.stat-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat-link::after { content: "\F138"; font-family: "bootstrap-icons"; position: absolute; right: 14px; bottom: 12px; color: #c3c9d6; font-size: 14px; }
.stat-link:hover::after { color: var(--primary); }
.stat { position: relative; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-sub .up { color: #17934a; }
.stat-sub .down { color: #d23f3f; }
.stat-icon {
  float: right; width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; font-size: 17px;
}
.stat-icon.green { background: #e6f6ec; color: #17934a; }
.stat-icon.red { background: #fdeaea; color: #d23f3f; }
.stat-icon.amber { background: #fff4e0; color: #c47b00; }
.stat-icon.gray { background: #eef0f4; color: #596377; }

/* Tables */
.table { margin-bottom: 0; }
.table thead th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border);
  background: #fafbfd; white-space: nowrap;
}
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f7f9fc; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.text-muted-sm { color: var(--muted); font-size: 12px; }
.badge { font-weight: 600; }
.badge.text-bg-light { color: #596377 !important; }

/* Empty / loading */
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty-state i { font-size: 40px; display: block; margin-bottom: 10px; color: #c3c9d6; }
.empty-state h5 { color: var(--text); font-size: 15px; }
.skeleton { background: linear-gradient(90deg,#eef0f4 25%,#f7f8fa 50%,#eef0f4 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; min-height: 14px; }
@keyframes sk { 0% {background-position: 200% 0} 100% {background-position: -200% 0} }

/* Filter bar */
.filter-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
.filter-bar .form-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Pager */
.pagination { margin: 0; }
.pagination .page-link { border-color: var(--border); color: var(--text); }
.pagination .active .page-link { background: var(--primary); border-color: var(--primary); }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--primary);
}
.timeline li.red::before { border-color: #d23f3f; }
.timeline li.green::before { border-color: #17934a; }
.timeline li.gray::before { border-color: #9aa3b5; }
.timeline .t-time { font-size: 12px; color: var(--muted); }

/* Template chips */
.template-card { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; background: #fafbfd; }
.template-card .t-title { font-weight: 600; font-size: 13px; }
.template-card .t-body { color: var(--muted); font-size: 13px; white-space: pre-wrap; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 10% -10%, #dbe8fb, transparent), var(--bg); padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: 0 10px 40px rgba(16,24,40,.08); }
.login-card .brand { padding: 0 0 18px; color: var(--text); }
.login-card .brand-icon { color: var(--primary); }

.copy-ok { color: #17934a; }
.code-box { background: #f6f8fb; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
pre.report-preview { background: #f6f8fb; border: 1px solid var(--border); border-radius: 8px; padding: 14px; white-space: pre-wrap; font-size: 13px; }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .main { margin-left: 0; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .channel-select .form-select { min-width: 130px; }
  .stat-value { font-size: 22px; }
}
@media (max-width: 575.98px) {
  .page-title { font-size: 16px; }
  .table-responsive { border-radius: var(--radius); }
}
