/* ============ الأساسيات ============ */
html, body {
    font-family: 'Cairo', Tahoma, sans-serif;
    background: var(--mud-palette-background);
    -webkit-tap-highlight-color: transparent;
}

*, .mud-typography, .mud-input, .mud-button-root, .mud-chip, .mud-tab, .mud-nav-link-text, .mud-table-cell, .mud-input-label {
    font-family: 'Cairo', Tahoma, sans-serif !important;
}

:root {
    --mwl-navy: #1A237E;
    --mwl-orange: #FF6D00;
    --mwl-card-shadow: 0 2px 10px rgba(20, 24, 60, .08);
    --mwl-radius: 18px;
    --tint-green: #E8F3EA;
    --tint-orange: #FDEBDC;
    --tint-red: #F8E1E1;
    --tint-blue: #E1ECF8;
    --tint-navy: #E6E7F1;
    --tint-yellow: #FFF6DC;
}

.dark {
    --mwl-card-shadow: 0 2px 10px rgba(0, 0, 0, .35);
    --tint-green: rgba(102, 187, 106, .16);
    --tint-orange: rgba(255, 158, 64, .16);
    --tint-red: rgba(239, 83, 80, .16);
    --tint-blue: rgba(100, 181, 246, .16);
    --tint-navy: rgba(140, 158, 255, .16);
    --tint-yellow: rgba(255, 183, 77, .14);
}

.mud-button-root, .mud-tab { text-transform: none !important; }
.muted { color: var(--mud-palette-text-secondary); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.fw-bold { font-weight: 700; }
.fw-800 { font-weight: 800; }
.text-success { color: var(--mud-palette-success) !important; }
.text-error { color: var(--mud-palette-error) !important; }
.text-warning { color: var(--mud-palette-warning) !important; }
.text-info { color: var(--mud-palette-info) !important; }
.text-primary { color: var(--mud-palette-primary) !important; }
.text-accent { color: var(--mud-palette-secondary) !important; }
.boot-loader { display: grid; place-items: center; min-height: 60vh; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 14px 14px 32px;
}

.has-bottom-nav .page-container { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
.has-fab .page-container { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }

/* ============ شريط التطبيق ============ */
.app-bar { box-shadow: 0 2px 8px rgba(10, 14, 50, .25) !important; }
.app-bar .mud-toolbar { gap: 4px; }
.app-bar-center { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 10px; }
.app-bar-title { font-weight: 700 !important; font-size: 1.2rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar-logo { width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, .25); }
.app-bar .end { display: flex; align-items: center; flex: none; }
@media (max-width: 420px) { .gen-chip { max-width: 30vw; } .app-bar-logo { width: 34px; height: 34px; } .app-bar-title { font-size: 1.05rem !important; } }

.gen-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 42vw;
    background: rgba(255, 255, 255, .14); color: #fff; border: 0; border-radius: 999px;
    padding: 4px 12px; font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
}
.gen-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ القائمة الجانبية ============ */
.drawer-head {
    background: linear-gradient(135deg, var(--mwl-navy), #283593);
    color: #fff; padding: 20px 16px 16px;
}
.drawer-head .brand { display: flex; align-items: center; gap: 12px; }
.drawer-head .brand img { width: 52px; height: 52px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255, 255, 255, .2); }
.drawer-head .brand-name { font-weight: 800; font-size: 1.25rem; }
.drawer-head .brand-sub { font-size: .8rem; opacity: .8; }
.drawer-user { margin-top: 12px; font-size: .85rem; opacity: .95; display: flex; align-items: center; gap: 6px; }
.drawer-gen { margin-top: 10px; }
.drawer-gen .mud-input { color: #fff !important; }
.nav-section { padding: 12px 20px 4px; font-size: .78rem; font-weight: 700; color: var(--mud-palette-text-secondary); }
.mud-nav-link { padding-block: 9px !important; border-radius: 12px; margin-inline: 8px; width: auto !important; }
.mud-nav-link .mud-nav-link-text { font-size: 1rem; }
.mud-nav-link.active { background: var(--tint-navy) !important; color: var(--mud-palette-primary) !important; font-weight: 700; }
.nav-logout { color: var(--mud-palette-error) !important; }

/* ============ الشريط السفلي ============ */
.bottom-nav {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1200;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-lines-default);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(20, 24, 60, .06);
}
.bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-decoration: none; color: var(--mud-palette-text-secondary);
    font-size: .8rem; padding: 4px 0;
}
.bottom-nav-item .mud-icon-root { font-size: 1.7rem; }
.bottom-nav-item.active { color: var(--mud-palette-primary); font-weight: 700; }

@media (min-width: 1280px) {
    .bottom-nav { display: none; }
    .has-bottom-nav .page-container { padding-bottom: 40px; }
}

/* ============ البطاقات ============ */
.card {
    background: var(--mud-palette-surface);
    border-radius: var(--mwl-radius);
    box-shadow: var(--mwl-card-shadow);
    padding: 16px;
}
.card + .card { margin-top: 14px; }
.card-title { font-weight: 800; font-size: 1.05rem; color: var(--mud-palette-primary); margin-bottom: 12px; }
.section-title { font-weight: 800; font-size: 1.15rem; margin: 18px 4px 10px; }

.hero {
    background: linear-gradient(135deg, var(--mwl-navy), #283593);
    color: #fff; border-radius: var(--mwl-radius); padding: 22px 20px;
    display: flex; align-items: center; gap: 16px; box-shadow: var(--mwl-card-shadow);
}
.hero img { width: 76px; height: 76px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255, 255, 255, .2); background: #EEECE4; }
.hero-title { font-size: 1.9rem; font-weight: 800; line-height: 1.3; }
.hero-sub { opacity: .8; }
.hero-meta { margin-top: 6px; font-size: .85rem; opacity: .85; display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* بطاقات الأرقام */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 14px; }
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 900px) { .stat-grid.four-lg { grid-template-columns: repeat(4, 1fr); } }
.stat {
    background: var(--mud-palette-surface); border-radius: var(--mwl-radius); box-shadow: var(--mwl-card-shadow);
    padding: 16px; min-width: 0;
}
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--mud-palette-text-secondary); font-size: .95rem; }
.stat-value { font-weight: 800; font-size: 1.45rem; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state-tile { text-align: center; padding: 16px 8px; }
.state-bubble { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px; font-weight: 800; font-size: 1.4rem; }
.state-tile .label { color: var(--mud-palette-text-secondary); }

/* الشرائح الملونة أعلى القوائم */
.chips-row { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips-row::-webkit-scrollbar { display: none; }
.tile {
    flex: 0 0 auto; min-width: 104px; border-radius: 14px; padding: 8px 14px; text-align: center; cursor: default;
    border: 2px solid transparent; background: var(--tint-navy);
}
.tile.clickable { cursor: pointer; }
.tile.selected { border-color: currentColor; }
.tile-value { font-weight: 800; font-size: 1.12rem; white-space: nowrap; }
.tile-label { font-size: .82rem; opacity: .85; }
.t-green { background: var(--tint-green); color: var(--mud-palette-success); }
.t-orange { background: var(--tint-orange); color: var(--mud-palette-warning); }
.t-red { background: var(--tint-red); color: var(--mud-palette-error); }
.t-blue { background: var(--tint-blue); color: var(--mud-palette-info); }
.t-navy { background: var(--tint-navy); color: var(--mud-palette-primary); }
.t-yellow { background: var(--tint-yellow); color: var(--mud-palette-warning); }

/* ============ عناصر القوائم ============ */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
    background: var(--mud-palette-surface); border-radius: var(--mwl-radius); box-shadow: var(--mwl-card-shadow);
    padding: 14px; display: flex; gap: 12px; align-items: center; min-width: 0;
}
a.item, .item.clickable { color: inherit; text-decoration: none; cursor: pointer; transition: transform .08s; }
a.item:active, .item.clickable:active { transform: scale(.99); }
.item-body { flex: 1 1 auto; min-width: 0; }
.item-title { font-weight: 700; font-size: 1.08rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--mud-palette-text-secondary); font-size: .9rem; line-height: 1.7; }
.item-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; text-align: end; }
.item-amount { font-weight: 800; white-space: nowrap; }
.item-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }

.avatar {
    width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex: none;
    font-weight: 800; font-size: 1.3rem; background: var(--tint-navy); color: var(--mud-palette-primary);
}
.avatar.round { border-radius: 50%; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.badge {
    display: inline-block; padding: 2px 10px; border-radius: 8px; font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.b-green { background: var(--tint-green); color: var(--mud-palette-success); }
.b-orange { background: var(--tint-orange); color: var(--mud-palette-warning); }
.b-red { background: var(--tint-red); color: var(--mud-palette-error); }
.b-blue { background: var(--tint-blue); color: var(--mud-palette-info); }
.b-navy { background: var(--tint-navy); color: var(--mud-palette-primary); }
.b-gray { background: var(--mud-palette-background-gray); color: var(--mud-palette-text-secondary); }

.action-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 10px; }
.action-bar a, .action-bar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit; font-size: .8rem;
    border: 0; background: transparent; text-decoration: none; cursor: pointer; padding: 4px 0; border-radius: 10px;
}
.action-bar a:hover, .action-bar button:hover { background: var(--mud-palette-background-gray); }

/* الوصول السريع */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 900px) { .quick-grid { grid-template-columns: repeat(6, 1fr); } }
.quick {
    display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 6px; border-radius: 14px;
    text-decoration: none; font-weight: 700; border: 1.5px solid currentColor; font-size: .95rem;
}

/* صفوف المعلومات */
.info-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.info-row .label { display: flex; align-items: center; gap: 8px; color: var(--mud-palette-text-secondary); min-width: 130px; }
.info-row .value { flex: 1; text-align: end; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.totals-band {
    background: var(--mwl-navy); color: #fff; border-radius: var(--mwl-radius); padding: 16px;
    display: grid; grid-template-columns: 1fr 1fr; box-shadow: var(--mwl-card-shadow);
}
.totals-band > div { text-align: center; }
.totals-band > div + div { border-inline-start: 1px solid rgba(255, 255, 255, .2); }
.totals-band .v { font-size: 1.5rem; font-weight: 800; }
.totals-band .l { opacity: .8; font-size: .9rem; }

.danger-band {
    background: linear-gradient(135deg, #C62828, #D32F2F); color: #fff; border-radius: var(--mwl-radius);
    padding: 18px; text-align: center; box-shadow: var(--mwl-card-shadow);
}
.danger-band .v { font-size: 2rem; font-weight: 800; }

.final-band {
    background: var(--mwl-navy); color: #fff; border-radius: var(--mwl-radius); padding: 16px 18px;
    display: flex; align-items: center; justify-content: space-between;
}
.final-band .v { font-size: 1.5rem; font-weight: 800; }

.summary-table { width: 100%; border-collapse: collapse; }
.summary-table td { padding: 8px 2px; }
.summary-table td:last-child { text-align: end; font-weight: 700; }
.summary-table tr.sep td { border-top: 1px solid var(--mud-palette-lines-default); }

/* زر الإضافة العائم */
.fab {
    position: fixed; inset-inline-end: 18px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 1100;
    background: var(--mwl-orange) !important; color: #fff !important; border-radius: 20px !important;
    min-width: 64px; height: 64px; box-shadow: 0 6px 18px rgba(255, 109, 0, .45) !important;
}
.no-bottom-nav .fab { bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (min-width: 1280px) { .fab { bottom: 28px; } }
.fab .mud-icon-root { font-size: 2rem; }
.fab-extended { padding-inline: 22px !important; font-weight: 700 !important; font-size: 1.05rem !important; }

.form-actions { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--mud-palette-background) 30%); z-index: 5; }
.btn-lg { height: 54px; font-size: 1.1rem !important; font-weight: 700 !important; border-radius: 14px !important; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 420px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

.empty-state { text-align: center; padding: 48px 16px; color: var(--mud-palette-text-secondary); }
.empty-state .mud-icon-root { font-size: 3.4rem; opacity: .5; }
.empty-text { margin-top: 8px; font-size: 1.05rem; }

.alert-item { border-inline-start: 5px solid var(--mud-palette-info); }
.alert-item.warning { border-inline-start-color: var(--mud-palette-warning); }
.alert-item.danger { border-inline-start-color: var(--mud-palette-error); }

.license-banner { border-radius: 14px; padding: 10px 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.license-banner a { margin-inline-start: auto; font-weight: 800; color: inherit; }

.photo-picker { width: 120px; height: 120px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; background: var(--tint-navy); color: var(--mud-palette-primary); overflow: hidden; cursor: pointer; text-align: center; font-size: .8rem; }
.photo-picker img { width: 100%; height: 100%; object-fit: cover; }

.table-wrap { overflow-x: auto; border-radius: 12px; }
.report-table { width: 100%; border-collapse: collapse; min-width: 560px; font-size: .92rem; }
.report-table th { background: var(--tint-navy); color: var(--mud-palette-primary); font-weight: 800; padding: 10px 8px; text-align: start; white-space: nowrap; }
.report-table td { padding: 10px 8px; border-bottom: 1px solid var(--mud-palette-lines-default); white-space: nowrap; }
.report-table tfoot td { font-weight: 800; background: var(--mud-palette-background-gray); }

.chart-legend { display: flex; gap: 24px; justify-content: center; margin-top: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 16px; height: 16px; border-radius: 5px; display: inline-block; }

.msg-preview { white-space: pre-wrap; background: var(--mud-palette-background-gray); border-radius: 12px; padding: 12px; font-size: .92rem; line-height: 1.8; }

/* ============ صفحات الدخول ============ */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px 18px; background: #F4F4F6; color: #1F2430; }
.auth-logo { width: 116px; height: 116px; border-radius: 50%; }
.auth-title { font-size: 2.3rem; font-weight: 800; color: #1A237E; margin-top: 18px; }
.auth-sub { color: #5F6473; margin-bottom: 26px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-field { position: relative; margin-bottom: 14px; }
.auth-field input {
    width: 100%; box-sizing: border-box; height: 56px; border: 1.5px solid #CDD1DE; border-radius: 14px; background: #fff;
    padding: 0 48px 0 48px; font: inherit; font-size: 1.05rem; color: #1F2430; outline: none; transition: border-color .15s;
}
.auth-field input:focus { border-color: #1A237E; }
.auth-field .ico { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: #4B5063; display: flex; }
.auth-field .eye { position: absolute; inset-inline-end: 10px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: #4B5063; cursor: pointer; display: flex; padding: 6px; }
.auth-field .eye.on { color: #1A237E; }
.auth-check { display: flex; align-items: center; gap: 10px; margin: 6px 4px 20px; font-size: 1.05rem; cursor: pointer; }
.auth-check input { width: 22px; height: 22px; accent-color: #1A237E; }
.auth-btn { width: 100%; height: 56px; border: 0; border-radius: 14px; background: #1A237E; color: #fff; font: inherit; font-size: 1.2rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 12px rgba(26, 35, 126, .3); }
.auth-btn:active { transform: translateY(1px); }
.auth-link { display: block; text-align: center; margin-top: 22px; color: #1A237E; font-weight: 800; text-decoration: none; }
.auth-link.muted { color: #5F6473; font-weight: 600; margin-top: 12px; }
.auth-error { background: #FDECEC; color: #B71C1C; border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 600; }
.auth-note { font-size: .85rem; color: #5F6473; text-align: center; margin-top: 10px; }
.auth-grid { display: grid; grid-template-columns: 1fr; gap: 0; }

.support-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.support-grid a { display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; font-weight: 700; font-size: .9rem; }
.support-grid .circle { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; }
.price-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.price-card { border-radius: 16px; padding: 16px; text-align: center; border: 2px solid var(--mud-palette-lines-default); background: var(--mud-palette-surface); }
.price-card.best { border-color: var(--mwl-orange); }
.price-card .p { font-size: 1.5rem; font-weight: 800; color: var(--mud-palette-primary); }

/* ============ الوصل والطباعة ============ */
.receipt {
    max-width: 380px; margin: 0 auto; background: #fff; color: #111; border-radius: 12px; padding: 18px 16px;
    box-shadow: var(--mwl-card-shadow); font-size: .95rem;
}
.receipt .head { text-align: center; border-bottom: 1px dashed #999; padding-bottom: 10px; margin-bottom: 10px; }
.receipt .head img { width: 64px; height: 64px; border-radius: 50%; }
.receipt .head .name { font-weight: 800; font-size: 1.2rem; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 4px 0; vertical-align: top; }
.receipt td:last-child { text-align: end; font-weight: 700; }
.receipt .total { border-top: 1px dashed #999; border-bottom: 1px dashed #999; font-size: 1.15rem; }
.receipt .foot { text-align: center; margin-top: 10px; color: #444; font-size: .85rem; }
.receipt .void { text-align: center; color: #C62828; font-weight: 800; border: 2px solid #C62828; border-radius: 8px; padding: 4px; margin-bottom: 8px; }

@media print {
    body * { visibility: hidden !important; }
    .print-area, .print-area * { visibility: visible !important; }
    .print-area { position: absolute; inset: 0 auto auto 0; width: 100%; }
    .receipt { box-shadow: none; border-radius: 0; max-width: none; padding: 0; }
    body[data-paper="t58"] .receipt { font-size: 11px; }
    body[data-paper="t80"] .receipt { font-size: 12.5px; }
    .mud-appbar, .bottom-nav, .fab { display: none !important; }
}

.text-center { text-align: center; }
.chart-box { direction: ltr; padding-left: 26px; }
.chart-box svg { overflow: visible; }
