/**
 * ZepMed panels — responsive layout + universal sidebar drawer toggle.
 * Works with sidebar-toggle.js (html.zm-nav-open) on admin, seller, delivery, etc.
 */

html, body.zepmed-app {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.layout {
    width: 100%;
    max-width: 100vw;
    min-height: 100vh;
    display: block !important;
}

/* ── Hamburger: always visible on every panel ─────────────────────────────── */
.sidebar-hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    border: 2px solid rgba(13, 148, 136, 0.45);
    border-radius: var(--zm-radius-sm, 8px);
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: #0f766e;
    flex-shrink: 0;
    margin-right: 10px;
    box-shadow: var(--zm-shadow-sm, 0 1px 3px rgba(0,0,0,0.06));
    z-index: 450;
}
.sidebar-hamburger-icon {
    font-size: 20px;
    line-height: 1;
}
.sidebar-hamburger-label {
    font-size: 12px;
    letter-spacing: 0.06em;
}
.sidebar-hamburger:hover,
.sidebar-hamburger:focus-visible {
    border-color: var(--zm-teal, #0d9488);
    color: var(--zm-teal-dark, #0f766e);
    outline: none;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
}
.topbar > div:first-of-type {
    flex: 1;
    min-width: 0;
}

/* ── Sidebar drawer (all breakpoints) ────────────────────────────────────── */
.sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh !important;
    width: var(--zm-sidebar-width, 260px);
    max-width: min(88vw, 320px);
    z-index: 400;
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
html.zm-nav-open .sidebar,
.sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.28);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 399;
    cursor: pointer;
}
html.zm-nav-open .sidebar-backdrop.visible,
.sidebar-backdrop.visible {
    display: block;
}

/* Content uses full width when nav closed */
.content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-left: 0 !important;
    padding: clamp(12px, 2.5vw, 28px);
    box-sizing: border-box;
}

/* Desktop: optional pinned sidebar (more screen space when open) */
@media (min-width: 1100px) {
    html.zm-nav-pinned.zm-nav-open .content {
        margin-left: var(--zm-sidebar-width, 260px) !important;
        width: calc(100% - var(--zm-sidebar-width, 260px));
    }
    html.zm-nav-pinned.zm-nav-open .sidebar-backdrop.visible {
        display: none !important;
    }
}

/* ── Responsive grids & cards ────────────────────────────────────────────── */
.stat-grid,
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
    gap: clamp(10px, 2vw, 16px);
}

.card-panel,
.module {
    max-width: 100%;
    overflow-x: auto;
}

.table-responsive,
.card-panel .table,
.module .table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.row {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
}
.row > [class*="col-"] {
    min-width: 0;
}

/* Forms & modals */
.panel-modal-card {
    max-width: min(96vw, 720px);
    max-height: 90vh;
    overflow-y: auto;
}
.panel-modal-card.wide {
    max-width: min(96vw, 960px);
}

/* Topbar actions wrap on small screens */
.topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* TV / small height screens */
html.zepmed-tv-mode .sidebar,
html.zm-nav-open.zepmed-tv-mode .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.35);
}

html.zepmed-tv-mode .sidebar-hamburger {
    position: relative;
    background: #0d9488;
    color: #fff;
    border-color: #0f766e;
    min-width: 110px;
}

html.zepmed-tv-mode .content {
    margin-left: var(--zm-sidebar-width, 260px) !important;
    width: calc(100% - var(--zm-sidebar-width, 260px));
}

html.zepmed-tv-mode .sidebar-backdrop.visible {
    display: none !important;
}

.zm-tv-hint {
    background: linear-gradient(90deg, #0f766e, #6366f1);
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 14px;
    line-height: 1.45;
}
.zm-tv-hint kbd {
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}
html.zepmed-tv-mode .zm-tv-hint {
    display: block !important;
}

html.zepmed-tv-mode #loginModal {
    z-index: 5000 !important;
}
html.zepmed-tv-mode #loginModal:not(.d-none) ~ .layout,
html.zepmed-tv-mode body.app-locked .layout {
    filter: none;
    pointer-events: none;
}

html.zepmed-tv-mode .panel-modal-card {
    max-width: min(92vw, 520px);
    font-size: 16px;
}

html.zepmed-tv-mode .panel-modal-card .form-control {
    font-size: 18px !important;
    min-height: 48px;
}

html.zepmed-tv-mode #loginBtn {
    min-height: 52px;
    font-size: 18px !important;
}
html.zepmed-tv-mode .stat-grid,
html.zepmed-tv-mode .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
}

@media (max-width: 768px) {
    .topbar h2 {
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }
    .menu-btn {
        padding: 12px 14px;
        font-size: 14px;
    }
    .btn, .btn-teal, .btn-outline-teal, .btn-primary {
        min-height: 40px;
    }
    .filter-pill {
        font-size: 12px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 12px;
    }
    .topbar-actions .btn,
    .topbar-actions .btn-teal {
        font-size: 12px;
        padding: 6px 10px;
    }
}
