/**
 * SightOps Presentation Framework v1.0.0
 * Loaded after design-tokens.css. Desktop shell (style.css) unchanged at ≥1024px.
 */

:root {
    --pf-transition-drawer: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --pf-transition-sheet: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --pf-bottom-nav-height: 3.75rem;
    --pf-app-bar-height: 3.25rem;
    --pf-fab-size: 3.5rem;
    --pf-card-padding: 1rem;
    --pf-card-radius: var(--radius-md, 12px);
    --pf-skeleton-base: #e8edf2;
    --pf-skeleton-shine: #f4f7fa;
}

/* ——— Drawer ——— */
.pf-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: var(--z-backdrop, 999);
}
.pf-drawer-backdrop--visible,
.pf-drawer.open + .pf-drawer-backdrop,
.sidebar.open + .sidebar-backdrop {
    display: block;
}
.pf-drawer,
.viewport-mobile .sidebar,
.viewport-tablet .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    width: min(100vw, 320px);
    z-index: var(--z-sidebar, 1000);
    transform: translateX(-100%);
    transition: transform var(--pf-transition-drawer);
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--sidebar-bg, #0f172a);
    color: #fff;
}
.pf-drawer--open,
.pf-drawer.open,
.viewport-mobile .sidebar.open,
.viewport-tablet .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
}
.pf-drawer__panel {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
}
.pf-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md, 1.25rem);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.pf-drawer__title {
    margin: 0;
    font-size: var(--text-lg, 1.125rem);
    font-weight: 600;
}
.pf-drawer__close {
    min-width: var(--tap-target-min, 2.75rem);
    min-height: var(--tap-target-min, 2.75rem);
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    border-radius: var(--radius-sm, 10px);
    cursor: pointer;
}
.pf-drawer__nav {
    flex: 1;
    padding: var(--spacing-sm, 0.75rem);
    overflow-y: auto;
}
.pf-drawer__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    min-height: var(--tap-target-min, 2.75rem);
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-sm, 10px);
}
.pf-drawer__item:hover {
    background: var(--sidebar-hover, rgba(255, 255, 255, 0.06));
}
body.pf-drawer-open {
    overflow: hidden;
}

/* ——— Bottom navigation ——— */
.pf-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky-topbar, 120);
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: var(--pf-bottom-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--surface-elevated, #fff);
    border-top: 1px solid var(--border-color, #e8edf2);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
}
.pf-bottom-nav__item {
    flex: 1;
    max-width: 20%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: var(--tap-target-min, 2.75rem);
    color: var(--text-secondary, #64748b);
    text-decoration: none;
    font-size: var(--text-xs, 0.75rem);
    font-weight: 500;
}
.pf-bottom-nav__item--active {
    color: var(--primary-color, #14b8a6);
}
.pf-bottom-nav__icon {
    position: relative;
    font-size: 1.25rem;
    line-height: 1;
}
.pf-bottom-nav__badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.25rem;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1rem;
    text-align: center;
    color: #fff;
    background: var(--danger-color, #ef4444);
    border-radius: var(--radius-pill, 999px);
}
.pf-has-bottom-nav .page-content,
.pf-has-bottom-nav .main-content {
    padding-bottom: calc(var(--pf-bottom-nav-height) + env(safe-area-inset-bottom, 0) + 0.5rem);
}

/* ——— App bar ——— */
.pf-app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--pf-app-bar-height);
    padding: 0.5rem var(--spacing-md, 1.25rem);
    background: var(--surface-elevated, #fff);
    border-bottom: 1px solid var(--border-color, #e8edf2);
}
.pf-app-bar__start {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}
.pf-app-bar__menu {
    flex-shrink: 0;
    min-width: var(--tap-target-min, 2.75rem);
    min-height: var(--tap-target-min, 2.75rem);
    border: none;
    background: transparent;
    color: var(--text-primary, #1e293b);
    border-radius: var(--radius-sm, 10px);
    cursor: pointer;
}
.pf-app-bar__titles {
    min-width: 0;
}
.pf-app-bar__title {
    margin: 0;
    font-size: var(--text-lg, 1.125rem);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pf-app-bar__subtitle {
    margin: 0;
    font-size: var(--text-xs, 0.75rem);
    color: var(--text-secondary, #64748b);
}
.pf-app-bar__end {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

/* ——— Search ——— */
.pf-search {
    width: 100%;
}
.pf-search__wrap {
    position: relative;
    display: block;
}
.pf-search__icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary, #64748b);
    pointer-events: none;
}
.pf-search__input {
    width: 100%;
    min-height: 3rem;
    padding-left: 2.5rem !important;
}

/* ——— FAB ——— */
.pf-fab-host {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--pf-bottom-nav-height) + env(safe-area-inset-bottom, 0) + 1rem);
    z-index: calc(var(--z-sticky-topbar, 120) + 1);
}
.pf-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: var(--pf-fab-size);
    min-height: var(--pf-fab-size);
    padding: 0 1.25rem;
    border: none;
    border-radius: var(--radius-pill, 999px);
    background: var(--primary-color, #14b8a6);
    color: #fff;
    font-weight: 600;
    font-size: var(--text-sm, 0.8125rem);
    box-shadow: var(--shadow-elevated);
    cursor: pointer;
    transition: transform var(--pf-transition-drawer), opacity var(--pf-transition-drawer);
}
.pf-fab:active {
    transform: scale(0.96);
}
.pf-fab__label {
    white-space: nowrap;
}

/* ——— Card ——— */
.pf-card {
    display: block;
    padding: var(--pf-card-padding);
    margin-bottom: 0.5rem;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e8edf2);
    border-radius: var(--pf-card-radius);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: background var(--transition-fast, 0.14s);
}
.pf-card:hover,
.pf-card:focus-visible {
    background: var(--table-row-hover, rgba(20, 184, 166, 0.06));
    outline: 2px solid var(--primary-color, #14b8a6);
    outline-offset: 2px;
}
.pf-card__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.pf-card__row--head {
    margin-bottom: 0.25rem;
}
.pf-card__primary {
    font-size: var(--text-base, 0.9375rem);
    font-weight: 600;
    color: var(--primary-color, #14b8a6);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pf-card__secondary,
.pf-card__meta,
.pf-card__status {
    font-size: var(--text-sm, 0.8125rem);
    color: var(--text-primary, #1e293b);
}
.pf-card__meta,
.pf-card__status {
    color: var(--text-secondary, #64748b);
    font-size: var(--text-xs, 0.75rem);
}
.pf-card__menu {
    flex-shrink: 0;
    min-width: var(--tap-target-min, 2.75rem);
    min-height: var(--tap-target-min, 2.75rem);
    border: none;
    background: transparent;
    color: var(--text-secondary, #64748b);
    border-radius: var(--radius-sm, 10px);
    cursor: pointer;
}
.pf-responsive-list--cards {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.pf-responsive-list__more {
    text-align: center;
    font-size: var(--text-sm, 0.8125rem);
    color: var(--text-secondary, #64748b);
    margin-top: 0.5rem;
}

/* ——— Empty state ——— */
.pf-empty {
    text-align: center;
    padding: var(--spacing-xl, 2.25rem) var(--spacing-md, 1.25rem);
}
.pf-empty__icon {
    font-size: 2.5rem;
    color: var(--text-secondary, #64748b);
    margin-bottom: 0.75rem;
    opacity: 0.7;
}
.pf-empty__title {
    margin: 0 0 0.35rem;
    font-size: var(--text-lg, 1.125rem);
}
.pf-empty__desc {
    margin: 0 0 1rem;
    color: var(--text-secondary, #64748b);
    font-size: var(--text-sm, 0.8125rem);
}
.pf-empty__actions .btn {
    min-height: 3rem;
}

/* ——— Feedback & skeletons ——— */
.pf-feedback-root {
    position: fixed;
    left: 50%;
    bottom: calc(var(--pf-bottom-nav-height) + env(safe-area-inset-bottom, 0) + 1rem);
    transform: translateX(-50%);
    z-index: var(--z-toast, 1100);
    width: min(92vw, 24rem);
    pointer-events: none;
}
.pf-feedback {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md, 12px);
    background: var(--surface-elevated, #fff);
    box-shadow: var(--shadow-elevated);
    pointer-events: auto;
    animation: pf-feedback-in 150ms var(--ease-out-soft, ease);
}
@keyframes pf-feedback-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.pf-feedback--success { border-left: 4px solid var(--success-color, #10b981); }
.pf-feedback--error { border-left: 4px solid var(--danger-color, #ef4444); }
.pf-feedback--warning { border-left: 4px solid var(--warning-color, #f59e0b); }
.pf-feedback--info { border-left: 4px solid var(--primary-color, #14b8a6); }
.pf-feedback__message {
    flex: 1;
    font-size: var(--text-sm, 0.8125rem);
}
.pf-feedback__action {
    border: none;
    background: transparent;
    color: var(--primary-color, #14b8a6);
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-target-min, 2.75rem);
    padding: 0 0.5rem;
}
.pf-skeleton {
    height: 0.75rem;
    border-radius: var(--radius-xs, 6px);
    background: linear-gradient(90deg, var(--pf-skeleton-base) 25%, var(--pf-skeleton-shine) 50%, var(--pf-skeleton-base) 75%);
    background-size: 200% 100%;
    animation: so-shimmer 1.2s ease-in-out infinite;
    margin-bottom: 0.5rem;
}
.pf-skeleton-card {
    padding: var(--pf-card-padding);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color, #e8edf2);
    border-radius: var(--pf-card-radius);
}

/* ——— Bottom sheet ——— */
.pf-bottom-sheet-host {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 1050);
    pointer-events: none;
}
.pf-bottom-sheet-host--visible {
    pointer-events: auto;
}
.pf-bottom-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0;
    transition: opacity var(--pf-transition-sheet);
}
.pf-bottom-sheet-host--visible .pf-bottom-sheet-backdrop {
    opacity: 1;
}
.pf-bottom-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    background: var(--surface-elevated, #fff);
    border-radius: var(--radius-lg, 14px) var(--radius-lg, 14px) 0 0;
    box-shadow: var(--shadow-elevated);
    transform: translateY(100%);
    transition: transform var(--pf-transition-sheet);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.pf-bottom-sheet-host--visible .pf-bottom-sheet {
    transform: translateY(0);
}
.pf-bottom-sheet__handle {
    width: 2.5rem;
    height: 0.25rem;
    margin: 0.5rem auto;
    background: var(--border-color, #e8edf2);
    border-radius: var(--radius-pill, 999px);
}
.pf-bottom-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem 0.5rem;
}
.pf-bottom-sheet__title {
    margin: 0;
    font-size: var(--text-lg, 1.125rem);
}
.pf-bottom-sheet__close {
    min-width: var(--tap-target-min, 2.75rem);
    min-height: var(--tap-target-min, 2.75rem);
    border: none;
    background: transparent;
    cursor: pointer;
}
.pf-bottom-sheet__body {
    flex: 1;
    overflow-y: auto;
    padding: 0 1rem 1rem;
}
.pf-bottom-sheet__footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--border-color, #e8edf2);
}
.pf-bottom-sheet__footer .btn {
    flex: 1;
    min-height: 3rem;
}
body.pf-bottom-sheet-open {
    overflow: hidden;
}

/* ——— Demo / mobile shell helpers ——— */
.pf-demo-shell {
    max-width: 28rem;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg-color, #f4f7fa);
}
.pf-demo-body {
    flex: 1;
    padding: var(--spacing-md, 1.25rem);
    overflow-x: hidden;
}
.pf-demo-section {
    margin-bottom: var(--spacing-lg, 1.75rem);
}
.pf-demo-section h2 {
    font-size: var(--text-sm, 0.8125rem);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #64748b);
    margin: 0 0 0.5rem;
}

/* Desktop: hide presentation-only chrome when not in demo */
@media (min-width: 1024px) {
    body.pf-demo-page .pf-bottom-nav {
        max-width: 28rem;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ——— Production shell (live app, not demo) ——— */
.pf-bottom-nav-host {
    display: none;
}

body.pf-shell-active .main-content {
    margin-left: 0 !important;
}

body.pf-shell-active .sidebar {
    transform: translateX(-100%);
    width: min(100vw, 320px);
    max-width: 100vw;
}

body.pf-shell-active .sidebar.open,
body.pf-shell-active .sidebar.pf-drawer--open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
}

body.pf-shell-active .sidebar.open + .sidebar-backdrop,
body.pf-shell-active .sidebar.pf-drawer--open + .sidebar-backdrop {
    display: block;
}

body.pf-shell-active .sidebar-toggle-btn {
    display: none;
}

body.pf-shell-active .menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: var(--tap-target-min, 2.75rem);
    min-height: var(--tap-target-min, 2.75rem);
}

body.pf-shell-active .top-bar-module-row,
body.pf-shell-active #globalItemSearchBar,
body.pf-shell-active .top-bar-quick-actions,
body.pf-shell-active #globalSelectedItemRow {
    display: none !important;
}

body.pf-shell-active .top-bar {
    flex-wrap: nowrap;
    padding: 0.5rem var(--spacing-md, 1.25rem);
    min-height: var(--pf-app-bar-height);
    gap: 0.5rem;
}

body.pf-shell-active .top-bar-right {
    margin-left: auto;
}

body.pf-shell-active .page-content.pf-has-bottom-nav {
    padding-bottom: calc(var(--pf-bottom-nav-height) + env(safe-area-inset-bottom, 0) + 0.75rem);
}

body.pf-shell-active .page-content {
    overflow-x: hidden;
    max-width: 100vw;
}

body.pf-shell-active .table-container {
    max-width: 100%;
}

body.pf-shell-active .app-container {
    overflow-x: hidden;
}

/* Desktop ≥1024px: presentation shell chrome hidden — pixel-identical workstation */
body.pf-desktop.pf-shell-active .pf-bottom-nav-host,
body.viewport-desktop .pf-bottom-nav-host {
    display: none !important;
}

body.pf-desktop .main-content {
    margin-left: var(--sidebar-width, 272px);
}

body.pf-desktop .sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed-width, 80px);
}

/* ——— Module sub-nav (Sales sections on mobile) ——— */
.pf-module-subnav-host {
    display: none;
    background: var(--surface-elevated, #fff);
    border-bottom: 1px solid var(--border-color, #e8edf2);
    padding: 0.35rem var(--spacing-md, 1.25rem);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
body.pf-shell-active .pf-module-subnav-host:not(:empty) {
    display: block;
}
.pf-module-subnav {
    display: flex;
    gap: 0.5rem;
    min-width: min-content;
}
.pf-module-subnav__pill {
    flex-shrink: 0;
    padding: 0.5rem 0.85rem;
    min-height: var(--tap-target-min, 2.75rem);
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-pill, 999px);
    background: var(--surface-muted, #eef2f6);
    color: var(--text-secondary, #64748b);
    text-decoration: none;
    font-size: var(--text-sm, 0.8125rem);
    font-weight: 500;
    white-space: nowrap;
}
.pf-module-subnav__pill--active {
    background: rgba(20, 184, 166, 0.14);
    color: var(--primary-dark, #0d9488);
    font-weight: 600;
}

/* ——— Sales invoices (mobile presentation) ——— */
.sales-invoices-cards-mount {
    display: none;
}
body.pf-shell-active .sales-invoices-cards-mount {
    display: block;
}
body.pf-shell-active .sales-invoices-table-wrap {
    display: none !important;
}
body.pf-shell-active .sales-invoices-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
body.pf-shell-active .sales-invoices-search-row .sales-invoices-search {
    width: 100%;
    min-height: 3rem;
    font-size: var(--text-base, 0.9375rem);
}
body.pf-shell-active .sales-invoices-filters-btn {
    width: 100%;
    min-height: 3rem;
}
body.pf-shell-active .sales-invoices-advanced-filters--collapsed {
    display: none !important;
}
body.pf-shell-active .sales-invoices-advanced-filters--expanded {
    display: flex !important;
    flex-direction: column;
    gap: 0.5rem;
}
body.pf-shell-active .sales-invoices-advanced-filters select,
body.pf-shell-active .sales-invoices-advanced-filters .form-input,
body.pf-shell-active .sales-invoices-advanced-filters .btn {
    width: 100% !important;
    min-height: 3rem;
}
body.pf-shell-active #salesCustomDateRange {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100%;
}
body.pf-shell-active .sales-invoices-header .sales-invoices-new-btn {
    min-height: 3rem;
}
body.pf-shell-active.pf-has-sales-fab .sales-invoices-header .sales-invoices-new-btn {
    display: none;
}
body.pf-shell-active .sales-invoices-table-wrap,
body.pf-shell-active .sales-invoices-cards-mount {
    max-height: none;
}
body.pf-shell-active .sales-invoices-body .table-container {
    max-height: calc(100dvh - 16rem) !important;
}

/* ——— Sales create / edit invoice form (mobile) ——— */
body.pf-shell-active #salesInvoiceForm [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
}
body.pf-shell-active #salesInvoiceForm [style*="grid-column: span 2"] {
    grid-column: span 1 !important;
}
body.pf-shell-active .sales-invoice-main-layout {
    flex-direction: column !important;
}
body.pf-shell-active .transaction-items-table,
body.pf-shell-active .txit-doc-table {
    font-size: var(--text-sm, 0.8125rem);
}
body.pf-shell-active .page-content {
    padding-left: var(--spacing-sm, 0.75rem);
    padding-right: var(--spacing-sm, 0.75rem);
}
body.pf-shell-active .card {
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
}

/* ——— General mobile page calm ——— */
body.pf-shell-active .page-content .card-header h3 {
    font-size: var(--text-lg, 1.125rem);
}
body.pf-shell-active .landing-tiles {
    grid-template-columns: 1fr !important;
}
