/* =========================
   IOT DASH / CHATBOX - CLEAN CSS (NO DUPLICATES)
   ========================= */

:root {
  --bg: #0b1220;
  --card: rgba(255, 255, 255, .06);
  --card2: rgba(255, 255, 255, .08);
  --stroke: rgba(255, 255, 255, .12);
  --text: rgba(255, 255, 255, .92);
  --muted: rgba(255, 255, 255, .70);
  --ok: #29d67d;
  --bad: #ff4d4d;
  --warn: #f7b84b;

  /* chiều cao header để chat-wrap tính */
  --headerH: 56px;                 /* ← từ 72px → 56px */

  /* khoảng trống dành cho 2 thanh mobile (dock + bar) */
  --mobileDockH: 160px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Quicksand", system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(77, 124, 255, .18), transparent 55%),
    radial-gradient(1000px 700px at 90% 20%, rgba(41, 214, 125, .14), transparent 55%),
    var(--bg);
  color: var(--text);
}

/* ===== Generic controls ===== */
.input {
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  outline: none;
}

.input::placeholder {
  color: rgba(255, 255, 255, .45);
}

.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .10);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  background: rgba(255, 255, 255, .14);
}

.btn.ghost {
  background: transparent;
}

button,
.btn {
  touch-action: manipulation;
}

/* =========================
   TOPBAR / HEADER
   ========================= */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;              /* ← từ 14px → 8px */
  border-bottom: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  background: rgba(11, 18, 32, .55);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.left-cluster {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4d7cff, #29d67d);
  box-shadow: 0 0 18px rgba(77, 124, 255, .45);
}

.logo-wide {
  height: 34px;                    /* ← từ 42px → 34px */
  max-width: 140px;
  object-fit: contain;
  display: block;
}
.brand-text {
  min-width: 0;
}

.brand-text .title {
  font-size: 15px;                 /* ← từ 18px → 15px */
  font-weight: 800;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text .subtitle {
  font-size: 11px;                 /* ← từ 12px → 11px */
  color: var(--muted);
  margin-top: 1px;                 /* ← từ 2px → 1px */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* =========================
   HEADER NAV (DESKTOP) - ICON + LABEL
   ========================= */
/* =========================
   HEADER NAV (DESKTOP) - ICON BUBBLE + LABEL
   ========================= */
.topbar {
  background: linear-gradient(180deg, #0f1a33 0%, #0a1428 100%);
  border-bottom: 1px solid rgba(77, 160, 255, .18);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .4);
}

.brand-text .title {
  text-shadow: 0 0 14px rgba(77, 160, 255, .35);
}

.logo-wide {
  filter: drop-shadow(0 0 8px rgba(77, 160, 255, .3));
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;                        /* ← từ 4px → 2px */

  min-width: 64px;                 /* ← từ 74px → 64px */
  padding: 5px 8px 4px;            /* ← từ 8px 10px 7px */
  border-radius: 12px;

  text-decoration: none;
  color: rgba(180, 200, 230, .75);

  background: rgba(20, 32, 58, .55);
  border: 1px solid rgba(77, 160, 255, .12);

  font-size: 10px;                 /* ← từ 11px → 10px */
  font-weight: 700;
  letter-spacing: .2px;
  transition: all .2s ease;
}

.nav-icon {
  width: 28px;                     /* ← từ 34px → 28px */
  height: 28px;                    /* ← từ 34px → 28px */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(77, 160, 255, .08);
  color: #6aa4ff;
  transition: all .2s ease;
  font-size: 0;
}

.nav-icon svg {
  width: 17px;                     /* ← từ 20px → 17px */
  height: 17px;
  display: block;
}

.nav-label {
  line-height: 1;
  margin-top: 1px;
  opacity: .85;
  transition: .2s ease;
}

/* Hover */
.nav-item:hover {
  transform: translateY(-1px);
  background: rgba(40, 70, 120, .5);
  border-color: rgba(77, 160, 255, .35);
  color: #e6f0ff;
}

.nav-item:hover .nav-icon {
  background: rgba(77, 160, 255, .18);
  color: #9ac4ff;
}

.nav-item:hover .nav-label {
  opacity: 1;
}

/* Active — glow xanh */
.nav-item.active {
  background: linear-gradient(180deg, #2b5fd9 0%, #1e47b8 100%);
  border-color: rgba(120, 180, 255, .6);
  color: #fff;
  box-shadow:
    inset 0 0 0 1px rgba(120, 180, 255, .25),
    0 4px 16px rgba(43, 95, 217, .45),
    0 0 20px rgba(77, 160, 255, .35);
}

.nav-item.active .nav-icon {
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

.nav-item.active .nav-label {
  opacity: 1;
  font-weight: 800;
}

.nav-item:active {
  transform: scale(.96);
}

/* Responsive: tablet */
@media (max-width: 1100px) {
  .nav-item {
    min-width: 62px;
    padding: 6px 8px;
  }

  .nav-icon {
    width: 28px;
    height: 28px;
  }

  .nav-icon svg {
    width: 17px;
    height: 17px;
  }

  .nav-label {
    font-size: 10px;
  }
}

/* =========================
   PAGE LAYOUT
   ========================= */
.container {
  padding: 18px;
  padding-top: 90px;

}

.group {
  margin-bottom: 18px;
}

.group-title {
  margin: 8px 2px 10px;
  font-weight: 800;
  letter-spacing: .2px;
  color: rgba(255, 255, 255, .92);
}

.group-sub {
  margin-top: -6px;
  margin-bottom: 10px;
  font-size: 12px;
  color: rgba(255, 255, 255, .60);
}

/* Grid cards */
.grid,
.group .grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(320px, 1fr));
  gap: 14px;
}

@media (max-width:1200px) {

  .grid,
  .group .grid {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
  }
}

@media (max-width:760px) {

  .grid,
  .group .grid {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.card {
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .04));
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}

.card.offline {
  opacity: .6;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-name {
  font-weight: 700;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
}

.badge.ok {
  color: var(--ok);
  border-color: rgba(41, 214, 125, .35);
}

.badge.bad {
  color: var(--bad);
  border-color: rgba(255, 77, 77, .35);
}

.meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.card-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}

.card-actions .btn {
  flex: 1;
}

/* =========================
   MODAL
   ========================= */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  padding: 16px;
}

.modal-card {
  width: min(980px, 98vw);
  border: 1px solid var(--stroke);
  background: rgba(11, 18, 32, .85);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--stroke);
}

.modal-title {
  font-weight: 800;
  font-size: 16px;
}

.modal-sub {
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  cursor: pointer;
}

.modal-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--stroke);
  flex-wrap: wrap;
}

.pill {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, .06);
}

.tool-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.lbl {
  font-size: 12px;
  color: var(--muted);
}

.chart-wrap {
  padding: 14px 16px 18px;
}

/* =========================
   LOADING OVERLAY
   ========================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(11, 18, 32, .85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-overlay.hide {
  display: none;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #fff;
}

.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .2);
  border-top-color: #4d7cff;
  animation: spin .9s linear infinite;
}

.loading-text {
  font-size: 13px;
  opacity: .8;
  letter-spacing: .3px;
}

.loading-progress {
  font-size: 12px;
  opacity: .75;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================
   CHATBOX LAYOUT
   ========================= */
.chat-wrap {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 14px;
  height: calc(100vh - var(--headerH));
}

.chat-left,
.chat-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-head {
  padding: 14px;
  border-bottom: 1px solid var(--stroke);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-weight: 800;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
}

.status-badge {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  display: flex;
  gap: 6px;
  align-items: center;
}

.chat-body {
  flex: 1;
  padding: 14px;
  overflow: auto;
}

.chat-composer {
  padding: 12px;
  border-top: 1px solid var(--stroke);
  display: flex;
  gap: 10px;
}

.chat-composer input {
  flex: 1;
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--stroke);
  color: #fff;
  outline: none;
}

.block {
  margin-bottom: 16px;
}

.block-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
  font-size: 13px;
}

.full {
  width: 100%;
}

/* =========================
   MOBILE / TABLET
   ========================= */

/* Tablet */
@media (min-width:761px) and (max-width:1200px) {
  .group .grid {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
  }
}

/* Mobile */
@media (max-width:760px) {

  :root {
    --headerH: 64px;
  }

  .topbar {
    padding: 6px 6px;
    gap: 10px;
  }

  .logo-wide {
    height: 34px;
    max-width: 120px;
  }

  /* mobile: ẩn chữ brand (giữ logo) */
  .brand-text {
    display: none;
  }

  /* ẩn nav desktop, dùng dock */
  .main-nav {
    display: none !important;
  }

  /* ẩn control desktop cho gọn */
  #datePick,
  #btnViewDate,
  #btnLatest,
  #reload {
    display: none;
  }

  #search {
    width: min(68vw, 360px);
  }

  .container {
    padding: 12px;
    padding-bottom: var(--mobileDockH);
    padding-top: 64px;

  }

  /* chat: ẩn panel trái */
  .chat-wrap {
    grid-template-columns: 1fr;
  }

  .chat-left {
    display: none;
  }

  /* nếu chart-box có dùng: */
  .chart-box {
    height: 220px !important;
  }
}

/* =========================
   MOBILE BOTTOM BAR (DATE/REFRESH) + MOBILE DOCK (NAV)
   - bar nằm TRÊN dock
   ========================= */

/* mặc định ẩn, chỉ bật trên mobile */
.mobile-bar,
.mobile-nav {
  display: none;
}

@media (max-width:760px) {

  /* Dock chuyển trang (dưới cùng) */
  .mobile-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 60;

    display: flex;
    gap: 10px;
    padding: 10px;

    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(11, 18, 32, .72);
    backdrop-filter: blur(12px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  }

  .mobile-nav .mnav {
    flex: 1;
    height: 56px;
    border-radius: 14px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;

    text-decoration: none;
    color: rgba(255, 255, 255, .85);
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .10);
    transition: .18s ease;
  }

  .mobile-nav .micon {
    font-size: 18px;
    line-height: 1;
  }

  .mobile-nav .mlabel {
    font-size: 9.5px;
    line-height: 1;
    opacity: .75;
    letter-spacing: .2px;
  }

  .mobile-nav .mnav:hover {
    background: rgba(255, 255, 255, .10);
  }

  .mobile-nav .mnav.active {
    background: rgba(77, 124, 255, .25);
    border-color: rgba(77, 124, 255, .60);
    color: #fff;
  }

  .mobile-nav .mnav:active {
    transform: scale(.95);
  }

  /* Thanh lịch/refresh (nằm trên dock) */
  .mobile-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + 68px + env(safe-area-inset-bottom));
    /* trên dock */
    z-index: 70;

    display: flex;
    gap: 10px;
    align-items: center;

    padding: 10px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(11, 18, 32, .75);
    backdrop-filter: blur(12px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  }

  .mobile-bar .input {
    flex: 1;
    height: 42px;
    border-radius: 14px;
  }

  .mobile-bar .btn {
    height: 42px;
    padding: 0 14px;
    border-radius: 14px;
    white-space: nowrap;
  }
}

/* màn rất nhỏ */
@media (max-width:360px) {
  .mobile-nav {
    gap: 8px;
    padding: 9px;
  }

  .mobile-nav .mnav {
    height: 52px;
  }

  .mobile-nav .micon {
    font-size: 17px;
  }

  .mobile-nav .mlabel {
    font-size: 9px;
  }

  .mobile-bar .btn {
    padding: 0 12px;
  }
}

/* ===== FIX nền bị lệch khi scroll: tách nền ra lớp fixed ===== */
body {
  background: var(--bg) !important;
  /* chỉ giữ màu nền */
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;

  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(77, 124, 255, .18), transparent 55%),
    radial-gradient(1000px 700px at 90% 20%, rgba(41, 214, 125, .14), transparent 55%),
    var(--bg);

  transform: translateZ(0);
  /* giảm giật khi scroll */
}

/* ===============================
   MOBILE DOCK – Giống mapdma
   =============================== */
@media (max-width: 760px) {

  .mobile-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 9999;

    display: flex;
    gap: 10px;

    padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
    border-radius: 18px;

    /* Glass nhẹ */
    background: rgba(20, 30, 50, .22);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);

    border: 1px solid rgba(255, 255, 255, .15);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  }

  .mobile-nav .mnav {
    flex: 1;
    height: 56px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;

    border-radius: 14px;
    text-decoration: none;

    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .12);

    color: rgba(255, 255, 255, .85);
    transition: .18s ease;
  }

  .mobile-nav .micon {
    font-size: 18px;
  }

  .mobile-nav .mlabel {
    font-size: 9.5px;
    opacity: .75;
  }

  .mobile-nav .mnav.active {
    background: rgba(77, 124, 255, .25);
    border-color: rgba(77, 124, 255, .6);
    color: #fff;
  }

  .mobile-nav .mnav.active .mlabel {
    opacity: 1;
  }

  .mobile-nav .mnav:active {
    transform: scale(.95);
  }

}