*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: "Inter", "Roboto", Arial, sans-serif; font-size: 13px; line-height: 1.45;
  color: var(--text-body); background: var(--app-bg); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.muted { color: var(--text-secondary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Khung ứng dụng ---------- */
.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  width: 100%; max-width: 1400px; min-height: calc(100vh - 40px); margin: 20px auto;
  background: var(--surface); border-radius: 16px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(23, 33, 43, .10); transition: grid-template-columns var(--ease);
}
.app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px; min-width: 0; z-index: 40;
}
.sidebar-top { display: flex; align-items: center; gap: 8px; height: 30px; margin-bottom: 18px; padding: 0 2px; }
.logo-mark {
  flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--teal));
}
.logo-mark.big { width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 10px; }
.brand-name { font-weight: 700; font-size: 14px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-collapse { margin-left: auto; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-body); font-size: 13px; font-weight: 500; transition: background var(--ease), color var(--ease);
}
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--text-secondary); }
.nav-item:hover { background: var(--divider); text-decoration: none; }
.nav-item.active { background: var(--border); color: var(--text-primary); font-weight: 600; }
.nav-item.active svg { color: var(--primary); }
.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 8px 4px 0; min-width: 0; }
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-user-text b { font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-text small { font-size: 10.5px; color: var(--text-secondary); }
.app.collapsed .brand-name, .app.collapsed .nav-item span, .app.collapsed .sidebar-user-text { display: none; }
.app.collapsed .sidebar-top { flex-direction: column; height: auto; gap: 10px; }
.app.collapsed .sidebar-collapse { margin-left: 0; transform: rotate(180deg); }
.app.collapsed .nav-item { justify-content: center; padding: 9px 0; }

.main { display: flex; flex-direction: column; min-width: 0; background: var(--content-bg); }
.topbar {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex: none;
}
.page-title { font-size: 17px; font-weight: 700; color: var(--text-primary); margin-right: auto; white-space: nowrap; }
.menu-toggle { display: none; }
.scrim { display: none; }
.search {
  position: relative; display: flex; align-items: center; width: 220px; max-width: 40vw; height: 32px;
  background: var(--divider); border-radius: 8px; padding: 0 10px; gap: 6px; transition: box-shadow var(--ease);
}
.search:focus-within { box-shadow: 0 0 0 2px var(--primary-soft), 0 0 0 3px var(--primary); }
.search svg { width: 14px; height: 14px; color: var(--text-secondary); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: 0; font-size: 12px; }
.content { padding: 14px 16px 18px; flex: 1; min-width: 0; }

/* ---------- Lưới 12 cột ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-12 { grid-column: span 12; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }

/* ---------- Đăng nhập / cài đặt ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px 26px; text-align: center; }
.login-card h1 { font-size: 20px; color: var(--text-primary); margin-bottom: 4px; }
.login-card .form-stack { text-align: left; margin-top: 14px; }
.login-card .muted { margin-bottom: 8px; }
