:root {
    --bs-font-sans-serif: 'Cairo', system-ui, -apple-system, sans-serif;
    --primary-color: #2c3e50;
    --accent-color: #d4af37;
    --sidebar-width: 260px;
    --topbar-height: 60px;
}

html {
    max-width: 100%;
}

body {
    font-family: var(--bs-font-sans-serif);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.font-amiri {
    font-family: 'Amiri', serif;
}

.min-w-0 {
    min-width: 0;
}

/* ------------------------------------------------------------------ */
/* App shell / page layout                                              */
/* ------------------------------------------------------------------ */
.app-shell {
    min-width: 0;
}

.app-shell > * {
    min-width: 0;
}

.main-content {
    min-width: 0;
}

/* Sticky topbar (kept in normal flow; height matches the sidebar offset) */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-topbar .container-fluid {
    min-width: 0;
}

.app-brand {
    min-width: 0;
    flex: 0 1 auto;
}

.app-brand-text {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.app-topbar-actions {
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .app-topbar {
        height: var(--topbar-height);
        padding-block: 0;
    }

    .app-topbar .container-fluid {
        flex-wrap: nowrap;
    }
}

/* Compact, horizontally scrollable mobile navigation row (<768px only) */
.app-mobile-nav {
    flex-basis: 100%;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: .35rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-top: .5rem;
}

.app-mobile-nav::-webkit-scrollbar {
    display: none;
}

.app-mobile-nav .app-mobile-link {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    min-height: 34px;
    padding: .3rem .7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .07);
    color: #cbd5e1;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    transition: background .2s ease, color .2s ease;
}

.app-mobile-nav .app-mobile-link:hover,
.app-mobile-nav .app-mobile-link.active {
    background: #0d6efd;
    color: #fff;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */
.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background-color: #1e293b;
    color: #f8fafc;
    min-height: calc(100vh - var(--topbar-height));
}

@media (min-width: 768px) {
    .app-sidebar {
        position: sticky;
        top: var(--topbar-height);
        align-self: flex-start;
        height: calc(100vh - var(--topbar-height));
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: #475569 transparent;
    }
}

.app-sidebar .nav-link {
    color: #94a3b8;
    padding: 8px 12px;
    border-radius: 6px;
    margin: 2px 8px;
    font-size: .9rem;
    font-weight: 500;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    border-inline-start: 3px solid transparent;
    transition: background-color .2s ease, color .2s ease;
}

.app-sidebar .nav-link > span:first-child {
    flex: 0 0 1.25rem;
    text-align: center;
    line-height: 1;
}

.app-sidebar .nav-link > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar .nav-link:hover {
    color: #ffffff;
    background-color: #334155;
}

.app-sidebar .nav-link.active {
    color: #ffffff;
    background-color: #0d6efd;
    font-weight: 700;
    border-inline-start-color: var(--accent-color);
    box-shadow: 0 1px 6px rgba(13, 110, 253, .35);
}

.app-sidebar hr {
    border-top-color: rgba(248, 250, 252, .18);
    opacity: 1;
    margin: .75rem 8px;
}

/* ------------------------------------------------------------------ */
/* Flash alerts                                                        */
/* ------------------------------------------------------------------ */
.ui-flash-stack {
    display: grid;
    gap: .5rem;
    margin-bottom: 1rem;
}

.ui-flash-stack .alert {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.ui-flash-stack .alert .btn-close {
    margin-inline-start: auto;
    flex-shrink: 0;
}

/* ------------------------------------------------------------------ */
/* Shared UI utilities (frozen — consumed by page views)               */
/* ------------------------------------------------------------------ */
.ui-page-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: .75rem;
    margin-bottom: 1rem;
}

.ui-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}

.ui-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.ui-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.ui-table-card {
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, .125);
    border-radius: .5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    overflow: hidden;
}

.ui-table-card .table-responsive {
    width: 100%;
    max-width: 100%;
}

.ui-table-card .table {
    margin-bottom: 0;
}

.ui-empty {
    text-align: center;
    color: #6c757d;
    padding: 2rem 1rem;
}

.ui-section-title {
    font-weight: 600;
    margin-bottom: .5rem;
}

/* ------------------------------------------------------------------ */
/* Touch targets, focus, tables, cards                                 */
/* ------------------------------------------------------------------ */
.form-control,
.form-select,
.btn {
    min-height: 38px;
}

.btn-sm,
.btn-group-sm > .btn {
    min-height: 30px;
}

.btn-close {
    min-height: 0;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid rgba(13, 110, 253, .45);
    outline-offset: 2px;
    box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .18);
}

.table > tbody > tr:hover {
    background-color: rgba(13, 110, 253, .045);
}

.card {
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

/* POS Touch Targets (PRD §7.3 >= 48px) */
.btn-pos-touch {
    min-height: 48px;
    min-width: 48px;
    font-size: 1.05rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-pos-service {
    min-height: 56px;
    padding: 12px 16px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    text-align: start;
}

/* Metric Cards */
.card-stat {
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s;
}

.card-stat:hover {
    transform: translateY(-2px);
}

/* RTL Helpers */
[dir="rtl"] .dropdown-menu {
    text-align: right;
}

[dir="rtl"] .me-2 {
    margin-left: 0.5rem !important;
    margin-right: 0 !important;
}

[dir="rtl"] .ms-2 {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
}

/* ------------------------------------------------------------------ */
/* Small-screen tweaks                                                 */
/* ------------------------------------------------------------------ */
@media (max-width: 767.98px) {
    .main-content {
        padding: .75rem;
    }

    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.3rem; }
    h3, .h3 { font-size: 1.15rem; }

    .ui-page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .ui-page-head > * {
        width: 100%;
    }

    .ui-toolbar > .btn,
    .ui-toolbar > .form-control,
    .ui-toolbar > .form-select {
        flex: 1 1 auto;
    }

    .app-topbar {
        padding-inline: .75rem;
    }

    .app-topbar .navbar-brand {
        margin-inline-end: .5rem;
        font-size: 1rem;
    }

    .app-brand-icon {
        font-size: 1.35rem !important;
    }

    .table-responsive {
        max-width: 100%;
    }

    .app-shell,
    .main-content,
    .card,
    .ui-table-card {
        max-width: 100%;
    }

    img,
    svg,
    video,
    canvas {
        max-width: 100%;
    }

    .footer .container {
        padding-inline: .75rem;
        line-height: 1.9;
    }
}

/* Thermal Receipt Styling */
@media print {
    body {
        background: transparent !important;
        font-family: 'Cairo', monospace !important;
    }
    .no-print {
        display: none !important;
    }
    .receipt-80mm {
        width: 72mm;
        margin: 0 auto;
        padding: 2mm;
        font-size: 12px;
    }
}
