/**
 * Dashboard mobile — cố định 1:1, không pinch-zoom, không auto-zoom iOS khi focus input
 */

/* ===== Viewport / text scaling ===== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .app-shell,
  .main-wrapper,
  .main-content,
  .tab-panel {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  /* Input ≥16px — tránh Safari/Chrome mobile zoom khi focus */
  input,
  select,
  textarea,
  .input,
  .search-box input {
    font-size: 16px !important;
    max-width: 100%;
  }

  button,
  .btn,
  .btn-tag,
  .nav-item,
  .bottom-nav-item,
  .zozo-mtab {
    touch-action: manipulation;
  }

  /* Topbar & content padding */
  .page-topbar {
    padding: 12px 14px 0;
  }
  .main-content {
    padding: 12px 14px 0;
    padding-bottom: 8px;
  }
  .page-footer {
    padding: 16px 14px;
    font-size: 11px;
  }

  /* Stat cards — không tràn số lớn */
  .stat-value {
    font-size: clamp(20px, 6vw, 28px) !important;
    word-break: break-word;
  }
  .stat-label {
    font-size: 10px;
  }

  .card {
    max-width: 100%;
    overflow: hidden;
  }

  /* Bảng card mode — không cuộn ngang toàn trang */
  .table-wrapper,
  .table-container {
    max-width: 100%;
    overflow-x: hidden;
  }
  .table-mobile {
    width: 100%;
    min-width: 0 !important;
  }
  .table-mobile tbody tr {
    margin: 8px 0;
  }

  /* Nodes vẫn cuộn trong khung riêng */
  .nodes-table .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Dialog / overlay full width mobile */
  .overlay {
    padding: 12px;
    align-items: flex-end;
  }
  .dialog {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90dvh;
  }

  /* Bottom nav — lưới 6 cột, không scroll ngang */
  .bottom-nav {
    display: grid !important;
    grid-template-columns: repeat(6, 1fr);
    justify-content: stretch;
    overflow-x: hidden;
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
    gap: 0;
  }
  .bottom-nav-item {
    min-width: 0 !important;
    width: 100%;
    padding: 6px 2px 4px;
    font-size: 9px;
    letter-spacing: 0;
  }
  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
  }

  .mobile-header {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .search-box {
    max-width: 100% !important;
    flex: 1;
    min-width: 0;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }
  .page-btn {
    min-width: 36px;
    min-height: 36px;
  }
}

/* ===== Zozo mobile ===== */
.zozo-mobile-bar {
  display: none;
  gap: 8px;
  padding: 0 0 12px;
  max-width: 100%;
}
.zozo-mtab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  min-height: 44px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--input-fill);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  font-family: var(--font-sans);
}
.zozo-mtab.active {
  color: var(--accent);
  border-color: rgba(91, 111, 232, 0.45);
  background: var(--accent-subtle);
  box-shadow: var(--glow-sm);
}

.zozo-toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  max-width: 100%;
}
.zozo-toolbar-filters .input,
.zozo-toolbar-filters select {
  min-width: 0;
  flex: 1 1 140px;
  max-width: 100%;
  height: 44px;
}
.zozo-toolbar-filters .btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
}
.zozo-toolbar-filters .btn-row .btn {
  flex: 1;
  min-height: 44px;
}

#tab-zozo-ai .stat-grid,
#tab-zozo-data .stat-grid {
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .zozo-mobile-bar:not([hidden]) {
    display: flex;
  }

  #tab-zozo-ai .page-header,
  #tab-zozo-data .page-header {
    margin-bottom: 10px;
  }
  #tab-zozo-ai .page-title,
  #tab-zozo-data .page-title {
    font-size: 18px;
  }
  #tab-zozo-ai .page-sub,
  #tab-zozo-data .page-sub {
    display: block !important;
    font-size: 13px !important;
    line-height: 1.45;
  }

  #tab-zozo-ai .stat-grid,
  #tab-zozo-data .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  #tab-zozo-ai .card-title,
  #tab-zozo-data .card-title {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
  }

  .zozo-toolbar-filters {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .zozo-toolbar-filters .input,
  .zozo-toolbar-filters select {
    width: 100% !important;
    flex: none;
  }

  #tab-zozo-ai .form-grid-lic,
  #tab-zozo-data .form-grid-lic {
    grid-template-columns: 1fr !important;
  }

  #tab-zozo-ai .form-grid-lic .btn,
  #tab-zozo-ai .form-grid-lic button[type="submit"] {
    width: 100%;
    min-height: 44px;
  }

  #tab-zozo-ai .table-mobile tbody td[data-label="KEY"],
  #tab-zozo-ai .table-mobile tbody td[data-label="Key"],
  #tab-zozo-ai .table-mobile tbody td[data-label="HÀNH ĐỘNG"],
  #tab-zozo-ai .table-mobile tbody td[data-label="GHI CHÚ"],
  #zozo-ledger-card .table-mobile tbody td[data-label="Key"],
  #zozo-ledger-card .table-mobile tbody td[data-label="Profile"],
  #zozo-daily-card .table-mobile tbody td[data-label="Ngày"] {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  #tab-zozo-ai .table-mobile tbody td::before,
  #zozo-ledger-card .table-mobile tbody td::before,
  #zozo-daily-card .table-mobile tbody td::before {
    margin-bottom: 6px;
  }

  #tab-zozo-ai .lic-key-cell {
    flex-wrap: wrap;
    word-break: break-all;
    gap: 8px;
  }
  #tab-zozo-ai .lic-key-str {
    font-size: 13px;
    max-width: 100%;
    line-height: 1.35;
  }

  #tab-zozo-ai .action-btns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }
  #tab-zozo-ai .action-btns .btn-tag {
    width: 100%;
    min-height: 40px;
    text-align: center;
    justify-content: center;
    font-size: 12px;
    padding: 8px 6px;
  }

  #zozo-daily-card .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 480px) {
  .bottom-nav-item {
    font-size: 8px;
  }
  .bottom-nav-item svg {
    width: 18px;
    height: 18px;
  }

  #tab-zozo-ai .action-btns {
    grid-template-columns: 1fr;
  }

  #tab-zozo-data .stat-card:nth-child(4) {
    grid-column: 1 / -1;
  }
}
