/* ===================================================== */
/* 1. ROOT VARIABLES                                    */
/* ===================================================== */

:root {
  --bg0: #070a12;
  --bg1: #0b1220;
  --bg2: #0e1830;

  --panel: rgba(255, 255, 255, .06);
  --panel2: rgba(255, 255, 255, .085);
  --stroke: rgba(255, 255, 255, .10);
  --stroke2: rgba(255, 255, 255, .14);

  --text: rgba(255, 255, 255, .92);
  --muted: rgba(255, 255, 255, .62);
  --muted2: rgba(255, 255, 255, .48);

  --primary: #6d8bff;
  --primary2: #7c5cff;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;

  --shadow2: 0 10px 26px rgba(0, 0, 0, .28);
  --shadow3: 0 8px 18px rgba(0, 0, 0, .22);

  --r20: 20px;
  --r18: 18px;
  --r16: 16px;
  --r14: 14px;

  --sidebarW: 272px;
  --pagePad: 18px;
  --cardPad: 14px;
  --gap: 14px;

  --ctrlH: 42px;
  --kpiW: 180px;

  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

/* ===================================================== */
/* 2. RESET & BASE                                      */
/* ===================================================== */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 12% 10%, rgba(109, 139, 255, .22), transparent 60%),
    radial-gradient(920px 560px at 85% 16%, rgba(124, 92, 255, .20), transparent 62%),
    radial-gradient(900px 520px at 45% 88%, rgba(34, 197, 94, .12), transparent 58%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

canvas {
  width: 100% !important;
  display: block;
}

/* Scrollbar */
*::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .14);
  border-radius: 999px;
}

*::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, .04);
}

/* ===================================================== */
/* 3. LAYOUT                                            */
/* ===================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebarW) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 16px 14px;
  border-right: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .03));
  backdrop-filter: blur(16px);
}

.main {
  padding: var(--pagePad);
  padding-bottom: 26px;
}

/* ===================================================== */
/* 4. SIDEBAR COMPONENTS                                 */
/* ===================================================== */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 14px;
}

.brand .logo {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
}

.brand .title b {
  font-size: 13px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--muted);
  transition: .15s;
}

.nav a.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(109, 139, 255, .22), rgba(124, 92, 255, .18));
}

/* ===================================================== */
/* 5. TOPBAR                                            */
/* ===================================================== */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-radius: var(--r20);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .05);
  backdrop-filter: blur(16px);
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  font-size: 12px;
}

/* ===================================================== */
/* 6. CARD / TOOLBAR                                    */
/* ===================================================== */

.card {
  border-radius: var(--r20);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .06);
  padding: var(--cardPad);
}

.card-title {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 12px;
  color: var(--muted);
}

select,
input[type="date"] {
  height: var(--ctrlH);
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--stroke2);
  background: rgba(8, 12, 20, .55);
  color: var(--text);
}

.btn {
  height: var(--ctrlH);
  padding: 0 14px;
  border-radius: 14px;
  border: none;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

/* ===================================================== */
/* 7. KPI                                               */
/* ===================================================== */

.kpis {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.kpi {
  width: var(--kpiW);
  padding: 10px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
}

.kpi-value {
  font-size: 18px;
  font-weight: 800;
}

/* ===================================================== */
/* 8. GRID / CHART / TABLE                               */
/* ===================================================== */

.grid {
  display: grid;
  grid-template-columns: 1.25fr .75fr;
  gap: var(--gap);
  margin-top: var(--gap);
}

.chart-wrap {
  height: 340px;
}

.table-wrap {
  overflow: auto;
  max-height: 460px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: rgba(14, 24, 48, .95);
  padding: 10px;
}

tbody td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}

td.num,
th.num {
  text-align: right;
}

/* ===================================================== */
/* 9. RESPONSIVE                                        */
/* ===================================================== */

@media (max-width:1024px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: .3s;
    z-index: 1000;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

/* ===================================================== */
/* MOBILE LAYOUT FIX – FULL WIDTH, NO CENTER COLUMN      */
/* ===================================================== */

@media (max-width: 768px) {

  /* 1️⃣ CHỐT CHẶN – KHÔNG CHO TRÀN NGANG */
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* 2️⃣ PHÁ GRID DESKTOP – VỀ FLOW MOBILE */
  .shell {
    display: block !important;
    width: 100%;
    max-width: 100%;
  }

  /* 3️⃣ SIDEBAR OFF-CANVAS ĐÚNG NGHĨA */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebarW);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 1000;
    border-right: 1px solid var(--stroke);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* 4️⃣ MAIN FULL WIDTH – KHÔNG BỊ BÓ */
  .main {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding-left: 14px;
    padding-right: 14px;
  }

  /* 5️⃣ TOPBAR GIỐNG APP MOBILE */
  .topbar {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .topbar .left {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 17px;
    line-height: 1.25;
  }

  .menu-btn {
    display: inline-flex;
    font-size: 22px;
    line-height: 1;
  }

  /* 6️⃣ CARD KHÔNG BỊ HẸP GIỮA */
  .card {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  /* 7️⃣ TOOLBAR XẾP DỌC GỌN */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .field,
  select,
  input[type="date"],
  .btn {
    width: 100%;
    max-width: 100%;
  }

  /* 8️⃣ KPI – MỖI KPI 1 HÀNG */
  .kpis {
    width: 100%;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  

  .kpi {
    width: 100%;
  }

  .kpi-value {
    font-size: 17px;
  }

  /* 9️⃣ GRID → 1 CỘT */
  .grid {
    display: block;
    width: 100%;
    max-width: 100%;
  }

  /* 🔟 CHART FULL WIDTH – CAO HỢP LÝ */
  .chart-wrap {
    width: 100%;
    max-width: 100%;
    height: 240px !important;
  }

  /* 1️⃣1️⃣ TABLE MOBILE – VUỐT NGANG CHUẨN */
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 980px;
  }

  thead th,
  tbody td {
    padding: 8px 8px;
    font-size: 12px;
  }

  /* 1️⃣2️⃣ GIẢM GPU LOAD (MƯỢT HƠN) */
  .card,
  thead th {
    backdrop-filter: none;
  }
}

@media (max-width:560px) {
  :root {
    --pagePad: 14px;
    --cardPad: 12px;
  }
}

/* ===================================================== */
/* SKELETON LOADING                                      */
/* ===================================================== */

.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, .08);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, .18),
      transparent);
  animation: skeleton 1.2s infinite;
}

@keyframes skeleton {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

.hidden {
  display: none !important;
}