/* ============================================
   نظام حساب الكميات - Professional RTL CSS
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

:root {
    --primary: #1a56db;
    --primary-dark: #1341b3;
    --primary-light: #e8f0ff;
    --secondary: #6b7280;
    --success: #0f9d58;
    --success-light: #e6f4ea;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0ea5e9;
    --info-light: #e0f2fe;
    --purple: #7c3aed;
    --purple-light: #ede9fe;
    --dark: #111827;
    --gray: #6b7280;
    --gray-light: #f3f4f6;
    --border: #e5e7eb;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #1a56db;
    --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
}

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

body {
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    color: var(--dark);
    background: #f0f4f8;
    direction: rtl;
}

/* ── Login ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1a56db 100%);
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    width: 500px; height: 500px;
    border-radius: 50%;
    background: rgba(26,86,219,0.15);
    top: -100px; left: -100px;
}
.login-page::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    bottom: -80px; right: -80px;
}
.login-wrapper { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 20px; }
.login-card {
    background: white;
    border-radius: 20px;
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 32px; }
.logo-circle {
    width: 72px; height: 72px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    font-size: 32px; color: white;
    box-shadow: 0 8px 24px rgba(26,86,219,0.35);
}
.login-header h1 { font-size: 22px; font-weight: 800; color: var(--dark); margin-bottom: 6px; }
.login-header p { color: var(--gray); font-size: 14px; }
.login-form .form-group { margin-bottom: 20px; }
.login-form label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: var(--dark); }
.login-form label i { margin-left: 6px; color: var(--primary); }
.login-form input {
    width: 100%; padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    transition: all 0.2s;
    outline: none;
}
.login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
.btn-login {
    width: 100%; padding: 14px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white; border: none;
    border-radius: var(--radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 16px; font-weight: 700;
    cursor: pointer; transition: all 0.3s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-login:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(26,86,219,0.35); }
.login-hint { text-align: center; margin-top: 20px; color: var(--gray); font-size: 13px; }

/* ── App Layout ── */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    position: fixed; top: 0; right: 0;
    height: 100vh;
    z-index: 100;
    box-shadow: -4px 0 20px rgba(0,0,0,0.2);
}
.sidebar-logo {
    display: flex; align-items: center; gap: 12px;
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-size: 16px; font-weight: 800; color: white;
}
.logo-icon {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: white;
}
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 10px;
    font-weight: 500;
    transition: all 0.2s;
}
.nav-item i { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: var(--primary); color: white; }
.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.user-info { display: flex; align-items: center; gap: 10px; color: white; padding: 8px 12px; margin-bottom: 8px; font-size: 14px; }
.btn-logout {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
}
.btn-logout:hover { background: rgba(220,38,38,0.15); color: #ef4444; }

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    padding: 24px;
    min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 28px;
}
.topbar h2 { font-size: 22px; font-weight: 800; color: var(--dark); }
.topbar h2 i { color: var(--primary); margin-left: 8px; }
.topbar-actions { display: flex; gap: 10px; }

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-icon {
    width: 56px; height: 56px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-info h3 { font-size: 26px; font-weight: 800; color: var(--dark); }
.stat-info p { font-size: 13px; color: var(--gray); margin-top: 2px; }

/* ── Cards ── */
.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--gray-light);
}
.card-header h3 { font-size: 16px; font-weight: 700; color: var(--dark); }
.card-header h3 i { color: var(--primary); margin-left: 8px; }
.card-body { padding: 24px; }
.mt-4 { margin-top: 20px; }
.mb-4 { margin-bottom: 20px; }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: var(--gray-light);
    padding: 12px 16px;
    text-align: right;
    font-weight: 700;
    font-size: 13px;
    color: var(--dark);
    border-bottom: 2px solid var(--border);
}
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-light); }
.price-cell { color: var(--success); font-weight: 700; font-size: 15px; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; font-weight: 600;
    cursor: pointer; border: none;
    text-decoration: none;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(26,86,219,0.3); }
.btn-secondary { background: var(--gray-light); color: var(--dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.btn-warning:hover { background: #fde68a; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-info { background: var(--info-light); color: #0369a1; border: 1px solid #bae6fd; }
.btn-info:hover { background: #bae6fd; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 13px 28px; font-size: 15px; }
.action-btns { display: flex; gap: 6px; }

/* ── Forms ── */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 20px; }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-weight: 600; font-size: 14px; color: var(--dark); }
.form-group label i { color: var(--primary); margin-left: 6px; }
.form-group input,
.form-group select,
.form-group textarea {
    padding: 11px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    background: white;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
.req { color: var(--danger); }
.form-actions {
    display: flex; gap: 12px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* ── Tabs ── */
.tabs-container { margin-bottom: 24px; }
.tabs-header {
    display: flex;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    overflow: hidden;
    border-bottom: none;
}
.tab-btn {
    flex: 1; padding: 16px 24px;
    background: none; border: none;
    font-family: 'Tajawal', sans-serif;
    font-size: 15px; font-weight: 600;
    color: var(--gray);
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border-bottom: 3px solid transparent;
}
.tab-btn:hover { background: var(--gray-light); color: var(--dark); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Financial Table ── */
.fin-table-wrapper { overflow-x: auto; }
.fin-table { width: 100%; border-collapse: collapse; }
.fin-table th {
    background: var(--primary);
    color: white;
    padding: 13px 16px;
    text-align: right;
    font-weight: 600;
    font-size: 14px;
}
.fin-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.fin-table tr:last-child td { border-bottom: none; }
.fin-table tr:hover td { background: #f8faff; }
.fin-table .sub-row td { background: #fafafa; padding-right: 32px; }
.fin-table tfoot tr td { background: var(--dark); color: white; padding: 16px; font-size: 15px; border: none; }
.price-input {
    width: 140px; padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; font-weight: 600;
    outline: none; transition: all 0.2s;
}
.price-input:focus { border-color: var(--primary); }
.item-total { font-weight: 700; color: var(--success); font-size: 14px; }
.grand-total-row td { background: #0f172a !important; color: white !important; font-size: 16px !important; }
.grand-total-val { font-size: 20px !important; color: #fbbf24 !important; }

/* ── Quantities Preview ── */
.quantities-preview { border: 2px dashed var(--primary-light); }
.quantities-preview .card-header { background: var(--primary-light); }
.qty-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.qty-item {
    background: var(--gray-light);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 4px;
    border: 1px solid var(--border);
}
.qty-item span { font-size: 12px; color: var(--gray); }
.qty-item strong { font-size: 18px; font-weight: 800; color: var(--primary); }

/* ── Project Summary Bar ── */
.project-summary-bar {
    display: flex; gap: 1px;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.summary-item {
    flex: 1; background: white;
    padding: 20px 24px;
    display: flex; flex-direction: column; gap: 6px;
}
.summary-item span { font-size: 12px; color: var(--gray); font-weight: 500; }
.summary-item strong { font-size: 18px; font-weight: 800; color: var(--dark); }
.summary-item.highlight { background: var(--primary); }
.summary-item.highlight span { color: rgba(255,255,255,0.8); }
.summary-item.highlight strong { color: white; font-size: 22px; }

/* ── Info Grid ── */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.info-item {
    background: var(--gray-light);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    border: 1px solid var(--border);
}
.info-item span { display: block; font-size: 12px; color: var(--gray); margin-bottom: 4px; }
.info-item strong { font-size: 16px; font-weight: 700; color: var(--dark); }

/* ── Total Highlight Card ── */
.total-highlight-card {
    margin-top: 20px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: var(--radius);
    padding: 28px 32px;
    color: white;
    box-shadow: 0 8px 24px rgba(26,86,219,0.35);
}
.total-highlight-inner { display: flex; align-items: center; gap: 20px; }
.total-highlight-inner i { font-size: 48px; opacity: 0.7; }
.total-highlight-card p { font-size: 14px; opacity: 0.85; margin-bottom: 6px; }
.total-highlight-card h2 { font-size: 36px; font-weight: 800; }

/* ── Alerts ── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    display: flex; align-items: center; gap: 10px;
}
.alert i { font-size: 18px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }

/* ── Badge ── */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px; font-weight: 600;
}

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray); }
.empty-state i { font-size: 64px; opacity: 0.3; display: block; margin-bottom: 16px; }
.empty-state p { font-size: 18px; margin-bottom: 20px; }

/* ── Modal ── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
    backdrop-filter: blur(4px);
}
.modal-content { background: white; border-radius: var(--radius); max-width: 440px; width: 90%; box-shadow: var(--shadow-lg); }
.modal-header {
    padding: 20px 24px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border);
}
.modal-header.danger { background: var(--danger-light); color: var(--danger); }
.modal-header i { font-size: 22px; }
.modal-header h3 { font-size: 17px; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; display: flex; gap: 10px; justify-content: flex-start; border-top: 1px solid var(--border); }
.text-muted { color: var(--gray); font-size: 13px; }

/* ── Fin View Table ── */
.fin-view-table tfoot td {
    background: var(--dark) !important;
    color: white !important;
    padding: 16px !important;
    font-size: 16px !important;
}
.fin-view-table .grand-total-val { color: #fbbf24 !important; font-size: 18px !important; }

/* ── Auto-computed fields ── */
.auto-field .auto-value {
    background: linear-gradient(135deg, #f0f7ff, #e8f0ff);
    border: 2px dashed var(--primary);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 16px;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}
.auto-field .auto-value i { font-size: 13px; opacity: 0.6; }

/* ── Sides table ── */
.card-header { display: flex; align-items: center; justify-content: space-between; }
.card-header-actions { display: flex; gap: 8px; }
.sides-table { width: 100%; }
.sides-thead {
    display: grid;
    grid-template-columns: 60px 1fr 120px;
    gap: 12px;
    padding: 8px 12px;
    background: var(--gray-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    color: var(--gray);
    margin-bottom: 8px;
}
.side-row {
    display: grid;
    grid-template-columns: 60px 1fr 120px;
    gap: 12px;
    align-items: center;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.side-row:last-child { border-bottom: none; }
.side-row:hover { background: #f8faff; }
.side-num {
    font-size: 13px; font-weight: 700;
    color: var(--gray);
    text-align: center;
    background: var(--gray-light);
    border-radius: 6px;
    padding: 6px;
}
.side-input {
    width: 100%; padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 15px; font-weight: 600;
    outline: none; transition: border-color 0.2s;
    text-align: center;
}
.side-input:focus { border-color: var(--primary); }

/* ── Toggle switch ── */
.toggle-label {
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; user-select: none;
}
.toggle-label input[type=checkbox] { display: none; }
.toggle-slider {
    width: 44px; height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    transition: background 0.25s;
    flex-shrink: 0;
}
.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px; right: 3px;
    width: 18px; height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle-label input:checked + .toggle-slider { background: var(--success); }
.toggle-label input:checked + .toggle-slider::after { transform: translateX(-20px); }
.toggle-text { font-size: 13px; color: var(--gray); font-weight: 500; }
.toggle-label input:checked ~ .toggle-text { color: var(--success); font-weight: 700; }
.toggle-label input:checked ~ .toggle-text::before { content: 'شارع ✓'; }
.toggle-text::before { content: 'داخلي'; }

/* ── Perimeter chips ── */
.perimeter-chips {
    display: flex; gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}
.pchip {
    display: flex; align-items: center; gap: 10px;
    background: var(--primary-light);
    border: 1px solid #c7d7f8;
    border-radius: 10px;
    padding: 12px 18px;
    flex: 1; min-width: 180px;
}
.pchip i { color: var(--primary); font-size: 18px; }
.pchip span { font-size: 13px; color: var(--gray); }
.pchip strong { font-size: 18px; font-weight: 800; color: var(--primary); margin-right: auto; }
.pchip.street { background: #f0fdf4; border-color: #86efac; }
.pchip.street i { color: var(--success); }
.pchip.street strong { color: var(--success); }

/* ── Percent input ── */
.pct-input-wrap { display: flex; align-items: center; gap: 0; }
.pct-input-wrap input {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border-right: none; flex: 1;
}
.pct-input-wrap span {
    background: var(--gray-light);
    border: 2px solid var(--border);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 11px 14px;
    font-weight: 700; color: var(--gray);
}

/* ── Quantities preview enhanced ── */
.qty-item { position: relative; }
.qty-item em {
    font-style: normal;
    font-size: 11px;
    color: var(--gray);
    margin-top: 2px;
    display: block;
}
.qty-item.highlight { background: var(--primary-light); border-color: #c7d7f8; }
.qty-item.highlight strong { color: var(--primary); font-size: 20px; }

/* ── Print ── */
@media print {
    .sidebar, .topbar-actions, .btn, .form-actions { display: none !important; }
    .main-content { margin-right: 0 !important; padding: 10px !important; }
    .app-layout { display: block !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); transition: transform 0.3s; }
    .main-content { margin-right: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .project-summary-bar { flex-wrap: wrap; }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; }
}
