/* ================================================================
   Page chrome — shared app-header, hamburger button, and rules that
   hide the legacy CI3 sidebar/topbar across every page that loads
   common/top.php.

   common/top.php auto-applies `body.dashboard-fullscreen` via inline
   JS, so these rules take effect on every legacy page without any
   per-page edits.
   ================================================================ */

:root {
    --pc-brand: #2563eb;
    --pc-brand-dark: #1d4ed8;
    --pc-success: #00c292;
    --pc-success-dark: #00a87f;
    --pc-text: #0f172a;
    --pc-text-muted: #64748b;
    --pc-text-soft: #94a3b8;
    --pc-border: #e5e7eb;
    --pc-bg: #f8fafc;
    --pc-card: #ffffff;
    --pc-header-h: 52px;
}

/* ---------- Hide legacy CI3 chrome ---------- */
body.dashboard-fullscreen .header,
body.dashboard-fullscreen header.header,
body.dashboard-fullscreen .menu,
body.dashboard-fullscreen .menu-content,
body.dashboard-fullscreen .menu-footer,
body.dashboard-fullscreen .menu-shopping-cart,
body.dashboard-fullscreen .menu-bar,
body.dashboard-fullscreen nav.page-sidebar,
body.dashboard-fullscreen .page-sidebar,
body.dashboard-fullscreen .header-search,
body.dashboard-fullscreen .header-tray,
body.dashboard-fullscreen .quickview-wrapper,
body.dashboard-fullscreen .quickview-link {
    display: none !important;
}

/* ---------- Hide duplicate inline breadcrumbs ----------
   common/top.php renders the canonical breadcrumb in `.app-header .crumbs`.
   Many legacy views still emit their own `<ol class="breadcrumb breadcrumb-alt">`
   block wrapped in `<div class="bg-white">…</div>`. Hide only the navigation
   breadcrumbs (those whose <li> children carry the `.breadcrumb-item` class).

   IMPORTANT: some pages reuse `<ol class="breadcrumb-alt">` as a quick toolbar
   for action buttons (e.g. appointments/index.php Table/Calendar switcher).
   Those don't use `.breadcrumb-item` on their <li>s, so the `:has` selector
   leaves them visible — and the surrounding `.bg-white` wrapper is kept too. */
body.dashboard-fullscreen ol.breadcrumb-alt:has(> li.breadcrumb-item),
body.dashboard-fullscreen .breadcrumb.breadcrumb-alt:has(> li.breadcrumb-item) {
    display: none !important;
}
/* Empty `.bg-white` wrapper collapses naturally because `.container` has only
   horizontal padding. No wrapper-hide rule needed. */

body.dashboard-fullscreen,
body.dashboard-fullscreen.fixed-header,
body.dashboard-fullscreen .page-container,
body.dashboard-fullscreen .page-container .page-content-wrapper,
body.dashboard-fullscreen .page-container .page-content-wrapper .content,
body.dashboard-fullscreen .page-container .page-content-wrapper .content.sm-gutter {
    padding: 0 !important;
    margin: 0 !important;
}
body.dashboard-fullscreen .page-container { padding-left: 0 !important; }

/* Footer copyright bar — hidden, but the partial still renders so the
   shared modals (#app_modal, #taskModal, etc.) remain available */
body.dashboard-fullscreen .container.footer { display: none !important; }

/* ---------- App header ----------
   Fixed on desktop / tablet (≥ 721 px) so brand + nav stay reachable while
   the page scrolls. On mobile (≤ 720 px) we drop the fixed positioning —
   phones have less vertical real estate, and pinning ~52 px of chrome eats
   the visible card area. The mobile rules at the bottom of this file
   override `position` to `static`. */
body.dashboard-fullscreen .app-header {
    background: var(--pc-card);
    border-bottom: 1px solid var(--pc-border);
    padding: 0 24px;
    height: var(--pc-header-h);
    display: flex;
    align-items: center;
    gap: 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
/* Reserve space below the fixed header for in-flow page content */
body.dashboard-fullscreen .page-container {
    padding-top: var(--pc-header-h) !important;
}
body.dashboard-fullscreen .app-header .brand {
    font-size: 15px;
    font-weight: 800;
    color: var(--pc-brand);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    text-decoration: none;
}
body.dashboard-fullscreen .app-header .brand-logo {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--pc-brand), var(--pc-brand-dark));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 14px;
}
body.dashboard-fullscreen .app-header .crumbs {
    color: var(--pc-text-muted);
    font-size: 12px;
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.dashboard-fullscreen .app-header .crumbs a { color: var(--pc-text-muted); text-decoration: none; }
body.dashboard-fullscreen .app-header .crumbs a:hover { color: var(--pc-brand); }
body.dashboard-fullscreen .app-header .crumbs strong { color: var(--pc-text); font-weight: 700; }
body.dashboard-fullscreen .app-header .crumbs .sep { margin: 0 6px; color: var(--pc-text-soft); }
body.dashboard-fullscreen .app-header .header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ---------- Action buttons (New Appointment, Walk-in) ---------- */
body.dashboard-fullscreen .app-header .btn-new-apt {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: var(--pc-brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .2s, transform .2s, box-shadow .2s;
    white-space: nowrap;
}
body.dashboard-fullscreen .app-header .btn-new-apt:hover {
    background: var(--pc-brand-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    color: #fff;
}
body.dashboard-fullscreen .app-header .btn-new-apt .material-icons { font-size: 16px; }
body.dashboard-fullscreen .app-header .btn-new-apt.walkin { background: var(--pc-success); }
body.dashboard-fullscreen .app-header .btn-new-apt.walkin:hover {
    background: var(--pc-success-dark);
    box-shadow: 0 4px 12px rgba(0, 194, 146, 0.25);
}

/* ---------- Hamburger button ---------- */
body.dashboard-fullscreen .dash-menu-trigger {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--pc-card);
    border: 1px solid var(--pc-border);
    color: #475569;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
body.dashboard-fullscreen .dash-menu-trigger:hover,
body.dashboard-fullscreen .dash-menu-trigger.active {
    background: #f1f5f9;
    color: var(--pc-brand);
    border-color: #cbd5e1;
}
body.dashboard-fullscreen .dash-menu-trigger .material-icons { font-size: 20px; }

/* Shared icon button in the header actions row (search, etc.) — matches
   the menu-trigger circle so a row of icon buttons reads as a set. */
body.dashboard-fullscreen .header-icon-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--pc-card);
    border: 1px solid var(--pc-border);
    color: #475569;
    text-decoration: none;
    transition: background .15s, color .15s, border-color .15s;
}
body.dashboard-fullscreen .header-icon-btn:hover,
body.dashboard-fullscreen .header-icon-btn:focus-visible {
    background: #f1f5f9;
    color: var(--pc-brand);
    border-color: #cbd5e1;
    outline: none;
}
body.dashboard-fullscreen .header-icon-btn .material-icons { font-size: 20px; }

/* ================================================================
   App-level alert / confirm modal
   Drop-in replacement for window.alert / window.confirm — invoked via
   appAlert(msg) / appConfirm(msg). Promise-based.
   ================================================================ */
.app-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s ease, visibility .18s ease;
}
.app-modal-overlay.show { opacity: 1; visibility: visible; }

.app-modal {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -46%);
    width: min(440px, 92vw);
    background: #fff;
    color: #0f172a;
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s ease, visibility .18s ease, transform .2s ease;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
.app-modal.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%);
}

.app-modal-body {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 22px 22px 8px;
}
.app-modal-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.app-modal-icon .material-icons { font-size: 24px; }
.app-modal--info    .app-modal-icon { background: rgba(1, 80, 255, 0.10);  color: #0150ff; }
.app-modal--success .app-modal-icon { background: rgba(0, 194, 146, 0.12); color: #047857; }
.app-modal--warning .app-modal-icon { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.app-modal--danger  .app-modal-icon { background: rgba(224, 49, 49, 0.12);  color: #b91c1c; }

.app-modal-text { flex: 1; min-width: 0; }
.app-modal-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 4px;
    letter-spacing: -0.2px;
    color: #0f172a;
}
.app-modal-message {
    font-size: 13.5px;
    line-height: 1.5;
    color: rgba(15, 23, 42, 0.7);
    white-space: pre-line;
}

.app-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 22px 18px;
}
.app-modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid rgba(15, 23, 42, 0.14);
    background: #fff;
    color: #0f172a;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .15s, box-shadow .15s;
    font-family: inherit;
    min-width: 90px;
}
.app-modal-btn:hover { background: #f1f5f9; border-color: rgba(15, 23, 42, 0.2); }
.app-modal-btn--primary {
    background: #0150ff;
    border-color: #0150ff;
    color: #fff;
}
.app-modal-btn--primary:hover {
    background: #0040d8;
    border-color: #0040d8;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(1, 80, 255, 0.25);
}
.app-modal-btn--danger {
    background: #e03131;
    border-color: #e03131;
    color: #fff;
}
.app-modal-btn--danger:hover {
    background: #c92424;
    border-color: #c92424;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(224, 49, 49, 0.25);
}

/* ─────────────────────────────────────────────────────────────────
   GLOBAL MOBILE TOP-BAR POLISH
   Safe-area handling, tap feedback, hover gating, and touch-target
   sizing applied to every page that loads common/top.php (i.e. has
   `body.dashboard-fullscreen`). Mirrors the appointments-view-app
   mobile audit so the chrome is consistent EMR-wide.
   ───────────────────────────────────────────────────────────────── */

/* Honor reduced-motion system preference */
@media (prefers-reduced-motion: reduce) {
    body.dashboard-fullscreen .app-header *,
    body.dashboard-fullscreen .menu-drawer *,
    body.dashboard-fullscreen .menu-drawer-overlay {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* Hover-only effects: keep them off touch devices so taps don't leave
   buttons stuck in their hover state on iOS. */
@media (hover: none) or (pointer: coarse) {
    body.dashboard-fullscreen .app-header .btn-new-apt:hover,
    body.dashboard-fullscreen .app-header .view-switch-btn:hover,
    body.dashboard-fullscreen .dash-menu-trigger:hover {
        transform: none;
        box-shadow: none;
    }
}

/* Tap feedback for touch — a quick scale-down confirms the tap
   registered, since there's no hover state on touch devices. */
body.dashboard-fullscreen .app-header .btn-new-apt:active,
body.dashboard-fullscreen .app-header .view-switch-btn:active,
body.dashboard-fullscreen .dash-menu-trigger:active {
    transform: scale(0.97);
}

/* Safe-area handling (iPhone notch + home indicator). The viewport
   meta uses `viewport-fit=cover`; we honour env() insets so fixed
   chrome doesn't get clipped behind the notch. */
body.dashboard-fullscreen .app-header {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--header-h, 52px) + env(safe-area-inset-top, 0));
}
body.dashboard-fullscreen .menu-drawer {
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ---------- Mobile (≤ 720px): simplify the bar ---------- */
@media (max-width: 720px) {
    /* Header scrolls with the content on phones — no fixed pinning. */
    body.dashboard-fullscreen .app-header {
        position: static;
        top: auto; left: auto; right: auto;
        height: var(--pc-header-h);
        padding: 0 12px;
        gap: 8px;
    }
    /* Drop the placeholder space we reserved on desktop — the header is in
       the document flow on phones, so the page-container starts at top:0. */
    body.dashboard-fullscreen .page-container {
        padding-top: 0;
    }
    body.dashboard-fullscreen .app-header .crumbs { display: none; }

    /* Brand pinned left, actions pinned right. The crumbs `flex:1` was
       what previously pushed the action group to the right; with crumbs
       hidden on mobile we use margin-left:auto on header-actions to
       reclaim that behaviour. */
    body.dashboard-fullscreen .app-header .brand { margin-right: 0; }
    body.dashboard-fullscreen .app-header .header-actions { margin-left: auto; }

    /* Brand keeps its logo + wordmark on mobile so identity is consistent
       across every page. The action group (right side) collapses its
       button labels instead to keep the row compact. */
    body.dashboard-fullscreen .app-header .brand {
        font-size: 15px;
        gap: 8px;
        flex-shrink: 0;
    }
    body.dashboard-fullscreen .app-header .brand-logo {
        width: 32px; height: 32px; font-size: 14px;
    }

    /* New Appointment / Walk-in shrink to icon-only at this width to
       free space for the hamburger + view-switch. The full label is
       still announced to screen readers via aria-label on the link. */
    body.dashboard-fullscreen .app-header .btn-new-apt span:not(.material-icons) { display: none; }
    body.dashboard-fullscreen .app-header .btn-new-apt {
        padding: 0;
        width: 40px; height: 40px;
        justify-content: center;
        min-width: 40px; min-height: 40px;
    }

    /* Touch targets ≥ 40–44px for every interactive control in the bar */
    body.dashboard-fullscreen .app-header .view-switch-btn,
    body.dashboard-fullscreen .dash-menu-trigger {
        min-width: 44px; min-height: 44px;
    }

    /* Prevent iOS Safari auto-zoom-on-focus by forcing 16px font on any
       form controls embedded in the chrome (rare, but covers any
       inline searches a page might add). */
    body.dashboard-fullscreen .app-header input,
    body.dashboard-fullscreen .app-header select { font-size: 16px; }

    /* Use dynamic-viewport units where supported so the iOS URL bar
       collapse doesn't shift the menu drawer. */
    @supports (height: 100dvh) {
        body.dashboard-fullscreen .menu-drawer { height: 100dvh; }
    }
}

/* Even-tighter screens (≤ 380px) — drop the view-switch from the
   header to reclaim space; the same toggle still exists on the
   appointments page filter bar. */
@media (max-width: 380px) {
    body.dashboard-fullscreen .app-header .view-switch { display: none; }
}
