:root {
    --emerald: #059669;
    --emerald-dark: #047857;
    --emerald-soft: #ecfdf5;
    --teal: #0f766e;
    --teal-dark: #022c22;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --danger: #e11d48;
    --danger-soft: #fff1f2;
    --amber: #d97706;
    --amber-soft: #fffbeb;
    --orange: #f97316;
    --blue: #2563eb;
    --blue-soft: #eff6ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Cairo', 'Tajawal', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at 12% 15%, rgba(16, 185, 129, 0.08), transparent 40%),
                radial-gradient(circle at 88% 85%, rgba(249, 115, 22, 0.06), transparent 40%),
                var(--bg);
    color: var(--text);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.6;
}

.hidden { display: none !important; }

/* Login Screen */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: radial-gradient(circle at 15% 20%, rgba(16, 185, 129, 0.18), transparent 45%),
                radial-gradient(circle at 85% 80%, rgba(15, 118, 110, 0.16), transparent 45%),
                linear-gradient(135deg, #f0fdf4 0%, #fffbeb 50%, #f0fdf4 100%);
}

.login-card {
    width: 100%;
    max-width: 430px;
    background: var(--surface);
    border: 1.5px solid #d1fae5;
    border-radius: 1.5rem;
    padding: 2.25rem 1.75rem;
    box-shadow: 0 24px 50px rgba(6, 78, 59, 0.12);
    text-align: center;
}

.login-logo {
    width: 82px;
    height: 82px;
    border-radius: 1.25rem;
    object-fit: contain;
    border: 2px solid #a7f3d0;
    margin: 0 auto 1rem;
    display: block;
    background: #fff;
    padding: 4px;
}

.login-title { font-size: 1.35rem; font-weight: 900; color: #064e3b; margin-bottom: 0.2rem; }
.login-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 1.5rem; font-weight: 600; }

/* Header */
.topbar {
    background: linear-gradient(135deg, #022c22 0%, #064e3b 50%, #0f766e 100%);
    color: #fff;
    padding: 0.85rem 1.25rem;
    box-shadow: 0 4px 20px rgba(2, 44, 34, 0.16);
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.brand-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 0.85rem;
    background: #fff;
    padding: 3px;
    object-fit: contain;
    border: 2px solid rgba(255, 255, 255, 0.35);
}

.brand-title { font-size: 1.05rem; font-weight: 900; line-height: 1.25; }
.brand-sub { font-size: 0.75rem; color: #a7f3d0; font-weight: 700; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.branch-pill {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.24);
    color: #fff;
    padding: 0.38rem 0.85rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* Main Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem;
}

/* Tabs (Admin) */
.nav-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.tab-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    padding: 0.55rem 1.1rem;
    border-radius: 0.85rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    transition: all 0.2s ease;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--emerald), var(--teal));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.22);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.15rem;
    padding: 1rem 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.03);
}

.kpi-icon {
    width: 46px;
    height: 46px;
    border-radius: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.kpi-icon.emerald { background: var(--emerald-soft); color: var(--emerald); }
.kpi-icon.amber { background: var(--amber-soft); color: var(--amber); }
.kpi-icon.blue { background: var(--blue-soft); color: var(--blue); }

.kpi-label { font-size: 0.76rem; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 1.45rem; font-weight: 900; color: var(--text); line-height: 1.2; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 1.25rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
    margin-bottom: 1.25rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 900;
    color: #064e3b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Form Controls */
.form-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0.85rem;
}

.col-12 { grid-column: span 12; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

@media (max-width: 768px) {
    .col-6, .col-4, .col-3 { grid-column: span 12; }
}

.field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 800;
    color: #334155;
    margin-bottom: 0.35rem;
}

.input, .select {
    width: 100%;
    padding: 0.68rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: 0.85rem;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text);
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus, .select:focus {
    outline: none;
    border-color: var(--emerald);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14);
}

/* Quantity Stepper */
.qty-wrap {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

.qty-wrap .input {
    text-align: center;
    font-size: 1.05rem;
    font-weight: 900;
}

.step-btn {
    border: 1.5px solid #d1fae5;
    background: #ecfdf5;
    color: #047857;
    font-family: inherit;
    font-weight: 900;
    font-size: 0.8rem;
    padding: 0 0.65rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
}

.step-btn:hover { background: #d1fae5; }

/* Quick Item Chips */
.chips-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.55rem;
}

.chip-btn {
    border: 1px solid #d1fae5;
    background: #f0fdf4;
    color: #065f46;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 800;
    padding: 0.28rem 0.68rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s;
}

.chip-btn:hover, .chip-btn.active {
    background: var(--emerald);
    color: #fff;
    border-color: var(--emerald);
}

/* Buttons */
.btn {
    border: none;
    border-radius: 0.85rem;
    padding: 0.65rem 1.15rem;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--emerald), var(--teal));
    color: #fff;
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.22);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(5, 150, 105, 0.3); }

.btn-ghost {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.24); }

.btn-outline {
    background: #fff;
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-outline:hover { border-color: var(--emerald); color: var(--emerald); }

.btn-danger-soft {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
}

.btn-blue-soft {
    background: var(--blue-soft);
    color: var(--blue);
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
}

/* Filters Bar */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 1rem;
}

.range-pills {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.range-pill {
    border: 1px solid var(--border);
    background: #f8fafc;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    cursor: pointer;
}

.range-pill.active {
    background: #064e3b;
    color: #fff;
    border-color: #064e3b;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

thead th {
    background: #f0fdf4;
    color: #064e3b;
    font-weight: 900;
    text-align: right;
    padding: 0.75rem 0.85rem;
    border-bottom: 1.5px solid #d1fae5;
    white-space: nowrap;
}

tbody td {
    padding: 0.72rem 0.85rem;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 600;
    vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }

.qty-badge {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-weight: 900;
    display: inline-block;
    white-space: nowrap;
}

.branch-tag {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

/* Branch Summary Grid (Admin) */
.branches-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.branch-stat-card {
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 1rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.branch-stat-card:hover, .branch-stat-card.active {
    border-color: var(--emerald);
    background: #f0fdf4;
    transform: translateY(-2px);
}

.branch-stat-name { font-size: 0.86rem; font-weight: 900; color: #064e3b; margin-bottom: 0.25rem; }
.branch-stat-nums { font-size: 0.76rem; color: var(--muted); font-weight: 700; display: flex; justify-content: space-between; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 60;
}

.modal-box {
    background: #fff;
    border-radius: 1.25rem;
    width: 100%;
    max-width: 440px;
    padding: 1.5rem;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.22);
}

.modal-title { font-size: 1.05rem; font-weight: 900; color: #064e3b; margin-bottom: 1rem; }

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: #064e3b;
    color: #fff;
    padding: 0.7rem 1.3rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(2, 44, 34, 0.28);
    z-index: 80;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.error { background: var(--danger); }

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
    font-weight: 700;
}

.footer-note {
    text-align: center;
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 700;
    margin-top: 1.5rem;
}

/* Print A4 */
@media print {
    @page { size: A4 portrait; margin: 10mm; }
    body { background: #fff !important; }
    .no-print { display: none !important; }
    .card { box-shadow: none !important; border: 1.5px solid #0f766e !important; }
    .print-header { display: flex !important; align-items: center; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 10px; margin-bottom: 14px; }
}

.print-header { display: none; }
