/* =============================================
   المحاسب الوافي برو - Material 3 Design
   ============================================= */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --primary: #1a5276;
    --primary-dark: #154360;
    --primary-light: #2980b9;
    --accent: #f39c12;
    --accent-dark: #d68910;
    --success: #27ae60;
    --success-light: #d4efdf;
    --danger: #e74c3c;
    --danger-light: #fadbd8;
    --warning: #f39c12;
    --warning-light: #fef9e7;
    --info: #2980b9;
    --info-light: #d6eaf8;
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #ecf0f1;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --nav-height: 64px;
    --bottom-nav: 68px;
}

body {
    font-family: 'Segoe UI', 'SF Pro', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: block; }

/* ============ SPLASH SCREEN ============ */
.splash-screen {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    display: flex; align-items: center; justify-content: center; z-index: 9999;
    animation: fadeOut 0.5s ease 2.5s forwards;
}
.splash-content { text-align: center; color: #fff; }
.splash-logo { margin-bottom: 20px; animation: scaleIn 0.6s ease; }
.splash-title { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.splash-sub { font-size: 14px; opacity: 0.8; }
.splash-loader { margin-top: 30px; width: 200px; height: 4px; background: rgba(255,255,255,0.2); border-radius: 4px; overflow: hidden; }
.loader-bar { height: 100%; background: var(--accent); border-radius: 4px; animation: loadBar 2s ease forwards; }

@keyframes loadBar { from { width: 0; } to { width: 100%; } }
@keyframes scaleIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; pointer-events: none; } }

/* ============ LOGIN SCREEN ============ */
.login-bg {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-card {
    background: var(--card); border-radius: 24px; padding: 36px 28px; width: 100%; max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 30px; }
.login-header h2 { margin-top: 16px; font-size: 22px; color: var(--primary); }
.login-header p { color: var(--text-light); font-size: 14px; margin-top: 6px; }
.input-field {
    position: relative; margin-bottom: 16px;
}
.input-field .input-icon {
    position: absolute; right: 14px; top: 50%; transform: translateY(-50%); z-index: 1;
}
.input-field input {
    width: 100%; padding: 14px 44px 14px 14px; border: 2px solid var(--border); border-radius: 12px;
    font-size: 15px; transition: all 0.2s; background: #f8f9fa;
}
.input-field input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(26,82,118,0.1); }
.btn-login {
    width: 100%; padding: 14px; background: var(--primary); color: #fff; border: none; border-radius: 12px;
    font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.2s; margin-top: 8px;
}
.btn-login:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(26,82,118,0.3); }
.btn-login:active { transform: translateY(0); }
.login-error { color: var(--danger); text-align: center; margin-top: 12px; font-size: 13px; }

/* ============ APP BAR ============ */
.app-bar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--nav-height);
    background: var(--primary); color: #fff; display: flex; align-items: center;
    padding: 0 16px; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.menu-btn { background: none; border: none; color: #fff; cursor: pointer; padding: 8px; border-radius: 50%; }
.menu-btn:hover { background: rgba(255,255,255,0.1); }
.app-bar-title { flex: 1; margin-right: 12px; }
.app-bar-title span { font-size: 18px; font-weight: 600; }
.app-bar-action { background: none; border: none; color: #fff; cursor: pointer; padding: 8px; border-radius: 50%; position: relative; }
.notif-badge {
    position: absolute; top: 2px; left: 2px; background: var(--danger); color: #fff;
    font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: flex;
    align-items: center; justify-content: center; font-weight: 600;
}

/* ============ DRAWER ============ */
.drawer-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5);
    z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.drawer-overlay.active { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: -300px; width: 300px; height: 100%; background: #fff;
    z-index: 201; transition: right 0.3s ease; overflow-y: auto; display: flex; flex-direction: column;
}
.drawer.active { right: 0; }
.drawer-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 24px 20px; color: #fff; display: flex; align-items: center; gap: 14px;
}
.drawer-avatar { flex-shrink: 0; }
.drawer-name { font-size: 16px; font-weight: 600; }
.drawer-role { font-size: 12px; opacity: 0.8; margin-top: 2px; }
.drawer-menu { flex: 1; padding: 8px 0; }
.drawer-section-title {
    padding: 16px 20px 6px; font-size: 11px; color: var(--text-light);
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.drawer-item {
    display: flex; align-items: center; gap: 14px; padding: 12px 20px; color: var(--text);
    text-decoration: none; font-size: 14px; transition: all 0.15s; border-right: 3px solid transparent;
}
.drawer-item:hover { background: #f0f4f8; }
.drawer-item.active { background: rgba(26,82,118,0.08); color: var(--primary); border-right-color: var(--primary); font-weight: 600; }
.drawer-item svg { flex-shrink: 0; }
.drawer-footer { border-top: 1px solid var(--border); padding: 8px 0; }

/* ============ MAIN CONTENT ============ */
.main-content {
    margin-top: var(--nav-height); padding: 16px; padding-bottom: calc(var(--bottom-nav) + 20px);
    min-height: calc(100vh - var(--nav-height));
}

/* ============ PAGES ============ */
.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ============ HOME PAGE ============ */
.home-header { margin-bottom: 20px; }
.home-greeting h2 { font-size: 22px; color: var(--text); }
.home-greeting p { color: var(--text-light); font-size: 13px; margin-top: 4px; }

/* Quick Actions Grid */
.quick-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px;
}
.quick-card {
    background: var(--card); border-radius: var(--radius); padding: 18px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    cursor: pointer; transition: all 0.2s; box-shadow: var(--shadow);
}
.quick-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.quick-card:active { transform: scale(0.96); }
.quick-icon {
    width: 50px; height: 50px; border-radius: 14px; display: flex;
    align-items: center; justify-content: center;
}
.quick-label { font-size: 11px; font-weight: 600; text-align: center; color: var(--text); line-height: 1.3; }

/* Stats Row */
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; padding: 0 4px; }
.stats-row {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 24px;
}
.stat-card {
    background: var(--card); border-radius: var(--radius-sm); padding: 16px;
    box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px;
}
.stat-icon-box {
    width: 44px; height: 44px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; font-size: 20px;
}
.stat-value { font-size: 18px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* Chart Cards */
.chart-cards { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 24px; }
.chart-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chart-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.chart-body { padding: 16px; min-height: 100px; }

/* Bar Chart */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 100px; }
.bar { width: 18px; border-radius: 4px 4px 0 0; transition: height 0.6s ease; min-height: 4px; }
.bar.sales { background: linear-gradient(to top, var(--primary), var(--primary-light)); }
.bar.purchases { background: linear-gradient(to top, var(--accent-dark), var(--accent)); }
.bar-label { font-size: 10px; color: var(--text-light); }

/* Donut Chart */
.donut-chart { display: flex; align-items: center; gap: 16px; }
.donut-svg { width: 100px; height: 100px; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Activity List */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item {
    background: var(--card); border-radius: var(--radius-sm); padding: 14px 16px;
    display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.activity-icon {
    width: 40px; height: 40px; border-radius: 10px; display: flex;
    align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.activity-info { flex: 1; min-width: 0; }
.activity-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-sub { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.activity-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }

/* ============ PAGE TOOLBAR ============ */
.page-toolbar {
    display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center;
}
.toolbar-search {
    flex: 1; min-width: 150px; padding: 10px 16px; border: 2px solid var(--border);
    border-radius: 12px; font-size: 14px; background: var(--card);
}
.toolbar-search:focus { outline: none; border-color: var(--primary); }
.toolbar-btn {
    padding: 10px 18px; border: none; border-radius: 12px; font-size: 13px;
    font-weight: 600; cursor: pointer; transition: all 0.2s; white-space: nowrap;
    background: var(--card); color: var(--text); border: 1.5px solid var(--border);
}
.toolbar-btn:hover { background: #f0f4f8; }
.toolbar-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.toolbar-btn.primary:hover { background: var(--primary-dark); }
.toolbar-btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.toolbar-btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.toolbar-btn.info { background: var(--info); color: #fff; border-color: var(--info); }

/* ============ CARDS & LISTS ============ */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

.list-container { padding: 0; }
.list-item {
    padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex;
    align-items: center; gap: 12px; cursor: pointer; transition: background 0.15s;
}
.list-item:hover { background: #f8f9fa; }
.list-item:last-child { border-bottom: none; }
.list-item-icon {
    width: 42px; height: 42px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.list-item-trail { text-align: left; flex-shrink: 0; }
.list-item-amount { font-size: 14px; font-weight: 700; }
.list-item-badge { margin-top: 4px; }

/* Entity Cards (Cashboxes, Banks, Warehouses) */
.entity-card {
    background: var(--card); border-radius: var(--radius); padding: 18px;
    box-shadow: var(--shadow); transition: all 0.2s; cursor: pointer;
}
.entity-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.entity-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.entity-card-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.entity-card-name { font-size: 15px; font-weight: 700; }
.entity-card-sub { font-size: 12px; color: var(--text-light); }
.entity-card-amount { font-size: 22px; font-weight: 800; color: var(--primary); }
.entity-card-currency { font-size: 12px; color: var(--text-light); }

/* Tree View */
.tree-view { padding: 8px 0; }
.tree-item {
    padding: 10px 18px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background 0.15s;
}
.tree-item:hover { background: #f8f9fa; }
.tree-toggle { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-light); }
.tree-icon { font-size: 18px; }
.tree-code { font-size: 12px; color: var(--primary); font-weight: 700; min-width: 55px; }
.tree-name { flex: 1; font-size: 13px; font-weight: 500; }
.tree-balance { font-size: 13px; font-weight: 700; }
.tree-children { padding-right: 24px; }

/* Reports Grid */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.report-card {
    background: var(--card); border-radius: var(--radius); padding: 18px;
    display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
    cursor: pointer; transition: all 0.2s;
}
.report-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.report-icon { width: 50px; height: 50px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.report-info h3 { font-size: 14px; font-weight: 700; }
.report-info p { font-size: 12px; color: var(--text-light); margin-top: 3px; }

/* Report Result */
.report-result {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    margin-top: 16px; overflow: hidden;
}
.report-result-header { padding: 14px 18px; background: var(--primary); color: #fff; font-weight: 700; font-size: 15px; }
.report-result-body { padding: 16px 18px; }
.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td { padding: 10px 12px; text-align: right; font-size: 13px; border-bottom: 1px solid var(--border); }
.report-table th { background: #f8f9fa; font-weight: 600; color: var(--text-light); font-size: 12px; }
.report-table .total-row { font-weight: 700; background: #eef5fc; color: var(--primary); }

/* ============ BOTTOM NAV ============ */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottom-nav);
    background: var(--card); display: flex; align-items: center; justify-content: space-around;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08); z-index: 100;
}
.bottom-item {
    display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 12px;
    color: var(--text-light); text-decoration: none; font-size: 10px; font-weight: 500;
    transition: color 0.2s; position: relative;
}
.bottom-item.active { color: var(--primary); }
.bottom-item.active::before {
    content: ''; position: absolute; top: -2px; width: 30px; height: 3px;
    background: var(--primary); border-radius: 0 0 4px 4px;
}
.bottom-fab {
    width: 52px; height: 52px; background: var(--primary); border-radius: 16px;
    display: flex; align-items: center; justify-content: center; margin-top: -20px;
    box-shadow: 0 4px 12px rgba(26,82,118,0.3);
}
.bottom-fab:hover { background: var(--primary-dark); }

/* ============ FAB ============ */
.fab {
    position: fixed; bottom: calc(var(--bottom-nav) + 16px); left: 16px;
    width: 56px; height: 56px; background: var(--primary); border-radius: 16px;
    display: flex; align-items: center; justify-content: center; border: none;
    box-shadow: var(--shadow-lg); cursor: pointer; z-index: 90;
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4);
    z-index: 300; display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-sheet {
    background: var(--card); border-radius: 24px 24px 0 0; width: 100%; max-width: 500px;
    max-height: 85vh; overflow-y: auto; animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 36px; height: 4px; background: #ddd; border-radius: 4px; margin: 12px auto 0; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close-btn { background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-light); }
.modal-body { padding: 20px; }

/* Form in Modal */
.modal-body .form-group { margin-bottom: 14px; }
.modal-body label { display: block; font-size: 13px; font-weight: 600; color: var(--text-light); margin-bottom: 6px; }
.modal-body input, .modal-body select, .modal-body textarea {
    width: 100%; padding: 12px 14px; border: 2px solid var(--border); border-radius: 10px;
    font-size: 14px; font-family: inherit; transition: border 0.2s; background: #f8f9fa;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
    outline: none; border-color: var(--primary); background: #fff;
}
.modal-body .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-body .btn-save {
    width: 100%; padding: 14px; background: var(--primary); color: #fff; border: none;
    border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 8px;
}
.modal-body .btn-save:hover { background: var(--primary-dark); }

/* ============ TOAST ============ */
.toast {
    position: fixed; bottom: calc(var(--bottom-nav) + 16px); left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--text); color: #fff; padding: 12px 24px; border-radius: 12px;
    font-size: 14px; font-weight: 500; z-index: 400; opacity: 0; transition: all 0.3s;
    box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============ BADGES ============ */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-success { background: var(--success-light); color: #1a6b3c; }
.badge-danger { background: var(--danger-light); color: #922b21; }
.badge-warning { background: var(--warning-light); color: #7d6608; }
.badge-info { background: var(--info-light); color: #1a5276; }
.badge-primary { background: #dbeafe; color: var(--primary); }

/* ============ SETTINGS ============ */
.settings-container .settings-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.settings-card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15px; }
.settings-card-body { padding: 18px; }

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 14px; }

/* ============ RESPONSIVE ============ */
@media (min-width: 768px) {
    .quick-grid { grid-template-columns: repeat(4, 1fr); }
    .stats-row { grid-template-columns: repeat(4, 1fr); }
    .chart-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .quick-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .quick-card { padding: 14px 6px; }
    .quick-icon { width: 42px; height: 42px; }
    .quick-label { font-size: 10px; }
    .main-content { padding: 12px; }
    .modal-body .form-row { grid-template-columns: 1fr; }
}
