/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0f0f1a;
    /* Main Theme - Kummara Orange */
    --primary: #FF6B00;
    --primary-glow: rgba(255, 107, 0, 0.4);
    --secondary: #2D3436;
    --bg-dark: #121212;
    --glass: rgba(30, 30, 30, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #FFFFFF;
    --text-primary: var(--text-main);
    --text-muted: #A0A0A0;
    --btn-secondary-bg: rgba(255, 255, 255, 0.08);
    --text-secondary: #A0A0A0;
    /* Added missing var */
    --sidebar-bg: rgba(20, 20, 30, 0.8);
    /* Added missing var */
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;

    /* Semantic Colors */
    --program: #5D3FD3;
    /* Deep Purple/Indigo for Program */
    --reach: #FF6B00;
    /* Reach matches Primary Orange */
    --potential: #A0A0A0;
    --reachable: #FF6B00;
    --trusted: #00B894;
    --panel-bg: rgba(255, 255, 255, 0.03);
    /* Default dark panel */
    /* Vivid Green */
    --accent-blue: #0984e3;
    --accent-blue-glow: rgba(9, 132, 227, 0.4);
    --accent-red: #d63031;
    --accent-red-glow: rgba(214, 48, 49, 0.4);
    --accent-green: #00b894;

    --font-main: 'Outfit', sans-serif;
}

[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-dark: #ffffff;
    --secondary: #f8f9fa;
    --glass: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 0, 0, 0.1);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-main: #1a1a1a;
    --text-muted: #666666;
    --text-secondary: #555555;
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --panel-bg: rgba(0, 0, 0, 0.03);
    /* Light mode panel */
    --btn-secondary-bg: rgba(0, 0, 0, 0.05);
    /* Light mode button */

    /* Adjust specific elements for light mode */
    --accent-blue-glow: rgba(9, 132, 227, 0.2);
    --accent-red-glow: rgba(214, 48, 49, 0.2);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(255, 107, 0, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(93, 63, 211, 0.05) 0%, transparent 40%);
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    gap: 16px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
}

.sidebar-header .header-text {
    text-align: left;
}

.sidebar-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    /* background: linear-gradient(135deg, var(--accent-blue), var(--accent-green)); */
    /* -webkit-background-clip: text; */
    /* -webkit-text-fill-color: transparent; */
    /* background-clip: text; */
}

.sidebar-header .subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== Control Sections ===== */
.control-section {
    background: var(--panel-bg);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border-color);
}

.control-section h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ===== Control Groups ===== */
.control-group {
    margin-bottom: 12px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.control-group label span {
    color: var(--text-primary);
    font-weight: 600;
}

/* ===== Range Sliders ===== */
input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

[data-theme="light"] input[type="range"] {
    background: rgba(255, 165, 0, 0.3);
    /* Light Orange */
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(255, 107, 0, 0.4);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* ===== Buttons ===== */
button {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

button .icon {
    font-size: 1.1rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px var(--accent-blue-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-blue-glow);
}

.btn-primary.active {
    background: linear-gradient(135deg, var(--accent-red), #c0392b);
    box-shadow: 0 4px 15px var(--accent-red-glow);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    margin-top: 8px;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(231, 76, 60, 0.2);
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
    margin-top: 8px;
}

.btn-danger:hover {
    background: var(--accent-red);
    color: white;
}

/* Theme Toggle Button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    /* Push to right if in flex container */
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--panel-bg);
    transform: rotate(15deg);
}

.theme-toggle .icon {
    font-size: 1.2rem;
}

/* ===== Legend ===== */
.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-color.program {
    background: var(--program);
    box-shadow: 0 0 10px rgba(93, 63, 211, 0.4);
}

.legend-color.reach {
    background: var(--reach);
    opacity: 0.5;
    box-shadow: 0 0 10px var(--primary-glow);
}

.legend-color.potential {
    background: repeating-linear-gradient(45deg,
            #333,
            #333 3px,
            #555 3px,
            #555 6px);
    border: 2px solid #666;
}

.legend-color.reachable {
    background: repeating-linear-gradient(45deg,
            #333,
            #333 3px,
            #555 3px,
            #555 6px);
    border: 2px solid var(--reachable);
    box-shadow: 0 0 8px var(--primary-glow);
}

.legend-color.trusted {
    background: var(--trusted);
    box-shadow: 0 0 10px rgba(0, 184, 148, 0.4);
}

/* ===== Stats ===== */
.stats .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
}

.stats .stat-row:last-child {
    border-bottom: none;
}

.stats .stat-row span:last-child {
    font-weight: 600;
    color: var(--accent-blue);
}

/* ===== Canvas Container ===== */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

.instructions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.instructions strong {
    color: var(--text-primary);
}

/* Light Theme Overrides */
[data-theme="light"] .sidebar-header h1 {
    color: #000000;
}

[data-theme="light"] .instructions {
    color: #FFFF00;
}

[data-theme="light"] .instructions strong {
    color: #FFD700;
    /* Slightly darker gold for contrast or keep yellow */
    color: #FFFF00;
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

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

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 40vh;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px;
    }

    .sidebar-header {
        width: 100%;
        padding-bottom: 10px;
    }

    .control-section {
        flex: 1;
        min-width: 140px;
        padding: 10px;
    }

    .canvas-container {
        min-height: 60vh;
    }
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease-out;
}

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

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 700;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: auto;
    transition: color 0.2s;
}

.close-modal:hover {
    color: var(--text-main);
    transform: none;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    color: var(--text-main);
}

.modal-body section {
    margin-bottom: 24px;
}

.modal-body section:last-child {
    margin-bottom: 0;
}

.modal-body h3 {
    font-size: 1rem;
    color: var(--text-main);
    margin-bottom: 12px;
    border-left: 3px solid var(--primary);
    padding-left: 10px;
}

.modal-body p,
.modal-body li {
    font-size: 0.9rem;
    color: #ccc;
    line-height: 1.6;
    margin-bottom: 8px;
}

.modal-body ul {
    list-style-type: disc;
    padding-left: 20px;
}

.formula {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--accent-green);
    margin-top: 4px;
}

/* ===== Markdown Styles for AI Analysis ===== */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    color: var(--primary);
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    font-weight: 600;
}

.markdown-content h1 {
    font-size: 1.8rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.markdown-content h2 {
    font-size: 1.4rem;
}

.markdown-content h3 {
    font-size: 1.1rem;
}

.markdown-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
    color: var(--text-secondary);
}

.markdown-content li {
    margin-bottom: 0.5rem;
}

.markdown-content strong {
    color: var(--text-main);
    font-weight: 700;
}

.markdown-content em {
    color: var(--accent-blue);
    font-style: italic;
}

.markdown-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    color: var(--accent-green);
}

.markdown-content blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-muted);
    font-style: italic;
}

.markdown-content hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

.loading-spinner {
    text-align: center;
    font-size: 1.2rem;
    color: var(--text-muted);
    padding: 2rem;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

/* ===== Privacy Banner for AI Settings ===== */
.privacy-banner {
    background: linear-gradient(135deg, rgba(9, 132, 227, 0.15), rgba(0, 184, 148, 0.15));
    border: 1px solid rgba(9, 132, 227, 0.3);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: fadeInDown 0.5s ease-out;
}

[data-theme="light"] .privacy-banner {
    background: linear-gradient(135deg, rgba(9, 132, 227, 0.1), rgba(0, 184, 148, 0.1));
    border-color: rgba(9, 132, 227, 0.2);
}

.privacy-banner .banner-icon {
    font-size: 1.4rem;
    filter: drop-shadow(0 0 8px var(--accent-blue-glow));
}

.privacy-banner .banner-content {
    flex: 1;
}

.privacy-banner h4 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 6px;
}

.privacy-banner p {
    font-size: 0.8rem !important;
    margin-bottom: 0 !important;
    color: var(--text-secondary) !important;
    line-height: 1.4 !important;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}