/* =====================================================================
   mobile.css — Bố cục cho điện thoại. Nạp SAU styles.css.
   Trên màn hình rộng (> 768px) giao diện giữ nguyên như bản exe.
   ===================================================================== */

:root {
  --m-header-h: 50px;
  --m-nav-h: 58px;
}

/* Mục menu đang mở (dùng chung cho mọi kích thước) */
.win13-nav .nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #3c4043;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.win13-nav .nav-item.active {
  background: #fff;
  color: #2d6a0f;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}

/* Thông báo nhỏ (showToast) — luôn nổi trên cùng, không bị che */
body > .alert.alert-dismissible {
  position: fixed;
  top: calc(var(--m-header-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  z-index: 3000;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}

/* Bỏ hiệu ứng nhấn xanh mặc định của Android */
html.is-native * { -webkit-tap-highlight-color: transparent; }

@media (max-width: 768px) {

  /* ---------- HEADER ---------- */
  .header { padding: 0 8px; }
  .logo2-img { height: 38px; width: 38px; }
  .device-name { display: none; }
  .ios-control-group {
    display: flex !important;
    padding: 3px 6px;
    margin-right: 6px !important;
    gap: 4px !important;
  }
  .ios-btn { width: 32px; height: 32px; font-size: .85rem; }
  #gw4gSignalBadge { font-size: 9px; }
  .user-profile { padding-left: 6px; }
  .avatar-circle { width: 34px !important; height: 34px !important; font-size: .85rem; }

  /* ---------- MENU: chuyển xuống thanh dưới cùng ---------- */
  .win13-nav {
    display: flex !important;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    height: var(--m-nav-h);
    padding: 0 4px;
    gap: 0;
    border-radius: 0;
    border: none;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    backdrop-filter: none;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
    justify-content: space-between;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    z-index: 1200;
  }
  .win13-nav::-webkit-scrollbar { display: none; }
  .win13-nav:hover { background: #ffffff; box-shadow: 0 -2px 10px rgba(0, 0, 0, .06); }
  .win13-nav .nav-item {
    flex: 1 0 40px;
    max-width: 56px;
    height: 44px;
    border-radius: 12px;
    font-size: 1.05rem;
    color: #6c757d;
  }
  .win13-nav .nav-item.active {
    background: #EAF3DE;
    color: #2d6a0f;
    box-shadow: none;
  }

  /* Footer nhường chỗ cho thanh menu */
  .footer { display: none !important; }

  /* ---------- KHUNG NỘI DUNG ---------- */
  .content-wrapper {
    height: calc(100vh - var(--m-header-h) - var(--m-nav-h));
    height: calc(100dvh - var(--m-header-h) - var(--m-nav-h));
    margin-top: var(--m-header-h);
  }
  .leaflet-container { border-radius: 0; }

  #allChartsView, #chartView, #ndviView, #weatherView, #stationListView,
  #stationDetail, #aiChatView, #manualDataView, #farmCalendarView {
    bottom: var(--m-nav-h) !important;
  }
  #settingsView {
    bottom: var(--m-nav-h) !important;
    padding: 0 !important;
  }

  /* ---------- BẢN ĐỒ: tràn viền, popup vừa màn hình ---------- */
  .main-content.p-4 { padding: 0 !important; }
  .station-popup .leaflet-popup-content {
    min-width: 0 !important;
    max-width: calc(100vw - 70px) !important;
    width: calc(100vw - 70px) !important;
    max-height: 40vh;
    overflow-y: auto;
    margin: 10px !important;
  }
  .station-popup-content { min-width: 0 !important; }

  /* ---------- GIÁM SÁT TRẠM ---------- */
  #chartView > .d-flex.justify-content-between {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
    padding: 0 !important;
  }
  #chartView > .d-flex.justify-content-between > .d-flex.bg-white {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px !important;
  }
  #chartView .sun-track-mini-wrapper { display: none; }
  #chartView .pe-4.border-end { display: none; }
  #chartView [style*="min-width: 300px"] {
    min-width: 0 !important;
    width: 100%;
    margin-left: 0 !important;
  }

  /* ---------- BIỂU ĐỒ TỔNG ---------- */
  .acv-topbar { padding: 8px 10px; }
  .acv-title { font-size: 13px; }
  .acv-seg button { padding: 5px 10px; }
  .acv-summary { padding: 8px 10px 0; gap: 8px; }
  .acv-sum { padding: 8px 10px; }
  .acv-sum-val { font-size: 16px; }
  .acv-charts { padding: 8px 10px 12px; }
  .acv-card { margin-bottom: 10px; }
  .acv-card-hdr { flex-wrap: wrap; gap: 4px; padding: 8px 12px; }

  /* ---------- CÀI ĐẶT: menu trái → thanh ngang cuộn được ---------- */
  #settingsView .sv-wrap {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  #settingsView .sv-sidebar {
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: none;
    border-bottom: 0.5px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 5;
    scrollbar-width: none;
  }
  #settingsView .sv-sidebar::-webkit-scrollbar { display: none; }
  #settingsView .sv-sidebar-hdr,
  #settingsView .sv-nav-section { display: none; }
  #settingsView .sv-nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 10px 12px;
  }
  #settingsView .sv-nav-item.active { border-bottom-color: #3B6D11; }
  #settingsView .sv-sidebar-footer {
    margin-top: 0;
    border-top: none;
    padding: 6px 8px;
    flex: 0 0 auto;
  }
  #settingsView .sv-save-btn { white-space: nowrap; padding: 7px 12px; }
  #settingsView .sv-content { padding: 12px; }
  #settingsView .sv-field-row { flex-wrap: wrap; }
  #settingsView .sv-field-control { max-width: 100%; }
  #settingsView .sv-field-control input,
  #settingsView .sv-field-control select,
  #settingsView .sv-field-control textarea {
    max-width: 100% !important;
  }
  #settingsView .sv-thresh-grid { grid-template-columns: repeat(2, 1fr); }
  #settingsView .sv-table-wrap { overflow-x: auto; }

  /* ---------- CHI TIẾT TRẠM ---------- */
  .station-dashboard-wrapper { border-radius: 0 !important; margin-top: 0 !important; }
  .charts-main { padding: 12px !important; }
  .stats-sidebar { border-right: none !important; }

  /* ---------- AI CHUYÊN GIA ---------- */
  #aiExpertView {
    position: fixed;
    top: var(--m-header-h);
    left: 0;
    right: 0;
    bottom: var(--m-nav-h);
    height: auto !important;
    z-index: 10;
  }
  #aiExpertView .aix-chat { border-radius: 0; }
  #aiExpertView .aix-quick { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #aiExpertView .aix-quick::-webkit-scrollbar { display: none; }
  #aiExpertView .aix-qbtn { flex: 0 0 auto; }
  #aiExpertView .aix-input { font-size: 16px; } /* tránh Android tự phóng to khi gõ */

  /* ---------- NHẬP LIỆU THỦ CÔNG ---------- */
  #manualDataView .md-tab-btn { padding: 6px 10px; font-size: 12px; }
  #manualDataView [style*="grid-template-columns:repeat(4"],
  #manualDataView [style*="grid-template-columns:repeat(3"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* ---------- LỊCH CANH TÁC ---------- */
  .fc-tabs { width: 100%; overflow-x: auto; }
  .fc-tab { white-space: nowrap; flex: 1 0 auto; text-align: center; }
  .fc-cell { min-height: 54px; }
  .fc-ev { font-size: 9px; }
  .fc-modal { width: 92vw !important; }
  .fc-f3 { grid-template-columns: 1fr; }

  /* ---------- SMART ALERT: đẩy lên trên thanh menu ---------- */
  #sa-widget { bottom: calc(var(--m-nav-h) + 12px) !important; right: 12px !important; }
  #sa-btn { width: 44px; height: 44px; }
  /* Trang AI: đẩy chuông lên trên ô nhập để không che nút gửi */
  body:has(#aiExpertView[style*="display: block"]) #sa-widget {
    bottom: calc(var(--m-nav-h) + 96px) !important;
  }
  #sa-panel { width: calc(100vw - 24px) !important; max-height: 60vh !important; }
  .sa-toast {
    bottom: calc(var(--m-nav-h) + 68px) !important;
    right: 12px !important;
    left: 12px;
    max-width: none !important;
  }

  /* ---------- HỘP THOẠI ---------- */
  .modal-dialog { margin: 12px; }
  .swal2-popup { width: 92vw !important; }
}

@media (max-width: 400px) {
  #settingsView .sv-thresh-grid { grid-template-columns: 1fr; }
}
