/* إعداد المتغيرات والتصميم العام */
:root {
    --bg-dark: #070a13;
    --bg-card: rgba(17, 24, 39, 0.7);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* ألوان الحالة النيون */
    --color-primary: #10b981; /* أخضر زمردي للنجاح والحمولة الآمنة */
    --color-warning: #f59e0b; /* ذهبي/برتقالي للحمل القريب من الحد الأقصى */
    --color-danger: #ef4444;  /* أحمر نيون للحمولة الزائدة */
    --color-blue: #3b82f6;    /* أزرق نيون للرحلة والإجراءات العامة */
    
    --shadow-neon-green: 0 0 15px rgba(16, 185, 129, 0.4);
    --shadow-neon-orange: 0 0 15px rgba(245, 158, 11, 0.4);
    --shadow-neon-red: 0 0 20px rgba(239, 68, 68, 0.6);
    --shadow-neon-blue: 0 0 15px rgba(59, 130, 246, 0.3);
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --font-main: 'Cairo', system-ui, -apple-system, sans-serif;
}

/* إعادة تهيئة وإعداد الصفحة الرئيسية */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
        radial-gradient(at 50% 100%, rgba(239, 68, 68, 0.03) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.6;
}

/* تنسيق الحاوية الرئيسية للتطبيق */
.app-container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* الهيدر أو شريط العنوان الرئيسي */
.main-header {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 16px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    flex-wrap: wrap;
    gap: 16px;
}

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

.logo-icon {
    width: 42px;
    height: 42px;
    color: var(--color-primary);
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
}

.logo-text h1 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-text span {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.route-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.route-badge .flag {
    font-size: 20px;
}

.route-line {
    display: flex;
    align-items: center;
    color: var(--color-blue);
    width: 32px;
}

.route-line svg {
    width: 100%;
    transform: rotate(180deg); /* عكس السهم ليناسب الاتجاه RTL من اليمين لليسار */
}

/* منطقة العمل الرئيسية المقسمة لعمودين */
.main-content {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1100px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* تنسيقات البطاقات العامة */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255,255,255,0.1) inset;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 14px;
    margin-bottom: 4px;
}

.header-icon {
    width: 24px;
    height: 24px;
    color: var(--color-blue);
}

.card-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    flex-grow: 1;
}

/* قسم التخطيط وجدول البيانات */
.planner-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* حقول تفاصيل الرحلة */
.trip-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="text"],
input[type="date"],
select {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 500;
    outline: none;
    transition: all var(--transition-fast);
}

input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
    background: rgba(30, 41, 59, 0.8);
}

/* أزرار الإجراءات */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all var(--transition-normal);
}

.btn-icon {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--color-blue);
    color: #fff;
    box-shadow: var(--shadow-neon-blue);
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.btn-success {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-neon-green);
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.6);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    box-shadow: var(--shadow-neon-red);
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.7);
}

.btn-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* تنسيق جدول البضائع */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.cargo-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

.cargo-table th {
    background: rgba(15, 23, 42, 0.8);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    border-bottom: 2px solid rgba(255, 255, 255, 0.08);
}

.cargo-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(30, 41, 59, 0.2);
}

.cargo-table tr:hover td {
    background: rgba(30, 41, 59, 0.4);
}

.cargo-table input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 6px 10px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
}

.cargo-table input:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.3);
}

.cargo-table input:focus {
    border-color: var(--color-blue);
    background: rgba(15, 23, 42, 0.6);
    outline: none;
}

.cargo-table .total-weight-cell {
    font-weight: 700;
    color: var(--text-primary);
    padding-right: 10px;
}

.btn-delete-row {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-delete-row:hover {
    color: var(--color-danger);
    background: rgba(239, 68, 68, 0.1);
}

.cargo-actions {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

/* قسم العرض البصري والإحصائيات */
.visualizer-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* شبكة كروت الإحصائيات الفورية */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

@media (max-width: 580px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.stat-value .unit {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.stat-icon-wrapper {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    opacity: 0.15;
    color: var(--color-blue);
    pointer-events: none;
}

.stat-icon-wrapper svg {
    width: 100%;
    height: 100%;
}

.stat-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--color-primary);
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.5s ease;
}

/* تلوين الإحصائيات حسب الحالة */
.status-safe {
    color: var(--color-primary);
    filter: drop-shadow(0 0 4px rgba(16, 185, 129, 0.2));
}

.status-warning {
    color: var(--color-warning);
    filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.2));
}

.status-danger {
    color: var(--color-danger);
    filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.3));
}

/* محاكي الشاحنة الكبيرة */
.truck-card {
    position: relative;
}

.truck-simulator-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.truck-wrapper {
    width: 100%;
    max-width: 680px;
    position: relative;
    padding: 10px 0;
}

.truck-svg-container {
    width: 100%;
    height: auto;
}

.truck-svg {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
}

/* وميض أضواء الشاحنة */
.headlight {
    animation: pulseGlow 2s infinite alternate;
}

@keyframes pulseGlow {
    0% {
        opacity: 0.6;
        r: 4px;
        filter: drop-shadow(0 0 2px rgba(255,255,255,0.5));
    }
    100% {
        opacity: 1;
        r: 6px;
        filter: drop-shadow(0 0 8px rgba(255,255,255,0.9));
    }
}

/* تحذير تجاوز الحمولة نيون */
.overload-warning {
    width: 100%;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-danger);
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.1) inset;
    opacity: 0;
    max-height: 0;
    padding: 0;
    border: none;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.overload-warning.show {
    opacity: 1;
    max-height: 60px;
    padding: 12px 16px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    margin-bottom: 8px;
    animation: flashDanger 1.5s infinite alternate;
}

.warning-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

@keyframes flashDanger {
    0% {
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.15) inset, 0 0 2px rgba(239, 68, 68, 0.1);
    }
    100% {
        box-shadow: 0 0 15px rgba(239, 68, 68, 0.3) inset, 0 0 10px rgba(239, 68, 68, 0.25);
        background: rgba(239, 68, 68, 0.15);
    }
}

/* مفتاح دليل البضائع في الشاحنة */
.legend-container {
    width: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.no-items-text {
    font-size: 12px;
    color: var(--text-muted);
}

/* حركة العجلات عند تحميل البضائع */
.wheel-rotate {
    animation: rotateWheel 1s linear infinite;
}

@keyframes rotateWheel {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* سجل الرحلات ومستعرض البحث */
.history-card {
    gap: 16px;
}

.history-search input {
    width: 100%;
}

.history-list-wrapper {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 240px;
    overflow-y: auto;
    padding-left: 6px; /* لإظهار شريط التمرير بوضوح */
}

/* تخصيص شريط التمرير */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all var(--transition-fast);
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateX(-4px); /* إزاحة خفيفة لليسار تدل على التفاعل */
}

.history-item-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
}

.history-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
}

.history-item-actions {
    display: flex;
    gap: 8px;
}

.btn-history-load {
    background: rgba(59, 130, 246, 0.1);
    color: var(--color-blue);
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-history-load:hover {
    background: var(--color-blue);
    color: #fff;
}

.btn-history-delete {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
}

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

.no-history {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-icon {
    width: 40px;
    height: 40px;
    opacity: 0.4;
}

/* نظام التنبيهات المنبثقة (Toast System) */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px; /* زاوية اليسار مناسبة لعدم تداخلها مع لوحة التحكم */
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    border-right: 4px solid var(--color-blue); /* شريط التنبيه المناسب لـ RTL */
    border-radius: 8px;
    padding: 12px 20px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInToast 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    backdrop-filter: blur(8px);
}

.toast.toast-success {
    border-right-color: var(--color-primary);
}

.toast.toast-danger {
    border-right-color: var(--color-danger);
}

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

/* تذييل الصفحة */
.main-footer {
    border-top: 1px solid var(--border-glass);
    padding-top: 16px;
    margin-top: auto;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tech-info {
    font-size: 11px;
    opacity: 0.7;
}
