/* ==========================================================================
   ETERNAL REST — Responsive System
   Loaded LAST on every page. Mobile-first overrides for all layouts.
   Breakpoints: 1200 / 992 / 768 / 576
   ========================================================================== */

/* ── 0. Global responsive helpers ─────────────────────────────────────── */
html { overflow-x: hidden; }
body { overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; }
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Ensure containers don't overflow on small screens only — don't override desktop */
@media (max-width: 767.98px) {
  .container, .container-fluid { max-width: 100%; }
}

/* ── 1. Sidebar + Main Area — Drawer below 992px ──────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 36, 0.55);
  backdrop-filter: blur(2px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0,0,0,0.35);
    z-index: 100;
  }
  .sidebar.open,
  .sidebar.show,
  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }
  /* collapsed class on mobile should mean hidden (default), not shown */
  .sidebar.collapsed {
    transform: translateX(-100%) !important;
  }
  .main-area,
  .main-area.expanded {
    margin-left: 0 !important;
  }
  .topbar {
    padding: 0.65rem 1rem;
    gap: 0.6rem;
  }
  .page-title {
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .live-clock {
    display: none !important;
  }
  .main-content {
    padding: 1rem;
  }
}

/* ── 2. Topbar responsive ─────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .topbar {
    flex-wrap: wrap;
  }
  .topbar-actions {
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .topbar-actions .btn-action,
  .topbar-actions .btn-view2 {
    padding: 0.35rem 0.6rem;
    font-size: 0.7rem;
  }
  /* Notification panel becomes full-width drawer on mobile */
  #notifPanel,
  #clientNotifPanel {
    position: fixed !important;
    top: 64px !important;
    right: 0 !important;
    left: 0 !important;
    width: auto !important;
    margin: 0 0.75rem;
    max-width: none !important;
  }
}

@media (max-width: 575.98px) {
  .topbar {
    padding: 0.6rem 0.75rem;
  }
  .toggle-btn {
    width: 34px;
    height: 34px;
  }
  .page-title {
    font-size: 0.95rem;
  }
  #branchBadge,
  #branchBadge span {
    font-size: 0.68rem !important;
    padding: 0.2rem 0.6rem !important;
  }
}

/* ── 3. Stat cards ────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .stat-card {
    padding: 1rem;
  }
  .stat-num {
    font-size: 1.45rem !important;
  }
  .stat-label {
    font-size: 0.68rem !important;
  }
  .stat-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 0.95rem !important;
  }
}

/* ── 4. Tables → horizontal scroll + card fallback ────────────────────── */
.data-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table .table {
  min-width: 640px;
}
@media (max-width: 767.98px) {
  .data-table .table {
    min-width: 560px;
  }
  .table-head {
    padding: 0.9rem 1rem;
    flex-direction: column;
    align-items: flex-start;
  }
  .table-head h6 {
    font-size: 0.95rem;
  }
  /* Filter bars stack */
  .d-flex.flex-wrap.gap-2 {
    gap: 0.5rem !important;
  }
  .form-ctrl {
    font-size: 0.85rem;
    padding: 0.55rem 0.8rem;
  }
}

/* Mobile card view for tables — applied via JS class .table-cards on <table> */
@media (max-width: 575.98px) {
  .table-cards thead { display: none; }
  .table-cards,
  .table-cards tbody,
  .table-cards tr,
  .table-cards td {
    display: block;
    width: 100%;
  }
  .table-cards tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: var(--white);
  }
  .table-cards td {
    border: none !important;
    border-bottom: 1px solid #f0ece4 !important;
    padding: 0.6rem 0.9rem !important;
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    text-align: right;
  }
  .table-cards td:last-child { border-bottom: none !important; }
  .table-cards td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }
  .table-cards td[data-label=""]::before { display: none; }
  .table-cards td[data-label=""] { justify-content: flex-start; }
}

/* ── 5. Filter / search bars ─────────────────────────────────────────── */
@media (max-width: 767.98px) {
  #adminInvSearch,
  #adminInvStatus,
  #adminInvCat,
  #adminInvSort,
  #siFrom, #siTo,
  input[type="search"].form-ctrl,
  select.form-ctrl {
    width: 100% !important;
    flex: 1 1 100%;
  }
  .filter-wrap {
    flex-direction: column;
    align-items: stretch !important;
  }
  .search-box {
    width: 100% !important;
  }
}

/* ── 6. Modals responsive ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .modal-dialog {
    margin: 0.75rem;
    max-width: none;
  }
  .modal-content {
    border-radius: 12px;
  }
  .modal-header-c,
  .modal-header-custom,
  .res-modal-header,
  .client-auth-header {
    padding: 1rem 1.2rem !important;
  }
  .modal-body-form,
  .modal-body-c,
  .res-modal-body,
  .auth-panel {
    padding: 1.2rem !important;
  }
  .modal-footer-actions,
  .res-modal-footer {
    padding: 0.9rem 1.2rem !important;
    flex-wrap: wrap;
  }
  .res-modal-box {
    margin: 0.5rem;
    max-width: none;
    width: calc(100% - 1rem);
  }
  .res-modal-footer {
    flex-direction: column;
    align-items: stretch;
  }
  .res-modal-footer .d-flex {
    width: 100%;
    justify-content: stretch;
  }
  .res-modal-footer button {
    flex: 1;
  }
}

/* ── 7. Forms — stack on mobile ───────────────────────────────────────── */
@media (max-width: 767.98px) {
  .row.g-3 > [class*="col-"] {
    /* Bootstrap handles this, but ensure no overflow */
    min-width: 0;
  }
  .form-section-title {
    font-size: 0.62rem;
  }
  .photo-drop-zone,
  .sac-photo-drop-zone {
    min-height: 100px;
  }
}

/* ── 8. Branch cards & hub tabs ───────────────────────────────────────── */
@media (max-width: 767.98px) {
  .branch-card {
    padding: 1.1rem;
  }
  .hub-tab, .sa-hub-tab {
    padding: 0.45rem 0.75rem;
    font-size: 0.74rem;
  }
  #branchTabs {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }
  #branchTabs::-webkit-scrollbar { display: none; }
}

/* ── 9. INDEX.HTML — Public site ──────────────────────────────────────── */
@media (max-width: 991.98px) {
  .navbar-eternal .container {
    flex-wrap: wrap;
  }
  .brand-wrap {
    gap: 8px;
  }
  .brand-icon {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  .brand-name {
    font-size: 1.15rem;
  }
  .brand-tag {
    font-size: 0.58rem;
    letter-spacing: 1.5px;
  }
  .hero {
    min-height: auto;
    padding: 2.5rem 0 2rem;
  }
  .hero-cross {
    display: none;
  }
  .hero h1 {
    font-size: clamp(1.9rem, 6vw, 2.6rem);
  }
  .hero-sub {
    font-size: 0.92rem;
    max-width: none;
  }
  .hero-stats {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
  }
  .hero-stats .row {
    gap: 1rem 0;
  }
  .services-section,
  .inventory-section,
  .memorial-section,
  .reservation-section,
  .testimonials-section,
  .orbit-section {
    padding: 2.5rem 0 !important;
  }
  .section-title {
    font-size: clamp(1.5rem, 5vw, 2rem);
  }
  .filter-wrap {
    padding: 0.9rem 1rem;
  }
  .casket-img {
    height: 180px;
  }
  .res-form-wrap {
    padding: 1.5rem !important;
  }
  .step-bar,
  .res-modal-step-bar {
    gap: 0.25rem;
  }
  .step-node {
    width: 30px;
    height: 30px;
    font-size: 0.72rem;
  }
  .step-connector {
    margin: 0 0.25rem;
  }
  .res-contact-bar {
    padding: 1rem;
    gap: 0.6rem 1rem;
  }
  footer {
    padding: 2rem 0 1.25rem !important;
  }
  footer .row > div {
    margin-bottom: 1.25rem;
  }
}

@media (max-width: 575.98px) {
  .navbar-eternal {
    padding: 0.6rem 0;
  }
  .nav-branch-pill-btn {
    font-size: 0.65rem;
    padding: 0.18rem 0.55rem;
  }
  .hero {
    padding: 1.8rem 0 1.5rem;
  }
  .hero h1 {
    font-size: 1.75rem;
    line-height: 1.2;
  }
  .hero-sub {
    font-size: 0.88rem;
    margin-bottom: 1.25rem;
  }
  .btn-hero-primary,
  .btn-hero-outline {
    padding: 0.7rem 1.4rem;
    font-size: 0.78rem;
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .hero .d-flex.gap-3 {
    flex-direction: column;
    gap: 0.6rem !important;
  }
  .service-card {
    padding: 1.5rem 1.2rem;
  }
  .casket-card .casket-body {
    padding: 1rem;
  }
  .memorial-card {
    padding: 1.2rem;
  }
  .mem-avatar {
    width: 56px;
    height: 56px;
    font-size: 1.25rem;
  }
  .orbit-stage-wrap {
    width: 92vw;
  }
  .orbit-center span {
    font-size: 0.6rem;
  }
  .res-form-wrap {
    padding: 1.2rem !important;
    border-radius: 12px !important;
  }
  .testimonial-card {
    padding: 0.75rem;
  }
  .client-auth-modal .modal-content {
    height: auto;
    max-height: 92vh;
  }
  .auth-panel {
    padding: 1.2rem 1.2rem 1.5rem !important;
  }
}

/* ── 10. MEMORIAL.HTML ────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .mem-hero {
    min-height: 280px;
  }
  .mem-hero-content {
    padding: 1.5rem 1rem 1.8rem;
  }
  .mem-name {
    font-size: 1.6rem;
  }
  .mem-quote-hero {
    font-size: 0.92rem;
  }
  .stats-bar .row {
    gap: 0.75rem 0;
  }
  .mem-section {
    padding: 1.8rem 0;
  }
  .slideshow-wrap {
    aspect-ratio: 4/3;
    max-height: 320px;
  }
}

@media (max-width: 575.98px) {
  .mem-hero {
    min-height: 240px;
  }
  .mem-avatar-large {
    width: 72px;
    height: 72px;
    font-size: 1.7rem;
  }
  .mem-name {
    font-size: 1.35rem;
  }
  .mem-years {
    font-size: 0.68rem;
    letter-spacing: 2px;
  }
  .stat-pill .num {
    font-size: 1.15rem;
  }
  .sec-title {
    font-size: 1.1rem;
  }
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
  }
  .tribute-card {
    padding: 0.9rem;
  }
  .tribute-form {
    padding: 1rem;
  }
  .mem-gate-box {
    padding: 1.8rem 1.2rem;
    margin: 0.75rem;
  }
  .gate-tab {
    font-size: 0.72rem;
    padding: 0.55rem;
  }
  .video-gen-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
  }
  .music-selector {
    gap: 0.4rem;
  }
  .music-chip {
    font-size: 0.68rem;
    padding: 0.3rem 0.65rem;
  }
}

/* ── 11. LOGIN.HTML ───────────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .login-wrapper {
    padding: 1rem;
    max-width: none;
  }
  .brand-icon {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
  }
  .brand-name {
    font-size: 1.4rem;
  }
  .card-body {
    padding: 1.5rem 1.2rem !important;
  }
  .card-header {
    padding: 1.1rem 1.2rem !important;
  }
}

/* ── 12. Maintenance & Legal ──────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .card {
    padding: 2rem 1.25rem !important;
    border-radius: 16px !important;
  }
  header {
    padding: 2rem 1rem 1.8rem !important;
  }
  main {
    padding: 1.5rem 1rem 2.5rem !important;
  }
}

/* ── 13. Utilities ────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .d-flex.gap-2.flex-wrap {
    gap: 0.5rem !important;
  }
  .btn-action {
    padding: 0.35rem 0.6rem;
    font-size: 0.68rem;
  }
  .period-pill, .mv-tab {
    padding: 0.28rem 0.65rem;
    font-size: 0.7rem;
  }
  /* Ensure tables don't break layout */
  .table-responsive {
    border-radius: 10px;
  }
  /* Pagination / controls stack */
  .table-head .d-flex {
    width: 100%;
  }
}

/* ── 14. Print / reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── 15. Fix for iOS 100vh ────────────────────────────────────────────── */
@supports (-webkit-touch-callout: none) {
  .sidebar {
    height: -webkit-fill-available;
    max-height: -webkit-fill-available;
  }
}

/* ── 16. Ensure modals are scrollable on small screens ────────────────── */
@media (max-width: 767.98px) {
  .modal-dialog-scrollable .modal-content {
    max-height: 92vh;
  }
  .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── 17. Orbit wall responsive tweaks ─────────────────────────────────── */
@media (max-width: 575.98px) {
  .orbit-ring-line {
    opacity: 0.6;
  }
  .orbit-photo, .orbit-initial {
    border-width: 1.5px;
  }
}

/* ── 18. Superadmin nav groups on mobile ──────────────────────────────── */
@media (max-width: 991.98px) {
  .nav-group-head {
    padding: 0.5rem 1rem 0.4rem;
  }
  .nav-item-s {
    padding: 0.55rem 1rem 0.55rem 1.8rem;
    font-size: 0.8rem;
  }
  .nav-single {
    padding-left: 1rem !important;
  }
}

/* ── 19. Ensure no horizontal scroll from absolute elements ───────────── */
@media (max-width: 767.98px) {
  .hero::before,
  .hero-cross,
  .orbit-stage {
    max-width: 100vw;
    overflow: hidden;
  }
}
