:root {
    --primary-color: #005A9C;
    --secondary-color: #333;
    --background-color: #f4f7fa;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-color: #333;
    --text-light: #666;
    --border-color: #e1e5eb;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --primary-color: #4A9EFF;
    --secondary-color: #e0e0e0;
    --background-color: #1a1a1a;
    --sidebar-bg: #2d2d2d;
    --card-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --text-light: #a0a0a0;
    --border-color: #404040;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Rubik', 'Assistant', sans-serif;
    margin: 0;
    background-color: var(--background-color);
    color: var(--text-color);
}

.hidden {
    display: none !important;
}

#app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styles */
#sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    color: var(--primary-color);
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}

.language-switcher button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-light);
    padding: 0.2rem;
    transition: color 0.2s;
}

.language-switcher button.active {
    color: var(--primary-color);
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    gap: 0.5rem;
    flex-shrink: 0;
}

.filter-controls button {
    flex-basis: calc(50% - 0.25rem);
    padding: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    background-color: #fff;
    color: var(--text-light);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.filter-controls button:hover {
    background-color: #f0f0f0;
    color: var(--text-color);
}

.filter-controls button.active {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.sidebar-kpis {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.kpi-card-small {
    text-align: center;
}

.kpi-card-small h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 500;
}

.kpi-card-small p {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

#war-list {
    overflow-y: auto;
    flex-grow: 1;
}

#war-list a {
    display: block;
    padding: 1rem 1.5rem 1rem 2.2rem;
    text-decoration: none;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    position: relative;
    transition: all 0.2s;
}

#war-list a.active,
#war-list a:hover {
    background-color: var(--primary-color);
    color: white;
}

#war-list a::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

#war-list a[data-type="war"]::before {
    background-color: #c9302c;
}

#war-list a[data-type="operation"]::before {
    background-color: #428bca;
}

#war-list a[data-type="intifada"]::before {
    background-color: #f0ad4e;
}

#war-list a[data-type="terror_attack"]::before {
    background-color: #333;
}

/* Main Content Styles */
#main-content {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden;
}

#main-header h1 {
    margin: 0 0 0.25rem 0;
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    cursor: pointer;
}

#main-header p {
    margin: 0 0 1.5rem 0;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: var(--text-light);
}

/* Dashboard Grid */
#dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* CRITICAL: Chart.js Container Fix */
.chart-box {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    position: relative;
    height: 400px; /* Fixed height for Chart.js stability */
}

.chart-box.full-width {
    grid-column: 1 / -1;
}

.chart-box h3 {
    margin: 0 0 1rem 0;
    text-align: center;
    font-weight: 500;
    color: var(--text-color);
    font-size: clamp(0.9rem, 2vw, 1.1rem);
}

/* Chart.js canvas must be inside a positioned container */
.chart-box canvas {
    display: block;
    box-sizing: border-box;
    height: calc(100% - 3rem) !important; /* Account for title */
    width: 100% !important;
}

/* Details Section */
#details-view {
    margin-top: 2rem;
}

#details-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

#details-container .details-card:first-child {
    grid-column: 1 / -1;
}

.details-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.details-card h3 {
    margin: 0 0 1rem 0;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
    font-size: clamp(1rem, 2vw, 1.2rem);
}

.details-card p {
    margin: 0;
    line-height: 1.7;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

/* Timeline Events */
#timeline-events-container {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

#timeline-events-container h3 {
    margin: 0 0 1.5rem 0;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
    font-size: clamp(1rem, 2vw, 1.2rem);
}

#event-timeline {
    position: relative;
    padding-left: 25px;
}

#event-timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 5px;
    bottom: 5px;
    width: 4px;
    background: #e1e5eb;
    border-radius: 2px;
}

.timeline-item {
    position: relative;
    margin-bottom: 1rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 5px;
    width: 16px;
    height: 16px;
    background-color: white;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    z-index: 1;
}

.timeline-content {
    font-size: clamp(0.9rem, 1.5vw, 1rem);
    line-height: 1.6;
}

/* Footer */
.sources-footer {
    text-align: center;
    padding: 1.5rem;
    background-color: #333;
    color: #ccc;
    font-size: clamp(0.8rem, 1.5vw, 0.9rem);
}

/* AI Enhance Button */
#ai-enhance-btn {
    display: block;
    margin: -10px 0 15px auto;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    color: #fff;
    background: linear-gradient(45deg, #4285F4, #9c27b0);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#ai-enhance-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#ai-enhance-btn.loading {
    cursor: wait;
    background: #555;
}

#ai-enhance-btn.hidden {
    display: none;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateX(100%);
    animation: slideIn 0.5s forwards, fadeOut 0.5s 4.5s forwards;
    max-width: 90vw;
}

.toast.success {
    background: linear-gradient(45deg, #28a745, #20c997);
}

.toast.error {
    background: linear-gradient(45deg, #dc3545, #f0ad4e);
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* RTL Support */
html[dir="rtl"] #sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

html[dir="rtl"] #war-list a {
    padding-left: 1.5rem;
    padding-right: 2.2rem;
}

html[dir="rtl"] #war-list a::before {
    left: auto;
    right: 0.75rem;
}

html[dir="rtl"] #event-timeline {
    padding-left: 0;
    padding-right: 25px;
}

html[dir="rtl"] #event-timeline::before {
    left: auto;
    right: 8px;
}

html[dir="rtl"] .timeline-item::before {
    left: auto;
    right: -24px;
}

html[dir="rtl"] #toast-container {
    right: auto;
    left: 20px;
}

html[dir="rtl"] .toast {
    transform: translateX(-100%);
    animation: slideInRTL 0.5s forwards, fadeOutRTL 0.5s 4.5s forwards;
}

@keyframes slideInRTL {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOutRTL {
    to {
        opacity: 0;
        transform: translateX(-100%);
    }
}

/* Tablet Responsive */
@media (max-width: 1024px) {
    #sidebar {
        width: 280px;
    }

    #main-content {
        padding: 1.5rem;
    }

    .chart-box {
        height: 350px;
        padding: 1rem;
    }

    #dashboard-grid {
        gap: 1rem;
    }

    #details-container {
        grid-template-columns: 1fr;
    }
}

/* Mobile Landscape & Tablet Portrait */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-header {
        padding: 1rem;
    }

    .filter-controls {
        padding: 0.5rem 1rem;
    }

    #war-list {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        flex-grow: 0;
        max-height: 150px;
    }

    #war-list a {
        flex-shrink: 0;
        border-right: 1px solid var(--border-color);
        border-bottom: none;
        min-width: 180px;
    }

    #main-content {
        padding: 1rem;
    }

    #dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-box {
        height: 350px;
    }

    .chart-box.full-width {
        grid-column: auto;
    }

    #ai-enhance-btn {
        margin: 0 auto 15px auto;
        width: 100%;
        max-width: 300px;
    }

    #toast-container {
        right: 10px;
        left: 10px;
        top: 10px;
    }

    .toast {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}

/* Mobile Portrait */
@media (max-width: 480px) {
    .sidebar-header h2 {
        font-size: 1.2rem;
    }

    .filter-controls {
        padding: 0.5rem;
    }

    .filter-controls button {
        flex-basis: 100%;
        font-size: 0.85rem;
    }

    .sidebar-kpis {
        padding: 0.75rem 1rem;
    }

    .kpi-card-small p {
        font-size: 1.5rem;
    }

    #war-list a {
        min-width: 150px;
        padding: 0.75rem 1rem 0.75rem 1.8rem;
        font-size: 0.9rem;
    }

    #main-content {
        padding: 0.75rem;
    }

    #main-header h1 {
        font-size: 1.5rem;
    }

    #main-header p {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .chart-box {
        padding: 1rem 0.75rem;
        height: 300px;
    }

    .chart-box h3 {
        font-size: 0.95rem;
        margin-bottom: 0.75rem;
    }

    .details-card {
        padding: 1rem;
    }

    #timeline-events-container {
        padding: 1rem;
    }

    #event-timeline {
        padding-left: 20px;
    }

    #event-timeline::before {
        left: 6px;
    }

    .timeline-item::before {
        left: -20px;
        width: 12px;
        height: 12px;
    }

    .sources-footer {
        padding: 1rem;
        font-size: 0.8rem;
    }
}

/* Extra Small Mobile */
@media (max-width: 360px) {
    #sidebar {
        font-size: 0.9rem;
    }

    .sidebar-header {
        padding: 0.75rem;
    }

    .chart-box {
        height: 280px;
    }

    #war-list a {
        min-width: 130px;
        font-size: 0.85rem;
    }
}

/* Print Styles */
@media print {
    #sidebar,
    #ai-enhance-btn,
    #toast-container,
    .sources-footer {
        display: none;
    }

    #main-content {
        padding: 0;
    }

    .chart-box {
        height: auto;
        page-break-inside: avoid;
    }

    .chart-box,
    .details-card,
    #timeline-events-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

