/* POS design system — tokens + layout + primitives. Loaded after MudBlazor. */

:root {
    /* Spacing */
    --pos-space-xs: 4px;
    --pos-space-sm: 8px;
    --pos-space-md: 12px;
    --pos-space-lg: 16px;
    --pos-space-xl: 24px;
    --pos-space-xxl: 32px;

    /* Radius */
    --pos-radius-sm: 8px;
    --pos-radius-md: 12px;
    --pos-radius-lg: 16px;

    /* Semantic colors (light) — aligned with SalesApp checkout shell (#3d4e81 / #f4f7fe) */
    --pos-color-primary: #3d4e81;
    --pos-color-primary-contrast: #FFFFFF;
    --pos-color-accent: #6366f1;
    --pos-color-surface: #FFFFFF;
    --pos-color-background: #f4f7fe;
    --pos-color-success: #2E7D32;
    --pos-color-warning: #EF6C00;
    --pos-color-error: #C62828;
    --pos-color-text: rgba(0, 0, 0, 0.87);
    --pos-color-text-muted: rgba(0, 0, 0, 0.60);
    --pos-color-border: rgba(148, 163, 184, 0.35);

    /* Typography scale (rem) */
    --pos-font-title: 1.5rem;
    --pos-font-title-weight: 700;
    --pos-font-title-line: 1.25;

    --pos-font-section: 1.05rem;
    --pos-font-section-weight: 600;
    --pos-font-section-line: 1.35;

    --pos-font-body: 0.9375rem;
    --pos-font-body-weight: 400;
    --pos-font-body-line: 1.5;

    --pos-font-caption: 0.8125rem;
    --pos-font-caption-weight: 500;
    --pos-font-caption-line: 1.4;

    /* Touch */
    --pos-touch-min: 48px;
    --pos-touch-icon: 48px;

    /* Layout */
    --pos-main-padding: var(--pos-space-xl);
    --pos-pos-category-width: 220px;
    --pos-pos-cart-width: 360px;

    /* Elevation (POS cards) */
    --pos-shadow-card: 0 1px 2px rgba(15, 23, 42, 0.06), 0 2px 10px rgba(61, 78, 129, 0.06);
    --pos-shadow-card-hover: 0 4px 14px rgba(61, 78, 129, 0.12), 0 8px 24px rgba(15, 23, 42, 0.08);
    --pos-shadow-card-press: 0 1px 4px rgba(15, 23, 42, 0.08);
    --pos-shadow-pay: 0 4px 16px rgba(61, 78, 129, 0.32), 0 2px 6px rgba(61, 78, 129, 0.18);
}

html, body {
    font-family: 'Cairo', 'Segoe UI', 'Roboto', sans-serif;
}

/* --- Typography roles --- */
.pos-typo-title {
    font-size: var(--pos-font-title);
    font-weight: var(--pos-font-title-weight);
    line-height: var(--pos-font-title-line);
    color: var(--pos-color-text);
    letter-spacing: 0.02em;
}

.pos-typo-section {
    font-size: var(--pos-font-section);
    font-weight: var(--pos-font-section-weight);
    line-height: var(--pos-font-section-line);
    color: var(--pos-color-text);
}

.pos-typo-body {
    font-size: var(--pos-font-body);
    font-weight: var(--pos-font-body-weight);
    line-height: var(--pos-font-body-line);
    color: var(--pos-color-text);
}

.pos-typo-caption {
    font-size: var(--pos-font-caption);
    font-weight: var(--pos-font-caption-weight);
    line-height: var(--pos-font-caption-line);
    color: var(--pos-color-text-muted);
}

/* --- App shell --- */
.pos-app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    gap: var(--pos-space-lg);
}

.pos-app-shell__header {
    flex: 0 0 auto;
}

.pos-app-shell__body {
    flex: 1 1 auto;
    min-height: 0;
}

.pos-app-shell__footer {
    flex: 0 0 auto;
}

/* --- Main content (both apps) --- */
.pos-main-content {
    padding: var(--pos-main-padding);
    padding-inline: max(var(--pos-space-lg), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
    background: var(--pos-color-background);
    box-sizing: border-box;
}

/* Page shell: keeps non-checkout screens aligned to one readable column */
.pos-app-body-wrap {
    width: 100%;
}

.pos-app-body-wrap--page {
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: clamp(10px, 2.5vw, 20px);
    box-sizing: border-box;
}

.pos-app-body-wrap--checkout {
    max-width: none;
}

/* Flex panels / scroll regions — use in POS shells and embedded views */
.hx-pos-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.hx-pos-scroll {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* Top app bar (SalesApp non-checkout) — same calm card language as checkout */
.pos-app-topbar.mud-appbar,
.pos-app-topbar.mud-appbar-fixed {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%) !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.28) !important;
    color: var(--pos-color-text) !important;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.85) inset;
    padding-inline: max(14px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)) !important;
    min-height: 56px;
}

.pos-app-topbar .mud-typography-h6 {
    font-weight: 800 !important;
    letter-spacing: 0.04em;
    color: var(--pos-color-primary) !important;
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
}

/* Shared elevated surface for forms, tables chrome, sync cards */
.mud-paper.pos-app-surface {
    border-radius: var(--pos-radius-lg) !important;
    border: 1px solid rgba(61, 78, 129, 0.1) !important;
    box-shadow: var(--pos-shadow-card);
    background: linear-gradient(165deg, #ffffff 0%, #f8fafc 100%) !important;
}

/* Drawer navigation — subtle brand wash */
.pos-nav-menu {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    background: linear-gradient(180deg, #ffffff 0%, #f4f7fe 50%, #eef2ff 100%);
    border-inline-start: 1px solid rgba(61, 78, 129, 0.08);
}

.pos-nav-menu__header {
    padding: var(--pos-space-xl) var(--pos-space-lg);
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

.pos-nav-menu__mark {
    display: block;
    width: 2.5rem;
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--pos-color-primary), var(--pos-color-accent));
    margin-bottom: var(--pos-space-sm);
}

.pos-nav-menu__title {
    font-weight: 800;
    letter-spacing: 0.02em;
}

.pos-nav-menu__tagline {
    margin-top: 2px;
    opacity: 0.75;
}

.pos-nav-menu__links .mud-nav-link {
    border-radius: var(--pos-radius-md);
    margin-inline: var(--pos-space-sm);
}

.pos-nav-menu__links .mud-nav-link.mud-nav-link-active:not(.mud-nav-link-disabled) {
    background: rgba(61, 78, 129, 0.08) !important;
    color: var(--pos-color-primary) !important;
    font-weight: 700;
}

@media (max-width: 599px) {
    .pos-main-content {
        padding: var(--pos-space-lg);
    }
}

/* --- POS checkout layout (RTL: column 1 = visual right = categories) --- */
.pos-pos-layout {
    display: grid;
    grid-template-columns: minmax(180px, var(--pos-pos-category-width)) minmax(0, 1fr) minmax(280px, var(--pos-pos-cart-width));
    gap: var(--pos-space-lg);
    align-items: stretch;
    min-height: min(70dvh, 720px);
}

/* Category column: sticky rail on wide screens */
.pos-pos-layout__category-rail {
    position: sticky;
    top: var(--pos-space-md);
    align-self: start;
    max-height: min(calc(100dvh - 120px), 720px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-inline-end: var(--pos-space-xs);
    scrollbar-gutter: stable;
}

.pos-pos-layout__category-rail .pos-section-header {
    margin-bottom: var(--pos-space-md);
}

.pos-pos-layout__category-rail > .mud-button-root:last-of-type {
    margin-top: var(--pos-space-md);
}

@media (max-width: 959px) {
    .pos-pos-layout {
        grid-template-columns: 1fr;
        min-height: unset;
    }

    .pos-pos-layout__categories {
        order: 1;
    }

    .pos-pos-layout__category-rail {
        position: relative;
        top: auto;
        max-height: none;
        overflow: visible;
    }

    .pos-pos-layout__products {
        order: 2;
    }

    .pos-pos-layout__cart {
        order: 3;
        position: relative !important;
        top: auto !important;
        max-height: none !important;
    }
}

.pos-pos-layout__cart {
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-md);
    position: sticky;
    top: var(--pos-space-md);
    align-self: start;
    max-height: min(calc(100dvh - 140px), 680px);
}

.pos-pos-layout__cart-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-md);
    padding-inline-end: 2px;
}

.pos-pos-layout__cart-footer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-md);
}

/* --- Admin dashboard layout --- */
.pos-dashboard-layout {
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-lg);
    max-width: 1400px;
    margin-inline: auto;
}

.pos-dashboard-layout__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--pos-space-md);
}

/* --- Cards --- */
.pos-app-card {
    border-radius: var(--pos-radius-md);
    background: var(--pos-color-surface);
}

.pos-app-card--pad {
    padding: var(--pos-space-lg);
}

/* --- POS product grid --- */
.pos-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--pos-space-lg);
}

@media (min-width: 960px) {
    .pos-product-grid {
        grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
    }
}

.pos-product-card {
    position: relative;
    border-radius: var(--pos-radius-lg);
    padding: 0;
    border: 1px solid rgba(61, 78, 129, 0.12);
    background: linear-gradient(165deg, #FFFFFF 0%, #F8FAFC 100%);
    box-shadow: var(--pos-shadow-card);
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 188px;
    overflow: hidden;
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

button.pos-product-card {
    font: inherit;
    color: inherit;
    width: 100%;
    text-align: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.pos-product-card:hover {
    border-color: rgba(61, 78, 129, 0.28);
    box-shadow: var(--pos-shadow-card-hover);
    transform: translateY(-1px);
}

.pos-product-card:active {
    transform: translateY(0);
    box-shadow: var(--pos-shadow-card-press);
}

.pos-product-card__body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-xs);
    padding: var(--pos-space-lg) var(--pos-space-lg) var(--pos-space-md);
    min-height: 0;
}

.pos-product-card__title {
    font-size: var(--pos-font-section);
    font-weight: 700;
    line-height: var(--pos-font-section-line);
    color: var(--pos-color-text);
    letter-spacing: 0.01em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pos-product-card__meta {
    font-size: 0.75rem !important;
    line-height: 1.45 !important;
    font-weight: 500 !important;
    letter-spacing: 0.03em;
    color: var(--pos-color-text-muted) !important;
    font-variant-numeric: tabular-nums;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pos-product-card__price-row {
    margin-top: auto;
    padding-top: var(--pos-space-sm);
}

.pos-product-card__price-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--pos-space-sm) var(--pos-space-md);
    border-radius: var(--pos-radius-sm);
    font-size: 1.125rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    color: #FFFFFF;
    background: linear-gradient(135deg, #3d4e81 0%, #4f5f95 45%, #2f3d66 100%);
    box-shadow: 0 2px 6px rgba(61, 78, 129, 0.35);
}

/* --- Category rail --- */
.pos-category-rail {
    display: block;
}

.pos-category-list {
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-sm);
}

.pos-category-list__btn {
    justify-content: flex-start !important;
    text-align: start !important;
    min-height: 52px !important;
    border-radius: var(--pos-radius-md) !important;
    font-weight: 600 !important;
    letter-spacing: 0.02em !important;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease !important;
}

.pos-category-list__btn:not(.pos-category-list__btn--active):hover {
    background-color: rgba(61, 78, 129, 0.07) !important;
}

.pos-category-list__btn--active {
    background: linear-gradient(135deg, #3d4e81 0%, #6366f1 100%) !important;
    color: #FFFFFF !important;
    border-color: transparent !important;
    box-shadow: 0 2px 8px rgba(61, 78, 129, 0.35) !important;
}

/* --- Cart panel --- */
.pos-cart-panel__lines .pos-cart-line + .pos-cart-line {
    margin-top: 2px;
}

.pos-cart-panel__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--pos-space-xl) var(--pos-space-md);
    border-radius: var(--pos-radius-md);
    background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
    border: 1px dashed #CFD8DC;
}

.pos-cart-panel__empty-icon {
    font-size: 2.75rem !important;
    width: 1em !important;
    height: 1em !important;
    opacity: 0.35;
    margin-bottom: var(--pos-space-md);
}

.pos-cart-panel__empty-text {
    max-width: 16rem;
    line-height: 1.5 !important;
    color: var(--pos-color-text-muted) !important;
}

/* --- Cart line --- */
.pos-cart-line {
    border-radius: var(--pos-radius-md);
    padding: var(--pos-space-md) var(--pos-space-md);
    background: #FFFFFF;
    border: 1px solid #ECEFF1;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pos-cart-line:hover {
    border-color: #CFD8DC;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.pos-cart-line__qty {
    min-width: var(--pos-touch-min);
    justify-content: center;
    font-weight: 700 !important;
    font-variant-numeric: tabular-nums;
}

/* --- Totals emphasis --- */
.pos-totals-panel {
    position: relative;
    border-radius: var(--pos-radius-lg);
    padding: var(--pos-space-lg);
    padding-top: var(--pos-space-md);
    background: linear-gradient(180deg, #FFFFFF 0%, #ECEFF1 100%);
    border: 1px solid #90A4AE;
    box-shadow: var(--pos-shadow-card);
}

.pos-totals-panel__accent {
    height: 4px;
    border-radius: 4px;
    margin-bottom: var(--pos-space-md);
    background: linear-gradient(90deg, #3d4e81, #6366f1, #3d4e81);
}

.pos-totals-panel__row {
    padding-top: var(--pos-space-xs);
}

.pos-totals-panel__label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.8rem !important;
    color: var(--pos-color-text-muted) !important;
}

.pos-totals-panel__amount {
    font-size: 1.85rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #3d4e81;
    letter-spacing: 0.02em;
}

/* --- Pay CTA --- */
.pos-checkout-pay {
    min-height: 58px !important;
    font-size: 1.08rem !important;
    font-weight: 800 !important;
    letter-spacing: 0.06em !important;
    border-radius: var(--pos-radius-md) !important;
    text-transform: uppercase;
    box-shadow: var(--pos-shadow-pay) !important;
}

.pos-checkout-pay:not(:disabled) {
    background: linear-gradient(180deg, #4f5f95 0%, #3d4e81 45%, #2a365c 100%) !important;
}

.pos-checkout-pay:not(:disabled):hover {
    filter: brightness(1.05);
    box-shadow: 0 6px 22px rgba(61, 78, 129, 0.42) !important;
}

.pos-checkout-pay:not(:disabled):active {
    filter: brightness(0.97);
    transform: translateY(1px);
}

.pos-checkout-pay:disabled {
    box-shadow: none !important;
    opacity: 0.72;
}

/* --- Checkout rail: session + sync (visible, calm) --- */
.pos-session-context.pos-app-card,
.pos-session-context.mud-paper {
    background: linear-gradient(180deg, #FAFBFC 0%, #F5F7FA 100%);
    border-color: #E0E0E0 !important;
}

.pos-session-context .mud-typography-overline {
    letter-spacing: 0.12em;
    font-weight: 600;
}

.pos-sync-strip.mud-paper {
    background: #FAFBFC;
    border-color: #ECEFF1 !important;
}

.pos-sync-strip .mud-typography-subtitle1 {
    font-size: 1rem !important;
    font-weight: 600 !important;
    color: rgba(0, 0, 0, 0.72) !important;
}

.pos-shift-hint {
    border-radius: var(--pos-radius-sm) !important;
    background: rgba(239, 108, 0, 0.06) !important;
}

.pos-checkout-status {
    border-radius: var(--pos-radius-sm) !important;
    font-size: 0.875rem !important;
}

/* --- Touch targets (POS) --- */
.pos-touch .mud-button-root.mud-button-filled-size-large,
.pos-touch .mud-button-root.mud-button-outlined-size-large,
.pos-touch .mud-button-root.mud-button-filled-size-medium,
.pos-touch .mud-button-root.mud-button-outlined-size-medium {
    min-height: var(--pos-touch-min);
}

.pos-touch .mud-icon-button {
    width: var(--pos-touch-icon);
    height: var(--pos-touch-icon);
}

/* --- Data table shell --- */
.pos-data-table-wrap {
    border-radius: var(--pos-radius-lg);
    overflow: hidden;
    border: 1px solid rgba(61, 78, 129, 0.1);
    background: var(--pos-color-surface);
    box-shadow: var(--pos-shadow-card);
}

.pos-data-toolbar {
    padding: var(--pos-space-md) var(--pos-space-lg);
    border-bottom: 1px solid var(--pos-color-border);
    background: var(--pos-color-surface);
}

.pos-data-table-wrap .mud-table-container {
    border-radius: 0;
}

/* --- Interaction --- */
.pos-loading-block {
    padding: var(--pos-space-xxl);
}

.pos-empty-state {
    border-style: dashed;
    border-radius: var(--pos-radius-lg);
    border-color: #B0BEC5;
    padding: var(--pos-space-xxl) var(--pos-space-xl);
    text-align: center;
    background: linear-gradient(165deg, #FAFBFC 0%, #F5F7FA 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.pos-page-header {
    position: relative;
    margin-bottom: var(--pos-space-xl);
    margin-inline: 0;
    padding: var(--pos-space-lg) max(var(--pos-space-xl), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
    padding-top: calc(var(--pos-space-lg) + 4px);
    background: var(--pos-color-surface);
    border-radius: var(--pos-radius-lg);
    border: 1px solid rgba(61, 78, 129, 0.1);
    box-shadow: var(--pos-shadow-card);
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
}

.pos-page-header::before {
    content: "";
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--pos-color-primary) 0%, var(--pos-color-accent) 50%, var(--pos-color-primary) 100%);
    opacity: 0.95;
}

.pos-page-header .pos-typo-title {
    margin: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* --- Form --- */
.pos-form-section {
    border-radius: var(--pos-radius-md);
    padding: var(--pos-space-lg);
    margin-bottom: var(--pos-space-lg);
}

.pos-form-field {
    margin-bottom: var(--pos-space-md);
}

.pos-dialog-form {
    display: flex;
    flex-direction: column;
    gap: var(--pos-space-md);
    min-width: min(100%, 420px);
}
