:root {
  --bg-0: #0b0f17;
  --bg-1: #111827;
  --bg-2: #1a2333;
  --bg-3: #243044;
  --border: #2a3952;
  --text: #e5ecf6;
  --muted: #93a4bd;
  --gold: #f5c451;
  --gold-dim: #b88c28;
  --blue: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #f0883e;
  --purple: #bc8cff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* MÀN ĐĂNG NHẬP */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #1b2842 0%, #090d14 70%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: 12px;
  padding: 30px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.login-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold);
  background: rgba(245, 196, 81, 0.12);
  border: 1px solid rgba(245, 196, 81, 0.3);
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  color: #fff;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

.login-foot {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* BỐ CỤC CHÍNH */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f5c451, #b87c14);
  color: #111;
  font-weight: 900;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--gold);
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.nav-list {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-2);
  color: #fff;
}

.nav-item.active {
  background: rgba(245, 196, 81, 0.12);
  border-color: rgba(245, 196, 81, 0.35);
  color: var(--gold);
  font-weight: 600;
}

.nav-ic {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.dot-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.sidebar-actions {
  display: flex;
  gap: 6px;
}

.sidebar-actions .btn {
  flex: 1;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

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

.topbar-left h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

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

.mobile-menu-btn {
  display: none;
}

.content {
  padding: 20px 22px 40px;
  max-width: 1680px;
  width: 100%;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* CARDS & LƯỚI */
.grid {
  display: grid;
  gap: 14px;
}

.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
}

.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 15px 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-val {
  font-size: 23px;
  font-weight: 800;
  color: #fff;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* FORM & NÚT BẤM */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg-0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar > input,
.toolbar > select {
  width: auto;
  min-width: 150px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-3);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 7px;
  font-size: 11.5px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(180deg, #f5c451, #d99f26);
  border-color: #f5c451;
  color: #111;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-success {
  background: rgba(63, 185, 80, 0.18);
  border-color: rgba(63, 185, 80, 0.5);
  color: #6ee77d;
}

.btn-danger {
  background: rgba(248, 81, 73, 0.16);
  border-color: rgba(248, 81, 73, 0.45);
  color: #ff7b72;
}

.btn-warn {
  background: rgba(240, 136, 62, 0.18);
  border-color: rgba(240, 136, 62, 0.5);
  color: #ffa657;
}

.btn-ghost {
  background: transparent;
}

/* NHÃN TRẠNG THÁI */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-ok { background: rgba(63, 185, 80, 0.15); color: #56d364; border-color: rgba(63, 185, 80, 0.35); }
.badge-danger { background: rgba(248, 81, 73, 0.15); color: #ff7b72; border-color: rgba(248, 81, 73, 0.35); }
.badge-warn { background: rgba(245, 196, 81, 0.15); color: #f5c451; border-color: rgba(245, 196, 81, 0.35); }
.badge-info { background: rgba(88, 166, 255, 0.15); color: #79c0ff; border-color: rgba(88, 166, 255, 0.35); }
.badge-purple { background: rgba(188, 140, 255, 0.15); color: #d2a8ff; border-color: rgba(188, 140, 255, 0.35); }
.badge-muted { background: rgba(147, 164, 189, 0.12); color: var(--muted); border-color: rgba(147, 164, 189, 0.25); }

/* THANH TIẾN TRÌNH DUNG LƯỢNG LOG <= 30GB */
.quota-bar-wrap {
  width: 100%;
  height: 16px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}

.quota-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3fb950, #58a6ff);
  transition: width 0.35s ease;
}

.quota-bar-fill.warn {
  background: linear-gradient(90deg, #f5c451, #f0883e);
}

.quota-bar-fill.danger {
  background: linear-gradient(90deg, #f0883e, #f85149);
}

/* BẢNG DỮ LIỆU */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th,
table.data-table td {
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid rgba(42, 57, 82, 0.65);
  vertical-align: middle;
}

table.data-table th {
  background: var(--bg-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}

table.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

table.data-table tr.row-danger td {
  background: rgba(248, 81, 73, 0.09);
}

/* LƯỚI VẬT PHẨM & TRANG BỊ NHÂN VẬT */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}

.item-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.item-cell:hover {
  border-color: var(--gold);
  background: var(--bg-2);
}

.item-cell.is-blue {
  border-left: 3px solid #66aaff;
}

.item-cell.is-gold {
  border-left: 3px solid #ffd54a;
}

.item-ic {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: #070a10;
  border: 1px solid #263449;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.item-ic img {
  max-width: 34px;
  max-height: 34px;
  image-rendering: pixelated;
}

.item-meta {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-cell.is-blue .item-name { color: #82b8ff; }
.item-cell.is-gold .item-name { color: #ffd54a; }

.item-sub {
  font-size: 11.5px;
  color: var(--muted);
}

.item-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* TOOLTIP TRANG BỊ CHUẨN VÕ LÂM */
.jx-tooltip {
  position: fixed;
  z-index: 9999;
  width: 310px;
  background: rgba(8, 11, 18, 0.96);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.5;
}

.jx-tip-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.jx-tip-blue { color: #79b8ff; }
.jx-tip-gold { color: #ffd54a; }
.jx-tip-green { color: #56d364; }
.jx-tip-dim { color: #6e7f99; }
.jx-tip-red { color: #ff7b72; }
.jx-tip-origin {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed #2b3a52;
  font-size: 11px;
  color: #f5c451;
  text-align: left;
}

/* SUB-TABS TRONG VẬN HÀNH */
.sub-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.sub-tab {
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-1);
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.sub-tab.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #111;
}

/* MODAL & TOAST */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 200;
}

.modal-box {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--gold);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.alert {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-danger {
  background: rgba(248, 81, 73, 0.14);
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: #ff8e86;
}

.toast-box {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  max-width: 380px;
}

.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: -270px;
    transition: left 0.2s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
