/*
 * Coffee Shop MS — warm RTL theme.
 * Layered on top of Bootstrap 5 RTL; only overrides what the brand needs.
 */

:root {
    /* Brand palette: brown, gold, cream, green. */
    --coffee-900: #2C1810;
    --coffee-800: #3E2723;
    --coffee-700: #4E342E;
    --coffee-600: #6F4E37;
    --coffee-500: #8D6E63;
    --coffee-400: #A1887F;
    --coffee-300: #BCAAA4;

    --gold-600: #B8860B;
    --gold-500: #C9A227;
    --gold-400: #D4AF37;
    --gold-200: #F0DFA8;

    --cream-100: #FDFBF7;
    --cream-200: #F8F3EC;
    --cream-300: #F0E6D8;
    --cream-400: #E4D5C1;

    --green-600: #3D7A6C;
    --green-500: #4E8C7D;
    --green-300: #A8CFC4;

    --danger: #C0392B;
    --warning: #E08A1E;
    --info: #4A7BA7;

    --text-primary: #2C1810;
    --text-muted: #7A6A5F;

    --shadow-sm: 0 1px 3px rgba(44, 24, 16, .08), 0 1px 2px rgba(44, 24, 16, .06);
    --shadow-md: 0 4px 12px rgba(44, 24, 16, .10), 0 2px 4px rgba(44, 24, 16, .06);
    --shadow-lg: 0 12px 28px rgba(44, 24, 16, .14), 0 4px 8px rgba(44, 24, 16, .08);

    --radius: .75rem;
    --radius-sm: .5rem;
    --radius-lg: 1rem;

    --transition: .22s cubic-bezier(.4, 0, .2, 1);

    --sidebar-width: 268px;
}

/* ---------------------------------------------------------------- base */

body {
    font-family: 'Cairo', 'Tajawal', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--cream-200);
    color: var(--text-primary);
    font-size: .935rem;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--coffee-800); }

a { color: var(--coffee-600); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--gold-600); }

/* Arabic numerals stay LTR inside RTL text so prices read correctly. */
.num, .table td .num, .stat-value { direction: ltr; display: inline-block; unicode-bidi: embed; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--cream-300); }
::-webkit-scrollbar-thumb { background: var(--coffee-400); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--coffee-600); }

/* ---------------------------------------------------------------- shell */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(170deg, var(--coffee-800) 0%, var(--coffee-900) 100%);
    color: var(--cream-300);
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
}

.sidebar-brand {
    padding: 1.25rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
    display: flex;
    align-items: center;
    gap: .7rem;
}

.sidebar-brand .brand-mark {
    width: 42px; height: 42px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
    display: grid; place-items: center;
    color: var(--coffee-900); font-size: 1.25rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-text { line-height: 1.25; min-width: 0; }
.sidebar-brand .brand-title { font-weight: 800; color: #fff; font-size: 1.02rem; }
.sidebar-brand .brand-sub { font-size: .715rem; color: var(--coffee-300); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .65rem 1.5rem; }

.sidebar-nav .nav-section {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--coffee-400);
    padding: 1rem .75rem .35rem;
    font-weight: 700;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--cream-300);
    font-size: .89rem;
    font-weight: 500;
    margin-bottom: .15rem;
    transition: background var(--transition), color var(--transition), transform var(--transition);
}

.sidebar-nav .nav-link i { width: 1.25rem; text-align: center; font-size: .95rem; opacity: .85; }

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, .07);
    color: #fff;
    transform: translateX(-3px); /* RTL: nudges toward the content area. */
}

.sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, rgba(212, 175, 55, .22), rgba(212, 175, 55, .06));
    color: #fff;
    box-shadow: inset 3px 0 0 var(--gold-400);
}

.sidebar-nav .nav-link.active i { opacity: 1; color: var(--gold-400); }

.sidebar-footer {
    padding: .85rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .09);
    font-size: .74rem;
    color: var(--coffee-400);
}

.app-main {
    flex: 1;
    min-width: 0;
    margin-inline-start: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--cream-400);
    padding: .7rem 1.35rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-sm);
}

.topbar .page-title { font-size: 1.1rem; font-weight: 700; margin: 0; }

.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .55rem; }

.notif-btn { position: relative; }

.notif-badge {
    position: absolute;
    top: -3px; inset-inline-end: -3px;
    min-width: 18px; height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    display: grid; place-items: center;
}

.app-content { padding: 1.35rem; flex: 1; }

/* ---------------------------------------------------------------- cards */

.card {
    border: 1px solid var(--cream-400);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: #fff;
    transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    background: var(--cream-100);
    border-bottom: 1px solid var(--cream-400);
    font-weight: 700;
    color: var(--coffee-800);
    padding: .8rem 1.1rem;
    border-radius: var(--radius) var(--radius) 0 0 !important;
}

/* KPI cards */

.stat-card {
    position: relative;
    overflow: hidden;
    border: none;
    border-radius: var(--radius);
    color: #fff;
    padding: 1.2rem 1.3rem;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.stat-card::after {
    content: '';
    position: absolute;
    inset-block-start: -32px;
    inset-inline-end: -32px;
    width: 128px; height: 128px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .09);
}

.stat-card .stat-icon {
    width: 46px; height: 46px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .19);
    display: grid; place-items: center;
    font-size: 1.3rem;
    margin-bottom: .75rem;
}

.stat-card .stat-label { font-size: .82rem; opacity: .92; font-weight: 500; }
.stat-card .stat-value { font-size: 1.85rem; font-weight: 800; line-height: 1.25; }
.stat-card .stat-meta { font-size: .75rem; opacity: .85; }

.stat-card.tone-coffee { background: linear-gradient(135deg, var(--coffee-600), var(--coffee-800)); }
.stat-card.tone-gold   { background: linear-gradient(135deg, var(--gold-500), var(--gold-600)); }
.stat-card.tone-green  { background: linear-gradient(135deg, var(--green-500), var(--green-600)); }
.stat-card.tone-clay   { background: linear-gradient(135deg, #B07156, #8C5340); }

/* ---------------------------------------------------------------- tables */

.table { --bs-table-bg: transparent; margin-bottom: 0; }

.table > thead > tr > th {
    background: var(--cream-300);
    color: var(--coffee-800);
    font-weight: 700;
    font-size: .82rem;
    border-bottom: 2px solid var(--cream-400);
    white-space: nowrap;
    padding: .7rem .8rem;
}

.table > tbody > tr > td { padding: .65rem .8rem; vertical-align: middle; border-color: var(--cream-300); }
.table > tbody > tr { transition: background var(--transition); }
.table > tbody > tr:hover { background: var(--cream-100); }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }

/* Sortable column headers */
.table th a.sort-link { color: inherit; display: inline-flex; align-items: center; gap: .3rem; }
.table th a.sort-link i { font-size: .7rem; opacity: .5; }
.table th a.sort-link.active i { opacity: 1; color: var(--gold-600); }

/* ---------------------------------------------------------------- buttons */

.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: .875rem; transition: all var(--transition); }

.btn-coffee { background: var(--coffee-600); border-color: var(--coffee-600); color: #fff; }
.btn-coffee:hover, .btn-coffee:focus { background: var(--coffee-700); border-color: var(--coffee-700); color: #fff; box-shadow: var(--shadow-md); }

.btn-gold { background: var(--gold-500); border-color: var(--gold-500); color: var(--coffee-900); }
.btn-gold:hover, .btn-gold:focus { background: var(--gold-600); border-color: var(--gold-600); color: #fff; }

.btn-outline-coffee { border-color: var(--coffee-500); color: var(--coffee-600); }
.btn-outline-coffee:hover { background: var(--coffee-600); border-color: var(--coffee-600); color: #fff; }

.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; }

/* ---------------------------------------------------------------- forms */

.form-label { font-weight: 600; font-size: .84rem; color: var(--coffee-700); margin-bottom: .3rem; }

.form-control, .form-select {
    border: 1px solid var(--cream-400);
    border-radius: var(--radius-sm);
    font-size: .89rem;
    padding: .48rem .75rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--coffee-500);
    box-shadow: 0 0 0 .2rem rgba(111, 78, 55, .14);
}

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.text-danger, .field-validation-error { font-size: .8rem; }

.input-group-text { background: var(--cream-300); border-color: var(--cream-400); color: var(--coffee-700); font-size: .85rem; }

/* ---------------------------------------------------------------- badges */

.badge { font-weight: 600; font-size: .74rem; padding: .35em .65em; border-radius: 999px; }

.badge-soft-coffee { background: var(--cream-300); color: var(--coffee-700); }

/* ---------------------------------------------------------------- product cards */

.product-card {
    border: 1px solid var(--cream-400);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), box-shadow var(--transition);
}

.product-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }

.product-card .product-media {
    aspect-ratio: 4 / 3;
    background: var(--cream-300);
    display: grid; place-items: center;
    overflow: hidden;
    position: relative;
}

.product-card .product-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.product-card:hover .product-media img { transform: scale(1.06); }
.product-card .product-media .placeholder-icon { font-size: 2.4rem; color: var(--coffee-400); }

.product-card .product-body { padding: .85rem; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.product-card .product-name { font-weight: 700; font-size: .95rem; margin: 0; }
.product-card .product-desc {
    font-size: .78rem; color: var(--text-muted); margin: 0;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.product-card .product-price { font-weight: 800; color: var(--coffee-600); font-size: 1.05rem; }

.product-card .product-flag {
    position: absolute; top: .5rem; inset-inline-start: .5rem;
    background: var(--gold-500); color: var(--coffee-900);
    font-size: .68rem; font-weight: 700;
    padding: .18rem .5rem; border-radius: 999px;
}

.product-card.out-of-stock { opacity: .62; }
.product-card.out-of-stock .product-media::before {
    content: 'غير متوفر';
    position: absolute; inset: 0;
    background: rgba(44, 24, 16, .58);
    color: #fff; font-weight: 700;
    display: grid; place-items: center;
    z-index: 2;
}

/* ---------------------------------------------------------------- POS */

.pos-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1rem; align-items: start; }

.pos-cart { position: sticky; top: 5rem; }

.cart-line {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem 0;
    border-bottom: 1px dashed var(--cream-400);
}

.cart-line:last-child { border-bottom: none; }
.cart-line .cart-name { flex: 1; min-width: 0; font-size: .85rem; font-weight: 600; }
.cart-line .cart-name small { display: block; font-weight: 400; color: var(--text-muted); }

.qty-control { display: inline-flex; align-items: center; border: 1px solid var(--cream-400); border-radius: var(--radius-sm); overflow: hidden; }
.qty-control button { border: none; background: var(--cream-200); width: 26px; height: 28px; color: var(--coffee-700); font-weight: 700; }
.qty-control button:hover { background: var(--coffee-600); color: #fff; }
.qty-control input { width: 40px; border: none; text-align: center; font-size: .82rem; font-weight: 700; }
.qty-control input:focus { outline: none; }

.totals-row { display: flex; justify-content: space-between; font-size: .86rem; padding: .22rem 0; }
.totals-row.grand { font-size: 1.12rem; font-weight: 800; color: var(--coffee-700); border-top: 2px solid var(--cream-400); padding-top: .5rem; margin-top: .35rem; }

/* ---------------------------------------------------------------- timeline */

.timeline { position: relative; padding-inline-start: 1.6rem; }
.timeline::before {
    content: ''; position: absolute;
    inset-block: .4rem; inset-inline-start: .38rem;
    width: 2px; background: var(--cream-400);
}
.timeline-item { position: relative; padding-bottom: 1rem; }
.timeline-item::before {
    content: ''; position: absolute;
    inset-inline-start: -1.32rem; top: .38rem;
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--gold-500); border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--cream-400);
}
.timeline-item:last-child { padding-bottom: 0; }

/* ---------------------------------------------------------------- misc */

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 3rem; color: var(--coffee-300); margin-bottom: .8rem; display: block; }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 340px; }

.low-stock-row { background: rgba(192, 57, 43, .07) !important; }

.avatar-circle {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--coffee-500), var(--coffee-700));
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: .82rem; flex-shrink: 0;
}

.thumb {
    width: 42px; height: 42px; border-radius: var(--radius-sm);
    object-fit: cover; background: var(--cream-300);
}

/* ---------------------------------------------------------------- print */

@media print {
    .sidebar, .topbar, .app-content > .no-print, .no-print { display: none !important; }
    .app-main { margin-inline-start: 0; }
    .app-content { padding: 0; }
    body { background: #fff; }
    .card { border: none; box-shadow: none; }
    a[href]::after { content: none !important; }
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1200px) {
    .pos-grid { grid-template-columns: 1fr; }
    .pos-cart { position: static; }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); } /* RTL: hides off the right edge. */
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-inline-start: 0; }

    .sidebar-backdrop {
        position: fixed; inset: 0;
        background: rgba(44, 24, 16, .45);
        z-index: 1035;
    }
}

@media (max-width: 575.98px) {
    .app-content { padding: .85rem; }
    .stat-card .stat-value { font-size: 1.5rem; }
    .topbar { padding: .6rem .85rem; }
    .topbar .page-title { font-size: .98rem; }
}

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    .card:hover, .stat-card:hover, .product-card:hover { transform: none; }
}
