/* AWS Monitor - tampilan HP (layar 720px ke bawah) */

/* Elemen khusus HP: disembunyikan di laptop/desktop */
.bottom-nav,
.overlay {
  display: none;
}

/* Perbaikan: tombol dengan atribut hidden harus benar-benar hilang */
.login-link[hidden],
.logout[hidden] {
  display: none;
}

#mapView {
  position: relative;
  isolation: isolate; /* supaya kontrol peta tidak menimpa menu */
}

@media (max-width: 720px) {
  :root {
    --nav-h: 64px;
  }

  html {
    scroll-padding-top: 72px;
  }

  body {
    background: #f3f6fb;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
  }

  body.no-scroll {
    overflow: hidden;
  }

  input,
  select,
  textarea {
    font-size: 16px; /* mencegah iPhone zoom sendiri saat mengetik */
  }

  /* ---------- Bar atas ---------- */
  .mobile-top {
    display: flex;
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 25;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }

  .mobile-top button {
    flex: none;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #f1f5fb;
    color: var(--navy);
  }

  .mobile-top button svg {
    width: 21px;
    height: 21px;
  }

  .mobile-top b {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    letter-spacing: -0.02em;
    color: var(--navy);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-dot {
    flex: none;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9aa6b5;
  }

  .top-dot.online {
    background: #16a34a;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.16);
  }

  .top-dot.offline {
    background: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14);
  }

  #mobileRole {
    flex: none;
    font-size: 11px;
    font-weight: 800;
    color: var(--blue);
    background: var(--blue-soft);
    padding: 6px 10px;
    border-radius: 99px;
  }

  /* ---------- Isi halaman ---------- */
  .content {
    margin: 0;
    padding: calc(68px + env(safe-area-inset-top, 0px)) 14px calc(var(--nav-h) + 26px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
  }

  /* Judul halaman sudah ada di bar atas, jadi disembunyikan (tetap terbaca screen reader) */
  .topbar {
    display: block;
    margin-bottom: 14px;
  }

  .topbar > div:first-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .station-picker {
    min-width: 0;
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 10px 12px 12px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(22, 47, 82, 0.05);
  }

  .station-picker-head {
    margin-bottom: 8px;
  }

  .station-picker-head small,
  .station-picker-live {
    display: none;
  }

  .station-picker-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .station-picker select {
    min-height: 46px;
    border-radius: 12px;
    font-size: 16px;
  }

  /* ---------- Kartu utama (hero) ---------- */
  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    min-height: 0;
    padding: 18px;
    margin-bottom: 14px;
    border-radius: 20px;
    box-shadow: 0 10px 24px rgba(16, 38, 74, 0.12);
  }

  .hero h2 {
    font-size: 24px;
    margin: 10px 0 3px;
  }

  .hero p {
    font-size: 13px;
  }

  .hero .last-update {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    text-align: left;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.16);
  }

  .last-update small {
    display: inline;
  }

  .last-update b {
    margin: 0;
    font-size: 12px;
  }

  /* ---------- Kartu sensor ---------- */
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0 0 14px;
  }

  .sensor-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 13px;
    border-radius: 16px;
    overflow-wrap: anywhere;
    box-shadow: 0 2px 8px rgba(23, 45, 77, 0.04);
  }

  .sensor-top {
    order: 0;
    margin-bottom: 10px;
  }

  .sensor-icon {
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  .sensor-card label {
    order: 1;
    margin: 0;
    font-size: 12px;
    font-weight: 650;
    color: #586981;
  }

  .sensor-card strong {
    order: 2;
    margin: 3px 0 4px;
    font-size: clamp(21px, 6.4vw, 26px);
    line-height: 1.15;
  }

  .sensor-explanation {
    order: 3;
    margin: 0;
    min-height: 0;
    font-size: 11px;
    line-height: 1.4;
  }

  .sensor-card small {
    order: 4;
    margin-top: auto;
    padding-top: 10px;
    font-size: 9.5px;
    color: #9aa5b4;
  }

  .forecast-card strong {
    font-size: 17px;
  }

  .forecast-card p {
    order: 3;
    margin: 0;
    font-size: 11.5px;
  }

  /* ---------- Panel, grafik, status risiko ---------- */
  .two-col {
    gap: 12px;
    margin-top: 0;
  }

  .panel {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 18px;
    box-shadow: 0 2px 10px rgba(23, 45, 77, 0.04);
  }

  .two-col .panel {
    margin-bottom: 0;
  }

  .panel canvas {
    max-height: 230px;
  }

  .chart-panel {
    height: min(60vh, 380px);
    padding: 12px;
  }

  .chart-panel canvas {
    max-height: none;
  }

  .risk {
    padding: 12px 13px;
    border-radius: 12px;
    font-size: 12px;
  }

  .risk > b {
    padding: 4px 10px;
    border-radius: 99px;
    background: #eef1f5;
    font-size: 10.5px;
  }

  .risk > b.normal {
    background: #e6f5ec;
  }

  .risk > b.warn {
    background: #fcf0d9;
  }

  .risk > b.danger {
    background: #fce6e6;
  }

  /* ---------- Judul bagian ---------- */
  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 2px 0 12px;
  }

  .section-head h2 {
    font-size: 20px;
    margin: 0 0 3px;
  }

  .section-head p {
    font-size: 12.5px;
    line-height: 1.5;
  }

  .section-head select,
  .section-head .primary,
  .section-head .secondary {
    width: 100%;
    min-height: 46px;
    justify-content: center;
    border-radius: 12px;
    font-size: 15px;
  }

  .export-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    width: 100%;
  }

  .export-actions button {
    min-height: 46px;
    border-radius: 12px;
  }

  /* ---------- Peta ---------- */
  #mapView {
    height: 60vh;
    height: calc(100dvh - 260px);
    min-height: 320px;
    max-height: 520px;
    border-radius: 16px;
  }

  /* ---------- Riwayat: tabel berubah jadi kartu ---------- */
  .panel.table-wrap {
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .table-wrap table,
  .table-wrap tbody {
    display: block;
    min-width: 0;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(23, 45, 77, 0.04);
  }

  .table-wrap tbody tr:hover {
    background: #fff;
  }

  .table-wrap td {
    display: block;
    padding: 0;
    border: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--navy);
    white-space: normal;
  }

  .table-wrap td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #8793a4;
  }

  .table-wrap td:first-child {
    grid-column: 1 / -1;
    padding-bottom: 9px;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
    font-weight: 650;
    color: var(--muted);
  }

  .table-wrap td:first-child::before {
    display: none;
  }

  .table-wrap td[colspan] {
    padding: 4px 0;
    border: 0;
    font-weight: 500;
  }

  /* ---------- Peringatan, device, backup ---------- */
  .alert {
    padding: 14px;
    border-radius: 14px;
  }

  .alert b {
    font-size: 13px;
  }

  .alert p {
    font-size: 12px;
    line-height: 1.55;
  }

  .device-row {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 14px;
    border-radius: 14px;
  }

  .device-row button {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 12px;
  }

  .backup-info {
    padding: 28px 18px;
  }

  .primary,
  .secondary {
    min-height: 44px;
    border-radius: 12px;
  }

  /* ---------- Prakiraan cuaca ---------- */
  .forecast-hero {
    flex-direction: row;
    gap: 14px;
    padding: 18px;
    border-radius: 20px;
  }

  .forecast-hero .forecast-illustration {
    min-width: 56px;
    font-size: 50px;
  }

  .forecast-hero h3 {
    font-size: 20px;
    line-height: 1.2;
  }

  .forecast-hero .muted {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.5;
  }

  .forecast-hourly {
    display: flex;
    gap: 10px;
    margin: 12px -14px;
    padding: 2px 14px 6px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding-left: 14px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .forecast-hourly::-webkit-scrollbar {
    display: none;
  }

  .forecast-hourly > .panel {
    flex: 0 0 100%;
    margin: 0;
  }

  .hour-card {
    flex: 0 0 92px;
    scroll-snap-align: start;
    padding: 12px 6px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(23, 45, 77, 0.04);
  }

  /* ---------- Menu samping (drawer) ---------- */
  .sidebar {
    width: min(310px, 86vw);
    left: 0;
    z-index: 40;
    padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
    box-shadow: none;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
    box-shadow: 18px 0 50px rgba(9, 25, 49, 0.22);
    transition: transform 0.25s ease;
  }

  .sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    align-content: start;
    overflow-y: auto;
    padding-bottom: 10px;
  }

  .sidebar nav a {
    min-height: 46px;
    padding: 12px 13px;
    border-radius: 12px;
    font-size: 13px;
  }

  .sidebar nav a svg {
    width: 19px;
    height: 19px;
  }

  .mqtt {
    padding: 12px;
    border-radius: 13px;
    font-size: 11px;
  }

  .login-link,
  .logout {
    min-height: 46px;
    border-radius: 12px;
  }

  .overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(10, 24, 48, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------- Menu bawah ---------- */
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    inset: auto 0 0 0;
    z-index: 25;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 6px env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.94);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 20px rgba(16, 38, 74, 0.06);
  }

  .bottom-nav button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #7a889d;
    font-size: 10.5px;
    font-weight: 700;
  }

  .bn-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 30px;
    border-radius: 99px;
    transition: background 0.15s ease;
  }

  .bottom-nav button svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.9;
  }

  .bottom-nav button.active {
    color: var(--blue);
  }

  .bottom-nav button.active .bn-icon {
    background: var(--blue-soft);
  }

  .bn-badge {
    position: absolute;
    top: 0;
    left: calc(50% + 8px);
    display: grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border: 2px solid #fff;
    border-radius: 99px;
    background: #d93636;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
  }

  .bn-badge[hidden] {
    display: none;
  }

  /* ---------- Form tambah device (bottom sheet) ---------- */
  .modal {
    padding: 0;
    place-items: end stretch;
  }

  .modal-box {
    width: 100%;
    max-width: none;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
  }

  .modal-box h3 {
    margin: 0;
    padding-right: 40px;
    letter-spacing: -0.02em;
  }

  .close {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    line-height: 1;
  }

  .modal input {
    min-height: 48px;
    border-radius: 12px;
  }

  .modal .primary {
    min-height: 48px;
    justify-content: center;
  }
}

/* HP kecil (lebar 360px ke bawah) */
@media (max-width: 360px) {
  .content {
    padding-left: 11px;
    padding-right: 11px;
  }

  .cards {
    gap: 8px;
  }

  .sensor-card {
    padding: 11px;
  }

  .sensor-card strong {
    font-size: 20px;
  }

  .bottom-nav button {
    font-size: 10px;
  }

  .bn-icon {
    width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .overlay,
  .bn-icon {
    transition: none !important;
  }
}
