:root {
  --bg: #0f1419;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #93a0b4;
  --accent: #3d9cf0;
  --border: #2a3648;
  --ok: #3ecf8e;
  --chip: #243247;
}
* { box-sizing: border-box; }
html {
  /* Tránh layout nhảy khi thanh cuộn dọc hiện/ẩn giữa các trang */
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 1rem 1.25rem 2rem;
}
.top {
  display: grid;
  /* 3 cột ổn định: brand | menu | api — menu không xê dịch khi subtitle đổi */
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.brand {
  min-width: 0;
  max-width: 100%;
}
h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  /* Chiều cao 1 dòng cố định; text dài ellipsis — không đẩy menu */
  line-height: 1.35;
  min-height: 1.35em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Menu chính trên đầu trang */
.main-nav {
  display: flex;
  gap: 0.35rem;
  padding: 0.25rem;
  background: #101826;
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
  max-width: 100%;
  justify-self: center;
}
.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 1.15rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
  color: var(--text);
  background: rgba(61, 156, 240, 0.12);
}
.nav-item.active {
  background: var(--accent);
  color: #fff;
}
.settings-wrap {
  position: relative;
  justify-self: end;
  z-index: 60;
}
.btn-settings {
  font-weight: 600;
  white-space: nowrap;
  padding: 0.5rem 1rem;
}
.btn-settings[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}
.settings-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(360px, calc(100vw - 2rem));
  z-index: 70;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.settings-panel[hidden] { display: none !important; }
.settings-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.settings-panel .api-box {
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}
.settings-panel .api-box label { min-width: 0; width: 100%; }
.settings-panel .api-box input { width: 100%; }
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}
.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 0.35rem;
  max-width: min(18rem, 36vw);
  min-width: 0;
}
.user-badge-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 11rem;
  color: var(--text);
  font-weight: 500;
}
.user-badge .role-pill {
  flex-shrink: 0;
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item.nav-admin {
  border-color: rgba(61, 156, 240, 0.35);
}
.accounts-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.dept-section {
  margin-bottom: 1rem;
}
.dept-section h3 { margin: 0; }
.dept-intro { margin: 0.35rem 0 0.85rem; }
.dept-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(320px, 1.1fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 960px) {
  .dept-layout { grid-template-columns: 1fr; }
}
.dept-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}
.dept-form input[type="text"] {
  width: 100%;
  padding: 0.45rem 0.55rem;
}
.accounts-hero h2 { margin: 0 0 0.35rem; font-size: 1.15rem; }
.accounts-hero-text p { margin: 0; max-width: 48rem; line-height: 1.45; }
.accounts-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.2fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 960px) {
  .accounts-grid { grid-template-columns: 1fr; }
}
.accounts-form-card h3,
.accounts-list-card h3 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
}
.accounts-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 640px) {
  .accounts-form-grid { grid-template-columns: 1fr; }
}
.accounts-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
}
.accounts-form-grid input,
.accounts-form-grid select {
  width: 100%;
  padding: 0.45rem 0.55rem;
}
.accounts-enabled-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  align-self: end;
  padding-bottom: 0.35rem;
}
.accounts-menus-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem 1rem;
  margin-bottom: 1rem;
  background: rgba(0, 0, 0, 0.12);
}
.accounts-menus-block.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}
.accounts-menus-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.menu-perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.55rem;
}
.menu-perm-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.menu-perm-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(61, 156, 240, 0.35);
}
.menu-perm-card input {
  margin: 0 0 0.15rem;
  width: auto;
  align-self: flex-start;
}
.menu-perm-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.menu-perm-desc {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}
.accounts-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.accounts-table-wrap {
  max-height: min(70vh, 640px);
}
.role-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.role-pill.admin {
  color: #f0c674;
  border-color: rgba(240, 198, 116, 0.45);
  background: rgba(240, 198, 116, 0.08);
}
.role-pill.bod {
  color: #3d9cf0;
  border-color: rgba(61, 156, 240, 0.45);
  background: rgba(61, 156, 240, 0.1);
}
.role-pill.department {
  color: #3ecf8e;
  border-color: rgba(62, 207, 142, 0.4);
  background: rgba(62, 207, 142, 0.08);
}
.menu-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.menu-chip {
  font-size: 0.72rem;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--chip);
  color: var(--text);
}
.accounts-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.accounts-actions button {
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
}
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Nền đặc — không mờ / không lộ dashboard phía sau */
  background: var(--bg);
  padding: 1rem;
}
.login-overlay[hidden] { display: none !important; }
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}
.login-card h2 { margin: 0; font-size: 1.25rem; }
.login-hint { margin: 0; color: var(--muted); font-size: 0.9rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.login-card input { width: 100%; }
.login-error { color: #f07178; font-size: 0.85rem; margin: 0; }
.login-legacy { font-size: 0.8rem; margin: 0; }
.btn-user-del {
  color: #f07178;
}
.view[hidden] { display: none !important; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: rgba(61, 156, 240, 0.08); }
.selected-row { background: rgba(61, 156, 240, 0.18) !important; }
.muted-cell { color: var(--muted); text-align: center; padding: 1rem; }

.api-box, .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}
.filter-row + .filter-row { margin-top: 0.75rem; }
label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 140px;
}
.combo-label { min-width: 180px; position: relative; }
input, select, button {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101826;
  color: var(--text);
}
button { cursor: pointer; background: #243247; }
button.primary { background: var(--accent); border-color: transparent; color: #fff; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.filters { margin-bottom: 1rem; }
.quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding-bottom: 0.1rem;
}
.quick-label { font-size: 0.8rem; color: var(--muted); }
.chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--chip);
}
.chip:hover, .chip.active { background: var(--accent); border-color: transparent; }
.combo { position: relative; z-index: 5; }
.combo:focus-within { z-index: 40; }
.combo input { width: 100%; min-width: 160px; }
.combo-list {
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: #0d1520;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.combo-list li {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}
.combo-list li:hover, .combo-list li.active {
  background: rgba(61, 156, 240, 0.25);
}
.combo-list li.muted { color: var(--muted); cursor: default; }
.combo-list li.clear-opt { color: var(--accent); border-bottom: 1px solid var(--border); }
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.kpi .label { display: block; color: var(--muted); font-size: 0.8rem; }
.kpi strong { font-size: 1.15rem; }
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.month-stats-card { margin-bottom: 1rem; }
.month-stats-wrap { max-height: 360px; }
.chart-card h2, .table-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.table-wrap { overflow: auto; max-height: 480px; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); position: sticky; top: 0; background: var(--card); }
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--text); }
th.sortable::after {
  content: " \2195";
  font-size: 0.75em;
  opacity: 0.35;
}
th.sortable.sort-asc::after {
  content: " \2191";
  opacity: 0.9;
}
th.sortable.sort-desc::after {
  content: " \2193";
  opacity: 0.9;
}
tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: #141e2c;
  position: sticky;
  bottom: 0;
}
.status { color: var(--muted); min-height: 1.2rem; }
.status.err { color: #ff7b7b; }
.status.ok { color: var(--ok); }

/* Dashboard 2 — 3 bảng cạnh nhau */
.geo-tables {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: start;
}
.geo-col .table-head h2 { margin: 0; }
.geo-wrap { max-height: 560px; }
.aircraft-stats { margin-bottom: 1rem; }
.aircraft-stats-wrap { max-height: 280px; }
.pct-bar-cell {
  min-width: 7rem;
  vertical-align: middle;
}
.pct-bar-track {
  height: 8px;
  background: #101826;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.2rem;
}
.pct-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2a7fd4, var(--accent));
  border-radius: 999px;
  min-width: 0;
}
@media (max-width: 1100px) {
  .geo-tables { grid-template-columns: 1fr; }
  .top {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }
  .main-nav { justify-self: start; }
  .settings-wrap { justify-self: end; }
}
/* Nạp dữ liệu */
.inline-check {
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem !important;
  min-width: auto;
  cursor: pointer;
}
.inline-check input { width: auto; }
.inline-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  min-width: auto;
}
.inline-field select {
  min-width: 9rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101826;
  color: var(--text);
  font-size: 0.85rem;
}
.muted-inline { font-size: 0.8rem; color: var(--muted); }
.text-ok { color: var(--ok); }
.text-err { color: #ff7b7b; }
.kpi-small { font-size: 0.85rem !important; font-weight: 600; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: rgba(62, 207, 142, 0.2); color: var(--ok); }
.badge-failed { background: rgba(255, 123, 123, 0.2); color: #ff7b7b; }
.badge-skipped { background: rgba(147, 160, 180, 0.2); color: var(--muted); }
.badge-other { background: var(--chip); color: var(--text); }
.badge-running { background: rgba(61, 156, 240, 0.25); color: var(--accent); }
.badge-stopping { background: rgba(255, 180, 80, 0.25); color: #ffb450; }
.badge-stopped { background: rgba(147, 160, 180, 0.25); color: var(--muted); }
.btn-danger {
  border: 1px solid #ff7b7b;
  background: rgba(255, 123, 123, 0.15);
  color: #ff9b9b;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
}
.btn-danger:hover { background: rgba(255, 123, 123, 0.28); color: #ffc0c0; }
.btn-danger:disabled,
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
#iBtnTrigger.btn-running {
  border-color: var(--accent);
  background: rgba(61, 156, 240, 0.15);
  color: var(--accent);
  font-weight: 600;
}

.progress-card { margin-bottom: 1rem; }
.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.progress-head h2 { margin: 0; font-size: 1.05rem; }
.progress-bar-track {
  height: 10px;
  background: #101826;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.6rem 0;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2a7fd4, var(--accent));
  border-radius: 999px;
  transition: width 0.35s ease;
  min-width: 0;
}
.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.progress-stats strong { color: var(--text); }

.ingest-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.ingest-tab {
  border: 1px solid var(--border);
  background: #101826;
  color: var(--muted);
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
.ingest-tab:hover { color: var(--text); border-color: var(--accent); }
.ingest-tab.active {
  background: rgba(61, 156, 240, 0.18);
  color: var(--accent);
  border-color: var(--accent);
}
.ingest-tab-kpis { margin: 0; }
.btn-link-action {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  padding: 0.15rem 0.35rem;
  text-decoration: underline;
}
.btn-link-action:hover { color: #7ec0ff; }
.btn-drive {
  color: var(--ok);
  margin-left: 0.35rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 1rem 1.15rem 1.15rem;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}
.modal-close:hover { color: var(--text); }
.error-meta {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
}
.error-meta dt { color: var(--muted); margin: 0; }
.error-meta dd { margin: 0; word-break: break-word; }
.error-full {
  margin: 0 0 1rem;
  padding: 0.75rem;
  background: #101826;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  max-height: 280px;
  overflow: auto;
  color: #ffb4b4;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
}
.btn-link {
  color: var(--accent);
  font-weight: 600;
}
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; }

/* Menu Xuất Excel (màn Địa giới) */
.export-menu {
  position: relative;
  display: inline-block;
  align-self: flex-end;
}
.export-menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 280px;
  max-width: min(420px, 92vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.4rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.export-menu-panel[hidden] {
  display: none !important;
}
.export-menu-item {
  text-align: left;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.35;
  white-space: normal;
}
.export-menu-item:hover,
.export-menu-item:focus-visible {
  background: rgba(61, 156, 240, 0.16);
  color: #fff;
  outline: none;
}

@media (max-width: 700px) {
  .error-meta { grid-template-columns: 1fr; }
}
