/* ==========================================================
   App Shell — Modern Mobile-First Layout
   - Sidebar drawer (RTL/LTR aware via CSS logical properties)
   - Bottom nav for mobile
   - Card-based UI
   ========================================================== */

:root {
    --primary: #d4a574;
    --accent:  #f59e0b;
    --sidebar-bg:   #1f2937;
    --sidebar-text: #e5e7eb;
    --sidebar-hover:#374151;
    --sidebar-w: 260px;

    --bg:      #f3f4f6;
    --surface: #ffffff;
    --text:    #1f2937;
    --muted:   #6b7280;
    --border:  #e5e7eb;

    --success: #10b981;
    --warning: #f59e0b;
    --danger:  #ef4444;
    --info:    #3b82f6;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.08), 0 4px 10px rgba(0,0,0,.05);

    --header-h: 60px;
    --bottomnav-h: 64px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Cairo", "Tahoma", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell { min-height: 100vh; }

/* ============================================================
   TOP HEADER
   ============================================================ */
.app-header {
    position: fixed;
    top: 0;
    inset-inline-start: var(--sidebar-w);
    inset-inline-end: 0;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    z-index: 50;
    box-shadow: var(--shadow);
}
.sidebar-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 22px; color: var(--text);
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    display: none; align-items: center; justify-content: center;
}
.sidebar-toggle:hover { background: var(--bg); }
.app-header h1.page-title {
    margin: 0; font-size: 18px; font-weight: 600;
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions .btn-icon {
    width: 40px; height: 40px;
    background: var(--bg); border: none; border-radius: 50%;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.header-actions .btn-icon:hover { background: var(--border); }
.user-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-weight: 600; font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; border: none;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.app-sidebar {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 100;
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.sidebar-header {
    padding: 18px 20px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-logo {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 20px; color: #fff;
    flex-shrink: 0;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.sidebar-brand { flex: 1; min-width: 0; }
.sidebar-brand .name { font-weight: 700; font-size: 15px; color: #fff;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-brand .tagline { font-size: 11px; opacity: .65; }
.sidebar-close {
    background: none; border: none; color: var(--sidebar-text);
    font-size: 22px; cursor: pointer; padding: 4px 8px;
    display: none;
}

.sidebar-nav {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 12px 8px 12px;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }
.nav-group { margin-bottom: 6px; }
.nav-group-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: .5;
    padding: 14px 14px 6px;
    font-weight: 600;
}
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all .15s;
    margin: 1px 0;
    font-size: 14px;
}
.nav-item i { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; opacity: .85; }
.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}
.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-weight: 600;
    box-shadow: 0 2px 8px rgba(212,165,116,.3);
}
.nav-item.active i { opacity: 1; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
}
.sidebar-user .avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 600; font-size: 14px;
}
.sidebar-user .info { flex: 1; min-width: 0; }
.sidebar-user .info .name { color: #fff; font-size: 13px; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .info .role { font-size: 11px; opacity: .65; }
.sidebar-user .logout {
    color: var(--sidebar-text); padding: 6px; border-radius: 6px;
    text-decoration: none;
}
.sidebar-user .logout:hover { background: rgba(239,68,68,.15); color: #fff; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.app-main {
    margin-inline-start: var(--sidebar-w);
    padding-top: var(--header-h);
    min-height: 100vh;
}
.app-content { padding: 20px; }

/* ============================================================
   BACKDROP (mobile)
   ============================================================ */
.sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

/* ============================================================
   BOTTOM NAV (mobile only)
   ============================================================ */
.app-bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottomnav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
}
.app-bottom-nav .bottom-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    color: var(--muted);
    text-decoration: none;
    font-size: 11px;
    padding: 8px 4px;
    transition: color .15s;
}
.app-bottom-nav .bottom-item i { font-size: 22px; }
.app-bottom-nav .bottom-item.active { color: var(--primary); }
.app-bottom-nav .bottom-item:hover { color: var(--primary); }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */
@media (max-width: 991px) {
    .sidebar-toggle, .sidebar-close { display: inline-flex; }
    .app-header { inset-inline-start: 0; }
    .app-main { margin-inline-start: 0; }
    .app-sidebar { transform: translateX(-100%); transition: transform .25s; }
    html[dir="rtl"] .app-sidebar { transform: translateX(100%); }
    .app-sidebar.open { transform: translateX(0) !important; }
    .app-bottom-nav { display: flex; }
    .app-main { padding-bottom: calc(var(--bottomnav-h) + 20px); }
}

/* ============================================================
   CARDS & UI ELEMENTS — App style
   ============================================================ */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--surface);
}
.card-header {
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all .15s;
    border: 1px solid transparent;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none; color: #fff;
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent), var(--primary));
    color: #fff; transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(212,165,116,.3);
}
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* Stat cards — supports both old (.blue/.green) and new (.stat-blue/.stat-green) naming */
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform .15s;
    position: relative;
    overflow: hidden;
    color: var(--text);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon-box {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 24px; color: #fff;
    margin-bottom: 12px;
}
.stat-card .stat-label, .stat-card .label { font-size: 13px; color: var(--muted); opacity: .9; }
.stat-card .stat-value, .stat-card .value { font-size: 28px; font-weight: 700; margin: 4px 0; }

/* Colored variants (gradients with white text) — used in admin dashboard */
.stat-card.blue,   .stat-card.stat-blue   { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; }
.stat-card.green,  .stat-card.stat-green  { background: linear-gradient(135deg, #10b981, #047857); color: #fff; }
.stat-card.orange, .stat-card.stat-orange { background: linear-gradient(135deg, #f59e0b, #b45309); color: #fff; }
.stat-card.red,    .stat-card.stat-red    { background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; }

.stat-card.blue .stat-label,   .stat-card.stat-blue .stat-label,
.stat-card.green .stat-label,  .stat-card.stat-green .stat-label,
.stat-card.orange .stat-label, .stat-card.stat-orange .stat-label,
.stat-card.red .stat-label,    .stat-card.stat-red .stat-label,
.stat-card.blue .label,   .stat-card.stat-blue .label,
.stat-card.green .label,  .stat-card.stat-green .label,
.stat-card.orange .label, .stat-card.stat-orange .label,
.stat-card.red .label,    .stat-card.stat-red .label { color: rgba(255,255,255,.9); opacity: 1; }

.stat-card .stat-icon {
    position: absolute;
    font-size: 80px;
    opacity: 0.15;
    top: 50%;
    transform: translateY(-50%);
}
html[dir="rtl"] .stat-card .stat-icon { left: 20px; }
html[dir="ltr"] .stat-card .stat-icon { right: 20px; }

/* Tables on mobile become card lists */
.table { border-collapse: separate; border-spacing: 0; }
.table thead th {
    background: #f9fafb; font-size: 12px;
    text-transform: uppercase; letter-spacing: .5px;
    color: var(--muted); font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.table tbody td { padding: 14px 12px; vertical-align: middle; }

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(var(--bottomnav-h) + 18px);
    inset-inline-end: 18px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    box-shadow: 0 6px 16px rgba(212,165,116,.4);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 28px;
    border: none;
    z-index: 49;
    text-decoration: none;
}
.fab:hover { transform: scale(1.05); color: #fff; }
@media (min-width: 992px) {
    .fab { bottom: 24px; }
}

/* Form inputs more touch-friendly */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    padding: 10px 14px;
    font-size: 15px;
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212,165,116,.15);
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
}

/* Public pages (without app shell) */
.public-only { min-height: 100vh; }
