/* === FALYUM COST SYSTEM - CSS === */
:root {
    --primary: #0d7c4a;
    --primary-light: #10a760;
    --primary-dark: #095c37;
    --gold: #d4a847;
    --gold-light: #f0d078;
    --bg: #f4f6f9;
    --bg-card: #ffffff;
    --bg-sidebar: #0a1628;
    --text: #1a2332;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,.12);
    --transition: .25s cubic-bezier(.4,0,.2,1);
    --sidebar-w: 260px;
    --topbar-h: 64px;
    --font: 'Cairo', 'Tajawal', sans-serif;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #020617;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
    --shadow-lg: 0 4px 24px rgba(0,0,0,.4);
}

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

html { font-size: 15px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    direction: rtl;
    transition: background var(--transition), color var(--transition);
}

/* === SIDEBAR === */
.sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-sidebar);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    border-left: 1px solid rgba(255,255,255,.06);
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-close { display: none; background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; }

.logo { display: flex; align-items: center; gap: 12px; }

.logo-icon {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, var(--primary), var(--gold));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 1.3rem; color: #fff;
    box-shadow: 0 2px 12px rgba(13,124,74,.4);
}

.logo-text { display: flex; flex-direction: column; }
.logo-name { color: #fff; font-weight: 800; font-size: 1.2rem; line-height: 1.2; }
.logo-sub { color: var(--gold); font-size: .65rem; letter-spacing: 2px; font-weight: 600; }

.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.6);
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition);
    font-size: .95rem;
}

.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }

.nav-item.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(13,124,74,.3), rgba(212,168,71,.1));
    border: 1px solid rgba(13,124,74,.3);
}

.nav-icon { font-size: 1.15rem; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.theme-toggle {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,.5);
    cursor: pointer;
    transition: all var(--transition);
    font-size: .9rem;
}
.theme-toggle:hover { color: #fff; background: rgba(255,255,255,.06); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 99;
    backdrop-filter: blur(4px);
}

/* === MAIN CONTENT === */
.main-content {
    margin-right: var(--sidebar-w);
    min-height: 100vh;
    transition: margin var(--transition);
}

.topbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--topbar-h);
    background: rgba(244,246,249,.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 28px;
}

[data-theme="dark"] .topbar { background: rgba(15,23,42,.85); }

.menu-toggle {
    display: none; background: none; border: none;
    font-size: 1.4rem; cursor: pointer; color: var(--text);
    padding: 4px 8px; border-radius: 6px;
}
.menu-toggle:hover { background: var(--border); }

.page-title { font-size: 1.25rem; font-weight: 700; flex: 1; }

.pages-container { padding: 24px 28px; }

.page { display: none; animation: fadeIn .3s ease; }
.page.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* === STATS === */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-icon { font-size: 2rem; width: 56px; height: 56px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.stat-card-1 .stat-icon { background: linear-gradient(135deg, rgba(13,124,74,.1), rgba(13,124,74,.2)); }
.stat-card-2 .stat-icon { background: linear-gradient(135deg, rgba(212,168,71,.1), rgba(212,168,71,.2)); }
.stat-card-3 .stat-icon { background: linear-gradient(135deg, rgba(59,130,246,.1), rgba(59,130,246,.2)); }
.stat-card-4 .stat-icon { background: linear-gradient(135deg, rgba(168,85,247,.1), rgba(168,85,247,.2)); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stat-label { font-size: .8rem; color: var(--text-secondary); font-weight: 500; }

/* === CARDS === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: box-shadow var(--transition);
}

.card-header {
    padding: 18px 22px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 10px;
}
.card-header h2 { font-size: 1.05rem; font-weight: 700; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card-body { padding: 22px; }

.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* === BUTTONS === */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-weight: 600; font-size: .9rem;
    cursor: pointer; border: none;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-sm { padding: 7px 14px; font-size: .82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; box-shadow: 0 2px 8px rgba(13,124,74,.3); }
.btn-primary:hover { box-shadow: 0 4px 16px rgba(13,124,74,.4); transform: translateY(-1px); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--text-muted); color: #fff; }

.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: rgba(13,124,74,.06); border-color: var(--primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* === FORMS === */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--text-secondary); }

.form-input {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .92rem;
    color: var(--text);
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,124,74,.1); }

.search-input { min-width: 180px; }
.filter-select { min-width: 140px; }

/* === DATA TABLE === */
.table-responsive { overflow-x: auto; padding: 0; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 12px 14px; font-size: .8rem; font-weight: 700; color: var(--text-secondary); text-align: right; background: var(--bg); border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(13,124,74,.03); }

.data-table input {
    width: 100%; padding: 7px 10px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-family: var(--font);
    font-size: .88rem;
    color: var(--text);
    background: var(--bg-card);
    outline: none;
    transition: border-color var(--transition);
}
.data-table input:focus { border-color: var(--primary); }
.data-table input[type="number"] { text-align: center; }

.col-num { width: 45px; text-align: center !important; }
.col-name { min-width: 200px; }
.col-qty, .col-price, .col-cost { width: 90px; text-align: center !important; }
.col-notes { min-width: 100px; }
.col-actions { width: 50px; text-align: center !important; }

.cost-display { font-weight: 700; color: var(--primary); text-align: center; padding: 7px; }

.delete-item-btn {
    background: none; border: none; cursor: pointer;
    font-size: 1.1rem; color: var(--danger);
    padding: 4px 8px; border-radius: 6px;
    transition: background var(--transition);
}
.delete-item-btn:hover { background: rgba(239,68,68,.1); }

.total-row { background: var(--bg) !important; }
.total-label { text-align: left !important; font-weight: 800; font-size: 1rem; color: var(--primary); }
.total-value { font-weight: 800; font-size: 1.1rem; color: var(--primary); text-align: center !important; }

/* === COST CALCULATOR === */
.calc-grid { display: flex; flex-direction: column; gap: 4px; max-width: 550px; margin: 0 auto; }

.calc-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.calc-label { font-weight: 600; font-size: .95rem; }
.calc-value { font-weight: 700; font-size: 1.05rem; min-width: 100px; text-align: left; }

.calc-label-group { display: flex; align-items: center; gap: 12px; }

.percent-input-group {
    display: flex; align-items: center; gap: 4px;
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.percent-input {
    width: 50px; border: none; background: transparent;
    font-family: var(--font); font-size: .88rem;
    text-align: center; color: var(--text); outline: none;
}

.calc-row.highlight { background: rgba(13,124,74,.06); border: 1px solid rgba(13,124,74,.15); }
.calc-row.highlight .calc-value { color: var(--primary); font-size: 1.15rem; }

.calc-row.final {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff; margin-top: 8px;
    border-radius: var(--radius);
    padding: 16px 20px;
}
.calc-row.final .calc-label { font-size: 1.05rem; }
.calc-row.final .calc-value { font-size: 1.35rem; font-weight: 900; color: #fff; }

.calc-row.per-unit { background: rgba(212,168,71,.1); border: 1px solid rgba(212,168,71,.2); }
.calc-row.per-unit .calc-value { color: var(--gold); }

.calc-row.qty-row {
    background: rgba(59,130,246,.06);
    border: 1px dashed rgba(59,130,246,.3);
    margin-top: 4px;
}
.calc-row.qty-row .calc-value { color: #3b82f6; font-weight: 800; }

.calc-qty-badge {
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff; font-weight: 800; font-size: .9rem;
    width: 32px; height: 32px; border-radius: 50%;
    margin-right: 8px;
}

/* === FORM ACTIONS === */
.form-actions { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

/* === EMPTY STATE === */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 20px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; }

/* === QUICK ACTIONS === */
.quick-action-btn {
    display: flex; align-items: center; gap: 12px;
    width: 100%; padding: 14px 16px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .92rem; font-weight: 600;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 8px;
    transition: all var(--transition);
}
.quick-action-btn:hover { border-color: var(--primary); background: rgba(13,124,74,.04); transform: translateX(-4px); }
.qa-icon { font-size: 1.3rem; }

/* === QUOTES LIST === */
.quote-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px; flex-wrap: wrap;
}
.quote-list-item:last-child { border-bottom: none; }

.quote-item-info { flex: 1; min-width: 200px; }
.quote-item-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.quote-item-meta { font-size: .8rem; color: var(--text-secondary); display: flex; gap: 12px; flex-wrap: wrap; }

.quote-item-price { font-weight: 800; font-size: 1.15rem; color: var(--primary); white-space: nowrap; }

.quote-item-actions { display: flex; gap: 6px; }

.category-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    background: rgba(13,124,74,.1);
    color: var(--primary);
}

/* === MATERIALS LIBRARY === */
.materials-lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }

.material-lib-card {
    padding: 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.material-lib-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

.material-lib-name { font-weight: 700; font-size: .95rem; margin-bottom: 6px; }
.material-lib-price { font-size: .85rem; color: var(--text-secondary); }
.material-lib-actions { display: flex; gap: 6px; margin-top: 10px; }

/* === SETTINGS === */
.settings-grid { display: flex; flex-direction: column; gap: 24px; max-width: 600px; }
.setting-group h3 { font-size: 1rem; font-weight: 700; margin-bottom: 14px; color: var(--primary); border-bottom: 2px solid var(--border); padding-bottom: 8px; }

/* === LOGIN SCREEN === */
.login-screen {
    display: none; position: fixed; inset: 0;
    background: var(--bg-sidebar);
    z-index: 9999;
    justify-content: center; align-items: center;
    background-image: radial-gradient(circle at center, rgba(13,124,74,.15) 0%, var(--bg-sidebar) 70%);
}
.login-screen.active { display: flex; }

.login-box {
    background: var(--bg-card);
    width: 90%; max-width: 400px;
    padding: 32px 28px;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,.2);
    border: 1px solid rgba(255,255,255,.05);
    animation: loginIn .4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes loginIn { from { opacity: 0; transform: scale(.9) translateY(20px); } }

/* === MODAL === */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    justify-content: center; align-items: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%; max-width: 520px;
    max-height: 80vh;
    box-shadow: var(--shadow-lg);
    animation: modalIn .25s ease;
    display: flex; flex-direction: column;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } }

.modal-header {
    padding: 18px 22px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--border); }

.modal-body { padding: 22px; overflow-y: auto; }

/* === TOAST === */
.toast-container { position: fixed; bottom: 24px; left: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    color: #fff; font-weight: 600; font-size: .9rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn .3s ease;
    display: flex; align-items: center; gap: 8px;
    max-width: 350px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } }

/* === PRINT TEMPLATE === */
.print-template { display: none; }

@media print {
    body * { visibility: hidden; }
    .print-template, .print-template * { visibility: visible; }
    .print-template {
        display: block; position: fixed; inset: 0;
        background: #fff; color: #000;
        padding: 24px 30px; font-size: 12px;
        direction: rtl; font-family: 'Cairo', 'Tajawal', sans-serif;
        overflow: auto;
    }
    .print-header { text-align: center; margin-bottom: 20px; border-bottom: 3px double #0d7c4a; padding-bottom: 16px; }
    .print-header h1 { font-size: 20px; margin-bottom: 4px; color: #0d7c4a; }
    .print-header p { font-size: 11px; color: #666; margin: 2px 0; }
    .print-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
    .print-table th, .print-table td { border: 1px solid #bbb; padding: 5px 8px; text-align: right; font-size: 10.5px; }
    .print-table th { background: #e8f5e9; font-weight: 700; color: #1a5632; font-size: 11px; }
    .print-table tbody tr:nth-child(even) { background: #fafafa; }
    .print-summary { max-width: 320px; margin-right: auto; margin-top: 8px; }
    .print-summary-row { display: flex; justify-content: space-between; padding: 5px 8px; border-bottom: 1px solid #eee; font-size: 11px; }
    .print-summary-row.final { background: #0d7c4a; color: #fff; padding: 10px 14px; border-radius: 4px; font-weight: 800; margin-top: 10px; font-size: 13px; }
    @page { size: A4; margin: 10mm; }
}

/* === RESPONSIVE === */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-right: 0; }
    .menu-toggle { display: block; }
    .pages-container { padding: 16px; }
    .topbar { padding: 0 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .card-header { flex-direction: column; align-items: flex-start; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }
    .calc-row { flex-direction: column; gap: 6px; align-items: flex-start; }
    .calc-value { text-align: right; width: 100%; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    html { font-size: 14px; }
    .materials-lib-grid { grid-template-columns: 1fr; }
}

/* === PREMIUM ENHANCEMENTS === */
.logo-icon { animation: logoPulse 3s ease-in-out infinite; }
@keyframes logoPulse { 0%,100%{ box-shadow: 0 2px 12px rgba(13,124,74,.4); } 50%{ box-shadow: 0 2px 20px rgba(13,124,74,.7), 0 0 30px rgba(212,168,71,.2); } }

.data-table tbody tr:nth-child(even) { background: rgba(13,124,74,.015); }
[data-theme="dark"] .data-table tbody tr:nth-child(even) { background: rgba(255,255,255,.02); }

.calc-row.final { animation: finalGlow 2s ease-in-out infinite alternate; }
@keyframes finalGlow { from { box-shadow: 0 2px 12px rgba(13,124,74,.3); } to { box-shadow: 0 4px 24px rgba(13,124,74,.5); } }

.stat-card { position: relative; overflow: hidden; }
.stat-card::after { content:''; position:absolute; top:-50%; right:-50%; width:100%; height:100%; background:linear-gradient(135deg,transparent,rgba(255,255,255,.05),transparent); transform:rotate(45deg); transition:all .5s; }
.stat-card:hover::after { right:150%; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

.quote-form-container > .card { margin-bottom: 20px; }

.material-lib-card { position:relative; overflow:hidden; }
.material-lib-card::before { content:''; position:absolute; top:0; right:0; width:4px; height:100%; background:var(--primary); opacity:0; transition:opacity var(--transition); }
.material-lib-card:hover::before { opacity:1; }

.nav-item { position: relative; }
.nav-item.active::before { content:''; position:absolute; right:0; top:50%; transform:translateY(-50%); width:3px; height:60%; background:var(--gold); border-radius:2px; }

select.form-input { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; padding-left: 32px; }
