/* Responsive & Mobile PWA stylesheet for Yoosee Cloud NVR Pro (Task P) */

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

body {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

img,
video,
canvas,
svg {
  max-width: 100%;
}

/* ---------- PWA banners, toasts & live viewer strip ---------- */
.pwa-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  margin: 0 0 14px;
  border-radius: 11px;
  border: 1px solid #2e4c74;
  background: #132136;
  color: #edf3fd;
  font-size: 13px;
  z-index: 55;
}

.pwa-banner.pwa-offline-banner {
  border-color: #6b5326;
  background: #2a2215;
  color: #f4d89b;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pwa-toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #355888;
  background: #141c28;
  color: #edf3fd;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  font-size: 13px;
}

.pwa-live-feed {
  border: 1px solid #273346;
  border-radius: 12px;
  background: #141c28;
  padding: 14px 16px;
  margin: 0 0 20px;
}

.pwa-live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.pwa-live-head h2 {
  font-size: 15px;
  margin: 0;
}

.pwa-live-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pwa-live-controls label {
  font-size: 12px;
  color: #9baac0;
}

.pwa-live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.pwa-live-card {
  border: 1px solid #273346;
  border-radius: 10px;
  background: #101824;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pwa-live-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.pwa-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #54d6b1;
  display: inline-block;
  flex-shrink: 0;
}

.pwa-live-preview-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  background: #060b12;
  border: 1px solid #223047;
}

.pwa-bottom-nav {
  display: none;
}

/* ---------- Notification drawer & shared controls (for viewer.html + mobile) ---------- */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  background: #4a2a1d;
  color: #ffc29a;
  font-size: 11px;
  font-weight: 650;
  border-radius: 10px;
  padding: 1px 7px;
}

#notif-drawer {
  background: #141c28;
  border: 1px solid #273346;
  border-radius: 12px;
  padding: 16px;
  color: #edf3fd;
}

#notif-drawer .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#notif-drawer .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#notif-drawer .chip {
  background: #101824;
  border: 1px solid #273346;
  color: #9baac0;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 12px;
}

#notif-drawer .chip.active {
  background: #192b45;
  border-color: #3d6797;
  color: #edf3fd;
}

#notif-drawer .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #243145;
  color: #c3d2e8;
}

#notif-drawer .badge.ok { background: #183a34; color: #54d6b1; }
#notif-drawer .badge.bad { background: #3c1e26; color: #ff8f9a; }
#notif-drawer .badge.warn { background: #3a2f18; color: #e5c687; }
#notif-drawer .badge.info { background: #1b2f4d; color: #73a7ff; }

#notif-drawer .panel {
  background: #101824;
  border: 1px solid #273346;
  border-radius: 10px;
  padding: 12px;
}

#notif-drawer .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #9baac0;
  margin-bottom: 8px;
  flex: 1;
  min-width: 140px;
}

#notif-drawer .form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

#notif-drawer .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

#notif-drawer .msg {
  margin-top: 8px;
  font-size: 12px;
  color: #9baac0;
}

#notif-drawer .msg.err { color: #ff8f9a; }
#notif-drawer .msg.ok { color: #54d6b1; }
#notif-drawer .small, #notif-drawer .muted { color: #9baac0; font-size: 12px; }

/* ---------- Desktop (> 1024px) & Tablet (761px - 1024px) ---------- */
@media (min-width: 761px) {
  .pwa-bottom-nav {
    display: none !important;
  }
}

@media (max-width: 1024px) and (min-width: 761px) {
  .layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
  main {
    padding: 20px;
  }
  .workspace {
    padding: 24px 20px;
  }
  .viewer-grid {
    grid-template-columns: minmax(0, 1fr) 240px;
  }
}

/* ---------- Touch targets (Mobile & Coarse Pointers) ---------- */
@media (max-width: 760px), (pointer: coarse) {
  button:not(.hour):not(.tl-bookmark-pin),
  select,
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  a.primary,
  a.secondary,
  a.ghost,
  a.quiet,
  nav button,
  .camera-card,
  .day-item,
  .chip,
  .ptz-btn,
  .timeline-zoom-wrap button,
  .pwa-bottom-nav button,
  .pwa-bottom-nav a,
  .pwa-bottom-btn,
  .pwa-banner-btn,
  .pwa-toast-btn {
    min-height: 44px;
  }

  .ptz-btn,
  #prev-day,
  #next-day,
  #btn-fullscreen,
  #notif-bell,
  #btn-play,
  #btn-mute,
  #btn-logout,
  #btn-login,
  #btn-refresh,
  #btn-jump,
  #btn-retry,
  .timeline-zoom-wrap button,
  .pwa-bottom-btn,
  .pwa-banner-btn,
  .pwa-toast-btn,
  .pwa-banner button,
  .pwa-toast button {
    min-width: 44px;
  }

  .timeline .hour {
    min-width: 0;
    min-height: 28px;
    padding: 4px 0;
  }

  .tl-bookmark-pin {
    min-width: 0;
    min-height: 0;
  }

  .ptz-btn {
    padding: 8px 10px;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
  }

  .timeline-zoom-wrap button {
    padding: 8px 10px;
    font-size: 12px;
  }

  .auto-day,
  .row.checks label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }
}

@media (max-width: 860px) {
  .topbar {
    height: auto;
    min-height: 60px;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
  }

  .topbar-actions,
  .account {
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
  }
}

/* ---------- Mobile (<= 760px: 360px, 375px, 390px, 412px, 760px) ---------- */
@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 60px;
    padding: max(8px, env(safe-area-inset-top, 8px)) 14px 8px;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
  }

  .topbar-actions,
  .account {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    min-width: 0;
    max-width: 100%;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "top" "nav" "main";
    padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }

  nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid #273346;
    scrollbar-width: thin;
  }

  nav .nav-group {
    display: none;
  }

  nav button {
    width: auto;
    flex-shrink: 0;
    white-space: nowrap;
    margin-bottom: 0;
    padding: 8px 12px;
  }

  main {
    padding: 16px 12px;
  }

  .workspace {
    padding: 18px 12px calc(82px + env(safe-area-inset-bottom, 0px));
  }

  .grid-2,
  .flow {
    grid-template-columns: 1fr;
  }

  .grid-2 > .panel {
    min-width: 0;
  }

  .flow > .panel {
    margin-top: 0;
    min-width: 0;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .day-controls {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .timeline-tools {
    flex-wrap: wrap;
    gap: 8px;
  }

  .smart-toolbar {
    gap: 8px;
  }

  #notif-drawer,
  #remote-access-drawer {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: calc(100vw - 16px) !important;
    top: 64px !important;
    max-height: calc(100vh - 144px);
    overflow-y: auto;
  }

  #notif-drawer .row,
  #remote-access-drawer .row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .pwa-toast {
    left: 12px;
    right: 12px;
    max-width: none;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }

  .pwa-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(14, 21, 31, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid #273346;
  }

  .pwa-bottom-nav button,
  .pwa-bottom-nav a {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    padding: 6px 4px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: #9baac0;
    font-size: 11px;
    font-weight: 550;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pwa-bottom-nav button.active {
    background: #192b45;
    border-color: #2e4c74;
    color: #edf3fd;
  }
}

/* ---------- Narrow Mobile (<= 480px & <= 360px / 320px) ---------- */
@media (max-width: 480px) {
  .login-wrap {
    width: auto;
    max-width: none;
    margin: 4vh 12px;
    padding: 20px 16px;
  }

  .login-screen {
    padding: 20px 12px;
    gap: 18px;
  }

  .login-card {
    padding: 20px 16px;
  }

  .topbar {
    padding: max(8px, env(safe-area-inset-top, 8px)) 10px 8px;
  }

  .brand {
    font-size: 16px;
  }

  .page-heading {
    flex-wrap: wrap;
    gap: 10px;
  }

  .pwa-live-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .camera-cards,
  .stats {
    grid-template-columns: 1fr;
  }

  .drive-storage-values {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* ---------- Landscape Mobile (e.g. 844x390) ---------- */
@media (max-height: 460px) and (orientation: landscape) {
  .video-wrap {
    max-height: 68vh;
  }

  .pwa-bottom-nav {
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }

  .login-screen {
    padding: 16px 20px;
  }
}
