:root {
  --sidebar-w: 250px;
  --topbar-h: 70px;
  --primary: #405189;
  --primary-2: #0ab39c;
  --accent: #7c5cfc;
  --bg: #f3f3f9;
  --card: #ffffff;
  --text: #495057;
  --heading: #212529;
  --muted: #878a99;
  --border: #e9ebec;
  --up: #0ab39c;
  --down: #f06548;
}
[data-theme="dark"] {
  --bg: #1a1d21;
  --card: #212529;
  --text: #ced4da;
  --heading: #ced4da;
  --muted: #adb5bd;
  --border: #32383e;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 20;
  transition: transform .25s;
}
[data-theme="dark"] .sidebar { background: #212529; }
[data-theme="dark"] .nav-link { color: #7c9dff; }
[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-item.open > .nav-link { color: #a9bdff; }
[data-theme="dark"] .nav-link.active-page {
  color: #34e0c4 !important; font-weight: 700;
  background: rgba(10,179,156,.15);
  box-shadow: inset 3px 0 0 #0ab39c;
}
[data-theme="dark"] .logo { color: #fff; }
/* Dark-mode: lift low-contrast navy links/text to a legible tint */
[data-theme="dark"] .data-table .link,
[data-theme="dark"] .pages-table a,
[data-theme="dark"] .link { color: #7c9dff; }
[data-theme="dark"] .data-table .link:hover,
[data-theme="dark"] .pages-table a:hover { color: #a9bdff; }
[data-theme="dark"] .breadcrumb span,
[data-theme="dark"] .data-table thead th,
[data-theme="dark"] .stat-head > span:first-child { color: #adb5bd; }
[data-theme="dark"] .data-table tbody td,
[data-theme="dark"] .card-head h5,
[data-theme="dark"] .modal-head h5,
[data-theme="dark"] h3, [data-theme="dark"] h4, [data-theme="dark"] h5 { color: #e4e6ea; }
[data-theme="dark"] .data-table tbody tr:hover { background: rgba(255,255,255,.03); }
/* Remaining links / accents in dark mode */
[data-theme="dark"] .banner-link,
[data-theme="dark"] .mini-table a,
[data-theme="dark"] .legend-table a,
[data-theme="dark"] a.link { color: #7c9dff; }
[data-theme="dark"] .banner-link:hover { color: #a9bdff; }
[data-theme="dark"] .show-all { color: #9aa1a9; }
[data-theme="dark"] .show-all:hover { color: #cfd3d8; }
[data-theme="dark"] .ref-list li b,
[data-theme="dark"] .metric-val,
[data-theme="dark"] .stat-card h3 { color: #e4e6ea; }
[data-theme="dark"] .ref-list li,
[data-theme="dark"] .mini-table td,
[data-theme="dark"] .pages-table td { color: #ced4da; }
[data-theme="dark"] .pg-btn { color: #ced4da; }
/* Banner keeps a light alert panel; darken its text so it stays readable */
[data-theme="dark"] .banner-body p { color: #ced4da; }
.sidebar-brand {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 24px; font-weight: 700; letter-spacing: 1px; color: var(--heading); }
.logo-accent { color: var(--primary-2); }
.sidebar-nav { padding: 16px 0; }
.nav-title { color: var(--muted); font-size: 11px; letter-spacing: 1px; padding: 8px 24px; }
.sidebar-nav ul { list-style: none; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; color: #545a6d; font-weight: 500;
  transition: color .2s;
}
.nav-link:hover, .nav-item.open > .nav-link { color: var(--primary); }
/* Active page highlight */
.nav-link.active-page {
  color: #0a8a78; font-weight: 700;
  background: rgba(10,179,156,.12); border-radius: 4px;
  box-shadow: inset 3px 0 0 var(--primary-2);
}
/* Highlight the active item's parent branch */
.nav-item.open > .nav-link:has(+ .sub-menu .active-page),
.sub-menu .nav-item.open > .nav-link:has(+ .sub-menu .active-page) { color: var(--primary); }
.nav-link i:first-child { width: 18px; text-align: center; font-size: 15px; }
.nav-link .arrow { margin-left: auto; font-size: 11px; transition: transform .2s; }
.nav-item.open > .nav-link .arrow { transform: rotate(90deg); }
.sub-menu { display: none; }
.nav-item.open > .sub-menu { display: block; }
.sub-menu .nav-link { padding-left: 40px; font-size: 13px; }
.sub-menu .sub-menu .nav-link { padding-left: 56px; }
.badge {
  margin-left: auto; background: #f7b84b; color: #fff;
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
}

/* Topbar */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-w); right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 15;
}
[data-theme="dark"] .topbar { background: #212529; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 16px; width: 38px; height: 38px;
  border-radius: 8px; position: relative;
}
.icon-btn:hover { background: var(--bg); }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 8px; padding: 8px 14px; width: 320px;
}
.search-box input { border: none; background: transparent; outline: none; width: 100%; color: var(--text); }
.badge-wrap .count {
  position: absolute; top: 2px; right: 2px;
  background: var(--primary-2); color: #fff; font-size: 10px;
  border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.profile { display: flex; align-items: center; gap: 10px; padding-left: 8px; cursor: pointer; }
.profile img { width: 34px; height: 34px; border-radius: 50%; }
.profile-info { display: flex; flex-direction: column; line-height: 1.2; }
.profile-info .name { font-weight: 600; color: var(--heading); font-size: 13px; }
.profile-info .role { color: var(--muted); font-size: 11px; }

/* Main */
.main-content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 24px) 24px 24px;
}
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h4 { color: var(--heading); font-size: 16px; text-transform: uppercase; }
.breadcrumb { color: var(--muted); font-size: 13px; }
.breadcrumb span { color: var(--text); }

/* Grid */
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.col-span-1 { grid-column: span 1; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.stack .grid { margin-bottom: 0; }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(56,65,74,.06);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h5 { color: var(--heading); font-size: 15px; }
.card-body { padding: 20px; }

/* Banner */
.banner { padding: 0; overflow: hidden; }
.banner-alert {
  background: #fef4e4; color: #d98c1f; padding: 12px 20px; font-size: 13px;
}
.banner-link { color: var(--primary); font-weight: 600; float: right; }
.banner-body { padding: 20px; }
.banner-body p { margin-bottom: 16px; color: var(--text); }
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 18px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.btn-soft {
  background: rgba(124,92,252,.1); color: var(--accent); border: none;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
}

/* Stat cards */
.stat-card { padding: 20px; }
.stat-card h3 { color: var(--heading); font-size: 22px; margin: 12px 0; }
.stat-head { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-head > span:first-child { color: var(--muted); text-transform: uppercase; font-size: 12px; font-weight: 600; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(10,179,156,.1); color: var(--primary-2);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.stat-foot { font-size: 12px; color: var(--muted); }
.stat-foot span { color: var(--muted); }
.stat-foot.up { color: var(--up); }
.stat-foot.down { color: var(--down); }

/* Pills */
.pill-group { display: flex; gap: 4px; background: var(--bg); border-radius: 6px; padding: 3px; }
.pill { border: none; background: transparent; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; color: var(--muted); }
.pill.active { background: var(--card); color: var(--heading); box-shadow: 0 1px 2px rgba(0,0,0,.1); }

/* Tables */
.mini-table, .pages-table, .legend-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .pages-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.mini-table td, .pages-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.pages-table a { color: var(--primary); }
.pages-table th:nth-child(2), .pages-table td:nth-child(2),
.pages-table th:nth-child(3), .pages-table td:nth-child(3) { text-align: right; }
.map-placeholder {
  height: 220px; display: flex; align-items: center; justify-content: center;
  color: var(--border); font-size: 120px; opacity: .5;
}

/* Metrics */
.metric-row { display: flex; justify-content: space-around; margin-bottom: 24px; }
.metric { text-align: center; }
.metric-val { display: block; font-size: 18px; font-weight: 600; color: var(--heading); }
.metric-val em { font-size: 12px; font-style: normal; }
.metric-label { color: var(--muted); font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Heatmap */
.heat-legend { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-a { background: #7c5cfc; } .sw-b { background: #5fd0d8; }
.heatmap { display: grid; grid-template-columns: 30px repeat(18, 1fr); gap: 4px; }
.heat-cell { aspect-ratio: 1; border-radius: 3px; }
.heat-label { display: flex; align-items: center; font-size: 11px; color: var(--muted); }

/* Device / referrals */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.dot-p { background: #7c5cfc; } .dot-o { background: #f7c04a; } .dot-c { background: #5fd0d8; }
.dot-g { background: #2fc39b; } .dot-y { background: #f17e5d; }
.legend-table { margin-top: 20px; }
.legend-table td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.ref-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 16px 0; }
.ref-list { list-style: none; }
.ref-list li { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ref-list li b { margin-left: auto; color: var(--heading); }
.show-all { display: block; text-align: center; margin-top: 12px; color: var(--muted); text-decoration: underline; }

/* Grid 4 */
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-4 { grid-template-columns: 1fr; } }

/* Stat icon colors */
.si-blue { background: rgba(64,120,255,.12); color: #4b7bff; }
.si-yellow { background: rgba(247,184,75,.15); color: #f7b84b; }
.si-green { background: rgba(10,179,156,.15); color: var(--primary-2); }
.stat-icon { color: #fff; }
.si-blue, .si-yellow, .si-green { color: #fff; }
.stat-head .si-blue { background: #4b7bff; }
.stat-head .si-yellow { background: #f7b84b; }
.stat-head .si-green { background: #0ab39c; }

/* Buttons */
.btn-danger {
  background: #f06548; color: #fff; border: none;
  padding: 9px 16px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.active-page { color: var(--primary) !important; font-weight: 600; }

/* Filter bar */
.filter-bar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box.grow { flex: 1; min-width: 240px; }
.input-fake, .input-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 14px; color: var(--text); min-width: 180px; cursor: pointer;
}
.input-fake { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.input-select { outline: none; }
.filter-bar .btn-primary { padding: 9px 16px; border-radius: 8px; }

/* Data table */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.data-table thead th {
  background: var(--bg); color: var(--muted); font-weight: 600; text-align: left;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.data-table thead th i { color: #c9cdd4; margin-left: 4px; font-size: 11px; }
.data-table tbody td { padding: 16px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tbody tr:hover { background: rgba(64,81,137,.03); }
.data-table .chk { width: 40px; }
.data-table .link { color: var(--primary); font-weight: 500; }
.data-table .link:hover { color: var(--accent); }

/* Avatars */
.avatar-stack { display: flex; align-items: center; }
.avatar-stack img {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--card);
  margin-left: -8px;
}
.avatar-stack img:first-child { margin-left: 0; }
.avatar-more {
  width: 30px; height: 30px; border-radius: 50%; margin-left: -8px;
  background: var(--primary); color: #fff; font-size: 11px;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--card);
}

/* Tags */
.tag { padding: 4px 9px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.st-new { background: rgba(10,179,156,.15); color: #0ab39c; }
.st-pending { background: rgba(247,184,75,.18); color: #d98c1f; }
.st-inprogress { background: rgba(75,123,255,.15); color: #4b7bff; }
.st-completed { background: rgba(10,179,156,.15); color: #0ab39c; }
.pr-high { background: #f06548; color: #fff; }
.pr-medium { background: #f7b84b; color: #fff; }
.pr-low { background: #0ab39c; color: #fff; }

/* Action buttons */
.action-menu { display: flex; gap: 6px; }
.act-btn {
  width: 30px; height: 30px; border-radius: 6px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  background: rgba(64,81,137,.1); color: var(--primary);
}
.act-btn:hover { background: var(--primary); color: #fff; }
.act-btn.del { background: rgba(240,101,72,.12); color: #f06548; }
.act-btn.del:hover { background: #f06548; color: #fff; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card); border-radius: 8px; width: 480px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal-sm { width: 380px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h5 { color: var(--heading); }
.modal-body { padding: 20px; }
.modal-body.center { text-align: center; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; font-weight: 600; color: var(--heading); margin-bottom: 6px; }
.form-row input, .form-row select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--card); color: var(--text); outline: none;
}
.form-row input:read-only, .form-row select:disabled { background: var(--bg); color: var(--muted); }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 20px; border-top: 1px solid var(--border);
}
.modal-foot.center { justify-content: center; }
.del-icon {
  width: 70px; height: 70px; margin: 0 auto 16px; border-radius: 50%;
  background: rgba(240,101,72,.12); color: #f06548; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
}
.modal-body.center h5 { color: var(--heading); margin-bottom: 8px; }

/* Pagination */
.pagination { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.pg-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Footer */
.footer { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding-top: 16px; }

canvas { max-height: 320px; }

/* Responsive */
.sidebar.collapsed { transform: translateX(-100%); }
.main-content.expanded { margin-left: 0; }
.topbar.expanded { left: 0; }
@media (max-width: 1200px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .topbar { left: 0; }
  .main-content { margin-left: 0; }
  .search-box { width: 160px; }
  .profile-info { display: none; }
}
