/* ==========================================================================
   AL KARMA FOODS SYSTEM — Design System
   Layers on top of Bootstrap 5.3 (data-bs-theme aware). Enhances tokens,
   the app shell, cards, tables, forms, buttons and badges for a cohesive,
   modern admin look in both light and dark themes.
   ========================================================================== */

:root {
    /* Brand */
    --akf-brand: #0f7b3f;
    --akf-brand-rgb: 15, 123, 63;
    --akf-brand-600: #0c6836;
    --akf-brand-700: #0a562d;
    --akf-brand-soft: rgba(var(--akf-brand-rgb), 0.10);

    --akf-sidebar-w: 268px;
    --akf-radius: 0.85rem;
    --akf-radius-sm: 0.6rem;
    --akf-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --akf-shadow-lg: 0 8px 30px rgba(16, 24, 40, .12);

    /* Map Bootstrap primary onto the brand */
    --bs-primary: var(--akf-brand);
    --bs-primary-rgb: var(--akf-brand-rgb);
    --bs-link-color: var(--akf-brand-600);
    --bs-link-hover-color: var(--akf-brand-700);
}

/* Light theme surfaces */
:root,
:root[data-bs-theme="light"] {
    --akf-bg: #f5f7fa;
    --akf-surface: #ffffff;
    --akf-surface-2: #f8fafc;
    --akf-border: #e8ecf1;
    --akf-text-muted: #6b7280;
    --akf-sidebar-bg: #ffffff;
    --akf-topbar-bg: rgba(255, 255, 255, .82);
}

/* Dark theme surfaces */
:root[data-bs-theme="dark"] {
    --akf-bg: #0b0f14;
    --akf-surface: #131a22;
    --akf-surface-2: #0f151c;
    --akf-border: #232d38;
    --akf-text-muted: #93a1b0;
    --akf-sidebar-bg: #0e141b;
    --akf-topbar-bg: rgba(14, 20, 27, .82);
    --akf-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .35);
    --bs-body-bg: #0b0f14;
    --bs-body-color: #dbe2ea;
}

body {
    background: var(--akf-bg);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}
html[dir="rtl"] body { font-family: 'Cairo', system-ui, sans-serif; }

/* ---------- App shell ---------------------------------------------------- */
.akf-sidebar {
    width: var(--akf-sidebar-w);
    height: 100vh;
    height: 100dvh;
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    background: var(--akf-sidebar-bg);
    border-inline-end: 1px solid var(--akf-border);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    z-index: 1040;
    transition: transform .22s ease;
    padding: 1rem .75rem;
}
.akf-sidebar::-webkit-scrollbar { width: 6px; }
.akf-sidebar::-webkit-scrollbar-thumb { background: var(--akf-border); border-radius: 3px; }

.akf-content { margin-inline-start: var(--akf-sidebar-w); min-height: 100vh; }

.akf-brand-mark {
    width: 40px; height: 40px; border-radius: 11px;
    background: linear-gradient(135deg, var(--akf-brand), var(--akf-brand-700));
    color: #fff; box-shadow: 0 6px 16px rgba(var(--akf-brand-rgb), .35);
}
.akf-brand-name { font-weight: 800; letter-spacing: -.02em; color: var(--bs-body-color); line-height: 1.05; }
.akf-brand-sub { font-size: .68rem; color: var(--akf-text-muted); letter-spacing: .12em; text-transform: uppercase; }

.akf-group-label {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
    color: var(--akf-text-muted); padding: .5rem .75rem .25rem;
}
.akf-nav-link {
    color: var(--bs-body-color); border-radius: var(--akf-radius-sm);
    padding: .55rem .7rem; display: flex; align-items: center; gap: .65rem;
    font-size: .9rem; font-weight: 500; text-decoration: none;
    transition: background .12s ease, color .12s ease;
    position: relative;
}
.akf-nav-link .bi { font-size: 1.05rem; opacity: .85; width: 1.2rem; text-align: center; }
.akf-nav-link:hover { background: var(--akf-surface-2); color: var(--bs-body-color); }
.akf-nav-link.active { background: var(--akf-brand); color: #fff; box-shadow: 0 4px 12px rgba(var(--akf-brand-rgb), .30); }
.akf-nav-link.active .bi { opacity: 1; }

/* ---------- Topbar ------------------------------------------------------- */
.akf-topbar {
    position: sticky; top: 0; z-index: 1030;
    background: var(--akf-topbar-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--akf-border);
    padding: .6rem 1.25rem;
    display: flex; align-items: center; gap: .75rem;
}
.akf-search {
    background: var(--akf-surface-2); border: 1px solid var(--akf-border);
    border-radius: 999px; padding: .35rem .9rem; display: flex; align-items: center; gap: .5rem;
    color: var(--akf-text-muted); max-width: 380px; width: 100%;
}
.akf-search input { border: 0; background: transparent; outline: none; width: 100%; color: var(--bs-body-color); font-size: .875rem; }
.akf-icon-btn {
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--akf-border);
    background: var(--akf-surface); color: var(--bs-body-color);
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .12s ease, border-color .12s ease;
}
.akf-icon-btn:hover { background: var(--akf-surface-2); border-color: var(--akf-brand); color: var(--akf-brand-600); }

/* ---------- Page header -------------------------------------------------- */
.akf-page { padding: 1.5rem 1.25rem 2.5rem; }
.akf-breadcrumb { font-size: .78rem; color: var(--akf-text-muted); }
.akf-breadcrumb a { color: var(--akf-text-muted); text-decoration: none; }
.akf-breadcrumb a:hover { color: var(--akf-brand-600); }
.akf-page-title { font-weight: 800; letter-spacing: -.02em; margin: 0; }

/* ---------- Cards -------------------------------------------------------- */
.card {
    border: 1px solid var(--akf-border);
    border-radius: var(--akf-radius);
    background: var(--akf-surface);
    box-shadow: var(--akf-shadow);
}
.card .card-header { background: transparent; border-bottom: 1px solid var(--akf-border); font-weight: 600; }
.akf-stat { border-radius: var(--akf-radius); }
.akf-stat .akf-stat-icon {
    width: 46px; height: 46px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.akf-stat .akf-stat-value { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.akf-stat .akf-stat-label { font-size: .78rem; color: var(--akf-text-muted); font-weight: 500; }

/* Tinted tiles */
.akf-tile { transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.akf-tile:hover { transform: translateY(-2px); box-shadow: var(--akf-shadow-lg); border-color: rgba(var(--akf-brand-rgb), .35); }

/* ---------- Tables ------------------------------------------------------- */
.table { --bs-table-bg: transparent; margin: 0; }
.table > thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--akf-text-muted); font-weight: 700; border-bottom: 1px solid var(--akf-border);
    background: var(--akf-surface-2); white-space: nowrap;
}
.table > tbody td { border-color: var(--akf-border); vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background: var(--akf-surface-2); }
.table code { color: var(--akf-brand-600); font-weight: 600; }
.akf-card-table { overflow: hidden; }
.akf-card-table .table > :not(caption) > * > * { padding-inline: 1rem; }

/* ---------- Forms -------------------------------------------------------- */
.form-control, .form-select {
    border-radius: var(--akf-radius-sm); border-color: var(--akf-border);
    background: var(--akf-surface); color: var(--bs-body-color);
}
.form-control:focus, .form-select:focus {
    border-color: var(--akf-brand); box-shadow: 0 0 0 .2rem rgba(var(--akf-brand-rgb), .18);
    background: var(--akf-surface);
}
.form-label { font-size: .82rem; font-weight: 600; margin-bottom: .3rem; }

/* ---------- Buttons ------------------------------------------------------ */
.btn { border-radius: var(--akf-radius-sm); font-weight: 600; }
.btn-success, .btn-primary { background: var(--akf-brand); border-color: var(--akf-brand); }
.btn-success:hover, .btn-primary:hover { background: var(--akf-brand-600); border-color: var(--akf-brand-600); }
.btn-outline-secondary { border-color: var(--akf-border); color: var(--bs-body-color); }
.btn-outline-secondary:hover { background: var(--akf-surface-2); border-color: var(--akf-brand); color: var(--akf-brand-600); }

/* ---------- Badges ------------------------------------------------------- */
.badge { font-weight: 600; border-radius: 999px; padding: .35em .7em; }

/* ---------- Empty state -------------------------------------------------- */
.akf-empty { text-align: center; padding: 3rem 1rem; color: var(--akf-text-muted); }
.akf-empty .bi { font-size: 2.5rem; opacity: .35; display: block; margin-bottom: .5rem; }

/* ---------- Toasts ------------------------------------------------------- */
.akf-toast-wrap { position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; }
.akf-toast {
    background: var(--akf-surface); border: 1px solid var(--akf-border);
    border-inline-start: 4px solid var(--akf-brand); border-radius: var(--akf-radius-sm);
    box-shadow: var(--akf-shadow-lg); padding: .75rem 1rem; min-width: 280px; max-width: 380px;
    display: flex; align-items: start; gap: .6rem; animation: akf-slide .25s ease;
}
.akf-toast.error { border-inline-start-color: #dc3545; }
@keyframes akf-slide { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive --------------------------------------------------- */
@media (max-width: 991.98px) {
    .akf-sidebar { transform: translateX(-100%); box-shadow: var(--akf-shadow-lg); }
    html[dir="rtl"] .akf-sidebar { transform: translateX(100%); }
    /* Higher specificity than html[dir=rtl] .akf-sidebar so the open state wins in RTL too. */
    .akf-sidebar.show,
    html[dir="rtl"] .akf-sidebar.show { transform: translateX(0); }
    .akf-content { margin-inline-start: 0; }
    .akf-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; }
}
