/* ============================================================
   Pet Registration and Health Management System
   RESPONSIVE LAYER — phones & tablets (admin + pet-owner side)

   Loaded LAST on every page so it can safely override the older
   desktop rules.  Nothing here changes the desktop layout
   (everything is inside max-width media queries) except tiny
   safety nets that are invisible on large screens.

   Breakpoints
     <= 900px   sidebar becomes a slide-in drawer (hamburger button)
     <= 640px   tables become stacked cards, tighter spacing
     <= 400px   extra-small phones (iPhone SE, Galaxy Fold, etc.)

   Works together with assets/mobile-nav.js
   ============================================================ */

/* ---------- Safety nets (all sizes) ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video, canvas { max-width: 100%; }
img { height: auto; }
/* Hamburger button + overlay exist in the DOM on every size, but are only shown on small screens */
.mnav-toggle { display: none; }
.mnav-overlay { display: none; }

/* Horizontal scroll wrapper added by mobile-nav.js around tables */
.rt-scroll { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   <= 900px  — TABLETS & PHONES
   ============================================================ */
@media (max-width: 900px) {

    html { overflow-x: hidden; }
    body { overflow-x: clip; max-width: 100%; }
    body.mnav-open { overflow: hidden; }

    /* ---- page shell: content always takes the full width ---- */
    .dashboard-layout,
    .client-layout { flex-direction: row; display: flex; width: 100%; max-width: 100%; }
    .main-content,
    .client-body { width: 100%; max-width: 100%; min-width: 0; flex: 1 1 auto; overflow-x: hidden; }
    .main-content { padding: 18px 16px 28px; }
    .client-main  { padding: 18px 16px 28px; }

    /* ---- background art: iOS ignores "fixed" backgrounds, so scale it to the page ---- */
    body {
        background-attachment: scroll;
        background-size: 100% auto;
        background-position: right bottom;
    }

    /* ---- SIDEBARS → slide-in drawer ---- */
    .sidebar,
    .client-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(290px, 84vw);
        min-width: 0;
        max-width: 84vw;
        height: 100vh;
        height: 100dvh;
        flex: none;
        align-self: auto;
        z-index: 1200;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;

        /* undo the old "sidebar on top as a row" layout */
        flex-direction: column;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        padding: 26px 14px 22px;

        /* hidden until the hamburger is tapped */
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform .28s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .28s;
    }
    .sidebar { display: block; }
    .client-sidebar { display: flex; }
    .client-sidebar .sidebar-logo-wrap { flex-direction: column; }
    .client-sidebar .sidebar-nav,
    .sidebar .sidebar-nav { flex-direction: column; flex-wrap: nowrap; flex: 1 1 auto; width: 100%; }
    .client-sidebar .sidebar-logout { margin-top: auto; padding-top: 14px; width: 100%; }

    body.mnav-open .sidebar,
    body.mnav-open .client-sidebar {
        transform: none;
        visibility: visible;
        transition-delay: 0s;
        box-shadow: 10px 0 36px rgba(0, 0, 0, .35);
    }

    /* dark backdrop behind the open drawer */
    .mnav-overlay {
        display: block;
        position: fixed; inset: 0;
        background: rgba(24, 40, 14, .55);
        -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
        opacity: 0; pointer-events: none;
        transition: opacity .25s ease;
        z-index: 1100;
    }
    body.mnav-open .mnav-overlay { opacity: 1; pointer-events: auto; }

    /* ---- hamburger button (injected into the top bar) ---- */
    .mnav-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        flex: 0 0 auto;
        width: 42px; height: 42px;
        margin-right: 2px;
        padding: 0;
        border: 0; border-radius: 12px;
        background: #4d6b2f; color: #fff;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
    }
    .mnav-toggle:active { transform: scale(.95); }
    .mnav-toggle:focus-visible { outline: 3px solid #CFE1B9; outline-offset: 2px; }
    .mnav-toggle svg { width: 22px; height: 22px; display: block; }
    .mnav-toggle.mnav-floating { position: fixed; top: 10px; left: 10px; z-index: 1000; }

    /* ---- TOP BARS ---- */
    .topbar {
        position: relative;
        display: flex; align-items: center;
        flex-wrap: wrap;                       /* action buttons drop under the title if space runs out */
        justify-content: flex-start;
        gap: 10px;
        margin-bottom: 18px;
    }
    .topbar > h1,
    .topbar > div:not([style]) { flex: 1 1 130px; min-width: 0; }
    .topbar h1 { font-size: 19px; line-height: 1.25; overflow-wrap: anywhere; }
    .topbar > div:not([style]) p { font-size: 12px !important; line-height: 1.35; }
    .topbar > .ab-group,
    .topbar > div[style*="flex"] {
        flex: 0 1 auto; margin-left: auto; max-width: 100%;
        flex-wrap: wrap; justify-content: flex-end;
    }
    .topbar .ab-group { gap: 8px; }
    .btn-my-profile { padding: 8px 13px; font-size: 12.5px; }
    .btn-back-records, .btn-print { padding: 8px 13px; font-size: 12.5px; white-space: nowrap; }

    .client-topbar {
        justify-content: flex-start;
        padding: 10px 14px;
        gap: 10px;
    }
    .topbar-title {
        flex: 1 1 0; min-width: 0;
        font-size: 17px; line-height: 1.25;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .topbar-right { flex: 0 0 auto; gap: 10px; }

    /* ---- notification panels: span the top bar so they never fall off-screen ----
       (selectors are deliberately more specific than admin_bell.css, which the
        admin top-bar include loads later, inside <body>)                        */
    .ab-group .ab-wrap,
    .topbar-right .notif-wrapper { position: static; }
    .ab-group .ab-wrap .ab-panel,
    .topbar-right .notif-wrapper .notif-dropdown,
    .topbar-right .notif-wrapper .notif-panel {
        position: absolute;
        left: 8px; right: 8px;
        top: calc(100% + 6px);
        width: auto; max-width: none;
    }

    /* ---- grids that were still multi-column ---- */
    .dashboard-grid, .dash-brgy-grid, .dec-top-grid, .notif-page-grid,
    .ap-layout, .ap-grid, .op-layout, .op-hero, .gr-layout, .gr-petgrid { grid-template-columns: minmax(0, 1fr); }
    .dashboard-grid > *, .dash-brgy-grid > *, .dec-top-grid > *, .notif-page-grid > *,
    .ap-layout > *, .op-layout > *, .op-hero > *, .gr-layout > * { min-width: 0; }

    /* ---- forms ---- */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
    select, textarea { font-size: 16px; max-width: 100%; }   /* 16px stops iOS from zooming on focus */
    .form-row { flex-direction: column; gap: 0; }
    .search-form, .vn-filters, .filter-bar, .filters { flex-wrap: wrap; }
    .vn-filters input, .vn-filters select { min-width: 0; flex: 1 1 140px; }

    /* ---- floating "archived pets" bin: smaller so it never covers content ---- */
    .trash-bin-wrap { bottom: 16px; right: 14px; }
    .trash-bin-fab, .trash-bin-wrap .trash-bin-fab { width: 54px; height: 54px; font-size: 24px; }
    .trash-bin-label { font-size: 10px; }
}

/* ============================================================
   <= 640px  — PHONES
   ============================================================ */
@media (max-width: 640px) {

    .main-content { padding: 14px 12px 26px; }
    .client-main  { padding: 14px 12px 26px; }
    .client-topbar { padding: 9px 12px; }

    .panel, .panel-card { padding: 14px; border-radius: 14px; }
    .panel h2 { font-size: 15px; margin-bottom: 12px; }

    /* ---- summary cards: two across, compact ---- */
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
    .summary-card { padding: 12px; gap: 10px; border-radius: 14px; }
    .sc-icon { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; }
    .sc-icon svg, .sc-icon img { width: 22px; height: 22px; }
    .sc-label { font-size: 10.5px; letter-spacing: .2px; overflow-wrap: anywhere; }
    .sc-value { font-size: 26px; }
    .sc-desc  { font-size: 11px; }
    .summary-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }

    .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card  { padding: 14px; }
    .stat-value { font-size: 24px; }

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

    /* ---- every two-column form grid → one column ---- */
    .ep-grid, .vp-grid, .rpa-grid, .vu-grid, .vacc-form-grid, .nf-row,
    .op-form-grid, .reg-grid, .vacc-summary-grid, .mp-grid { grid-template-columns: minmax(0, 1fr); }
    .op-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .gr-box dt { width: 100px; }

    /* ---- My Pets record cards: columns that were 260px wide minimum ---- */
    .mpr-sections { grid-template-columns: minmax(0, 1fr); }
    .mpr-title { min-width: 0; }
    .mpr-card { padding: 16px; }
    .mpr-title h3 { font-size: 21px; }

    /* ---- buttons that sat side by side wrap instead of overflowing ---- */
    .deceased-btns, .btn-row, .form-actions, .actions { flex-wrap: wrap; }

    /* ---- login / signup / verify cards ---- */
    .login-wrapper { padding: 14px; }
    .login-card, .form-card, .species-card { width: 100%; max-width: 100%; padding-left: 20px; padding-right: 20px; }
    .species-options { gap: 10px; }
    .species-btn { padding: 20px 8px; }
    .welcome-card { padding: 34px 22px; }

    /* ============================================================
       TABLES → STACKED CARDS  (classes/labels added by mobile-nav.js)
       ============================================================ */
    table.rt-stack,
    table.rt-stack tbody { display: block; width: 100%; min-width: 0; }
    table.rt-stack thead { /* hidden visually, still readable by screen readers */
        position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
        overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap;
    }
    table.rt-stack tr {
        display: block;
        margin: 0 0 12px;
        padding: 8px 12px;
        background: #fff;
        border: 1px solid #dbe6cc;
        border-left: 4px solid #88976C;
        border-radius: 12px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
    }
    table.rt-stack tr:hover { background: #fff; }
    table.rt-stack td {
        display: grid;
        grid-template-columns: minmax(86px, 38%) minmax(0, 1fr);
        column-gap: 10px;
        align-items: start;
        width: auto;
        padding: 7px 0;
        border: 0;
        border-bottom: 1px dashed #e1ebd4;
        text-align: left;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 13.5px;
    }
    table.rt-stack td:last-child { border-bottom: 0; }
    table.rt-stack td::before {
        content: attr(data-label);
        font-size: 11px; font-weight: 700; line-height: 1.5;
        color: #728156;
        text-transform: uppercase; letter-spacing: .3px;
    }
    table.rt-stack td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
    table.rt-stack td[data-label=""]::before { display: none; }
    /* "No records found" rows */
    table.rt-stack td[colspan] { display: block; text-align: center; padding: 14px 4px; }
    table.rt-stack td[colspan]::before { display: none; }
    /* button / link groups inside a cell stay together and wrap */
    table.rt-stack td .actions, table.rt-stack td form { display: flex; flex-wrap: wrap; gap: 6px; }
    table.rt-stack td img { max-width: 100%; }
    table.rt-stack td > * { min-width: 0; }
    .rt-scroll:has(> table.rt-stack) { overflow: visible; }
}

/* ============================================================
   <= 400px  — SMALL PHONES (iPhone SE, Galaxy Fold, 360px Androids)
   ============================================================ */
@media (max-width: 400px) {
    .main-content { padding: 12px 10px 24px; }
    .client-main  { padding: 12px 10px 24px; }
    .topbar h1 { font-size: 17px; }
    .topbar-owner { display: none; }          /* greeting hidden, name is still in the menu */
    .btn-my-profile { padding: 7px 10px; font-size: 12px; }
    .mnav-toggle { width: 40px; height: 40px; }

    .summary-card { flex-direction: column; align-items: flex-start; gap: 6px; }
    .sc-value { font-size: 24px; }

    .panel, .panel-card { padding: 12px; }
    table.rt-stack td { grid-template-columns: minmax(78px, 40%) minmax(0, 1fr); font-size: 13px; }
}

@media (max-width: 340px) {
    .summary-grid, .stat-cards, .vn-cards { grid-template-columns: minmax(0, 1fr); }
    .login-card, .form-card, .species-card { padding-left: 14px; padding-right: 14px; }
}

/* ---- phone in landscape: keep the drawer scrollable and compact ---- */
@media (max-width: 900px) and (max-height: 480px) {
    .sidebar, .client-sidebar { padding-top: 14px; }
    .sidebar h3 { margin-bottom: 14px; }
}

/* ---- respect users who turn animations off ---- */
@media (prefers-reduced-motion: reduce) {
    .sidebar, .client-sidebar, .mnav-overlay { transition: none; }
}

/* ---------- Header bar on phones/tablets: compact, title + bell stay on one row ---------- */
@media (max-width: 900px) {
    .topbar { padding: 10px 12px; margin-bottom: 16px; border-radius: 12px; }
    .topbar > h1 { flex: 1 1 100px; }
}
