:root {
  --primary: #0b3d2e;
  --primary-light: #145a44;
  --accent: #10b981;
  --accent-soft: #d1fae5;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0284c7;
  --info-soft: #e0f2fe;
  --bg: #f3f6f5;
  --surface: #ffffff;
  --border: #dfe7e4;
  --text: #0f172a;
  --muted: #52635d;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(11, 61, 46, 0.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary-light); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.flex-center { display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--muted); font-size: 13px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-700 { font-weight: 700; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #059669; }
.btn-amber { background: var(--amber); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border-color: var(--border); }
.btn-outline:hover { background: #f0f7f4; border-color: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green { background: var(--accent-soft); color: #065f46; }
.badge-red { background: var(--danger-soft); color: #991b1b; }
.badge-amber { background: var(--amber-soft); color: #92400e; }
.badge-blue { background: var(--info-soft); color: #075985; }
.badge-gray { background: #e5e7eb; color: #374151; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 12px 0;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* KPI Tiles */
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3.5px;
  background: var(--accent);
}
.kpi-card.warn::before { background: var(--amber); }
.kpi-card.danger::before { background: var(--danger); }
.kpi-card.info::before { background: var(--info); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 24px; font-weight: 800; color: var(--primary); margin: 4px 0 2px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
}
.form-control {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

/* Tables */
.table-wrap { overflow-x: auto; border-radius: 9px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
thead th {
  background: #f0f6f4;
  color: var(--primary);
  font-weight: 700;
  text-align: left;
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 9px 11px;
  border-bottom: 1px solid #eef2f0;
  vertical-align: middle;
}
tbody tr:hover { background: #f8fbfa; }
tfoot td {
  padding: 10px 11px;
  background: #f0f6f4;
  font-weight: 700;
}

/* Alerts */
.alert {
  padding: 12px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  border-left: 4px solid var(--accent);
  background: #ecfdf5;
  color: #064e3b;
}
.alert-warn { border-left-color: var(--amber); background: #fffbeb; color: #78350f; }
.alert-danger { border-left-color: var(--danger); background: #fef2f2; color: #7f1d1d; }
.alert-info { border-left-color: var(--info); background: #f0f9ff; color: #0c4a6e; }

/* ================= PUBLIC PORTAL ================= */
.pub-nav {
  background: var(--primary);
  color: #fff;
  padding: 13px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #10b981, #34d399);
  color: #063024;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 18px;
}

.pub-hero {
  background: linear-gradient(135deg, #07291f 0%, #0b3d2e 55%, #115e45 100%);
  color: #fff;
  padding: 46px 24px 56px;
}
.pub-container { max-width: 1200px; margin: 0 auto; padding: 0 18px; }
.pub-hero h1 {
  font-size: 32px;
  line-height: 1.25;
  margin: 10px 0 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.pub-hero p { color: #d1fae5; font-size: 15.5px; max-width: 680px; margin: 0 0 22px; }
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 24px;
}
.hero-stat {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 13px 15px;
}
.hero-stat strong { display: block; font-size: 20px; color: #6ee7b7; }
.hero-stat span { font-size: 12.5px; color: #e2f5ee; }

.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8faf9;
  cursor: pointer;
  font-size: 12.5px;
  user-select: none;
}
.chip-check input { accent-color: var(--accent); }
.chip-check.checked { background: var(--accent-soft); border-color: var(--accent); color: #065f46; font-weight: 600; }

/* ================= WORKSPACE LAYOUT ================= */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 262px;
  background: var(--primary);
  color: #e2f3ec;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar-nav { padding: 10px; flex: 1; }
.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #86b9a7;
  padding: 10px 10px 4px;
  font-weight: 700;
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 3px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: #d6ede4;
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  transition: background 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.1); }
.nav-item.active { background: var(--accent); color: #04291e; font-weight: 700; }
.nav-badge {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 11px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 25;
}
.content-wrap { padding: 20px 24px 48px; max-width: 1380px; width: 100%; margin: 0 auto; }

/* Sub-tabs */
.sub-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.sub-tab {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.sub-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Charts container */
.chart-box { width: 100%; min-height: 250px; position: relative; }
.chart-box svg { width: 100%; height: auto; display: block; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

/* Toast */
#toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--primary);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  font-weight: 600;
  font-size: 13.5px;
  max-width: 380px;
}
.toast.error { background: var(--danger); }

/* iOS Bottom Tab Bar (hiển thị trên iPhone / iPad / Mobile) */
.ios-bottom-bar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 50;
  justify-content: space-around;
}
.ios-tab {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.ios-tab span { font-size: 18px; line-height: 1; }
.ios-tab small { font-size: 10.5px; }
.ios-tab.active { color: var(--primary); background: var(--accent-soft); }
.ios-install-banner {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(68px + env(safe-area-inset-bottom));
  background: linear-gradient(135deg, #0b3d2e, #059669);
  color: #fff;
  padding: 11px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 120;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

/* Responsive */
@media (max-width: 980px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .sidebar { position: fixed; left: -270px; z-index: 60; transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .ios-bottom-bar { display: flex; }
  .content-wrap { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  .pub-nav { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .pub-hero h1 { font-size: 24px; }
  .hero-stats { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .no-print, .pub-nav { display: none !important; }
  .content-wrap { padding: 0 !important; max-width: 100% !important; }
  .card { box-shadow: none !important; break-inside: avoid; }
}
