/* ==========================================
   VARIABLES & ROOT
   ========================================== */

:root {
    --tesla-red: #E82127;
    --tesla-red-dark: #C41E22;
    --tesla-red-glow: rgba(232, 33, 39, 0.4);
    --tesla-black: #0A0A0A;
    --tesla-dark: #151515;
    --tesla-gray: #1E1E1E;
    --tesla-gray-light: #2A2A2A;
    --tesla-white: #FFFFFF;
    --tesla-text: #E0E0E0;
    --tesla-text-muted: #888888;
    --tesla-green: #00C853;
    --tesla-blue: #2196F3;
    
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    --shadow-card: 0 10px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px var(--tesla-red-glow);
}

/* ==========================================
   RESET & BASE
   ========================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-primary);
    background: var(--tesla-black);
    color: var(--tesla-text);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ==========================================
   BACKGROUND ANIMATION
   ========================================== */

.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.bg-gradient {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 20%, rgba(232, 33, 39, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 70% 80%, rgba(232, 33, 39, 0.05) 0%, transparent 50%);
    animation: bgMove 20s ease-in-out infinite;
}

@keyframes bgMove {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-5%, -5%) rotate(5deg); }
}

/* ==========================================
   LOGO
   ========================================== */

.logo-container {
    position: fixed;
    top: 30px;
    left: 40px;
    z-index: 100;
}

.tesla-logo {
    height: 50px;
    width: auto;
    filter: brightness(0) invert(1);
    opacity: 0.9;
    transition: var(--transition-fast);
}

.tesla-logo:hover {
    opacity: 1; 
    transform: scale(1.05);
}

/* ==========================================
   MAIN CONTAINER
   ========================================== */

.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 100px 40px 60px;
}

/* ==========================================
   HERO SECTION
   ========================================== */

.hero-section {
    text-align: center;
    padding: 60px 0 80px;
}

.main-title {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 700;
    letter-spacing: -2px;
    margin-bottom: 16px;
    color: var(--tesla-white);
}

.tesla-red {
    color: var(--tesla-red);
    position: relative;
}

.tesla-red::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--tesla-red);
    border-radius: 2px;
    opacity: 0.5;
}

.subtitle {
    font-size: 1.125rem;
    font-weight: 300;
    color: var(--tesla-text-muted);
    letter-spacing: 0.5px;
}

/* ==========================================
   TOOLS CONTAINER
   ========================================== */

.tools-container {
    margin-bottom: 60px;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
}

@media (max-width: 768px) {
    .tools-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================
   TOOL CARD
   ========================================== */

.tool-card {
    background: var(--tesla-gray);
    border: 1px solid var(--tesla-gray-light);
    border-radius: var(--border-radius);
    padding: 32px;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--tesla-red), transparent);
    opacity: 0;
    transition: var(--transition-smooth);
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card);
    border-color: rgba(232, 33, 39, 0.3);
}

.tool-card:hover::before {
    opacity: 1;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.card-number {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--tesla-red);
    background: rgba(232, 33, 39, 0.15);
    padding: 6px 12px;
    border-radius: 20px;
    letter-spacing: 1px;
}

.tool-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--tesla-white);
}

/* ==========================================
   DROP ZONE
   ========================================== */

.drop-zone {
    border: 2px dashed var(--tesla-gray-light);
    border-radius: var(--border-radius-sm);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.2);
}

.drop-zone:hover {
    border-color: var(--tesla-red);
    background: rgba(232, 33, 39, 0.05);
}

.drop-zone.drag-over {
    border-color: var(--tesla-red);
    background: rgba(232, 33, 39, 0.1);
    transform: scale(1.02);
}

.drop-zone.file-selected {
    border-color: #00C853;
    border-style: solid;
    background: rgba(0, 200, 83, 0.1);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.upload-icon-wrapper {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid var(--tesla-red);
    border-radius: 50%;
    animation: pulse 2s ease-out infinite;
    opacity: 0;
}

.drop-zone:hover .upload-pulse {
    opacity: 1;
}

@keyframes pulse {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

.upload-arrow {
    font-size: 1.5rem;
    color: var(--tesla-text-muted);
    transition: var(--transition-fast);
}

.drop-zone:hover .upload-arrow {
    color: var(--tesla-red);
    transform: translateY(-4px);
}

.drop-zone.file-selected .upload-arrow {
    color: #00C853;
}

.drop-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--tesla-text);
}

.drop-hint {
    font-size: 0.8rem;
    color: var(--tesla-text-muted);
}

.hidden-input {
    display: none;
}

/* ==========================================
   INPUT GROUP
   ========================================== */

.input-group {
    position: relative;
    margin-bottom: 24px;
}

.tesla-input {
    width: 100%;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--tesla-gray-light);
    border-radius: var(--border-radius-sm);
    color: var(--tesla-white);
    font-size: 1rem;
    font-family: var(--font-primary);
    transition: var(--transition-fast);
    outline: none;
}

.tesla-input:focus {
    border-color: var(--tesla-red);
    box-shadow: 0 0 0 4px rgba(232, 33, 39, 0.1);
}

.tesla-input::placeholder {
    color: var(--tesla-text-muted);
}

.input-label {
    position: absolute;
    top: -8px;
    left: 16px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--tesla-text-muted);
    background: var(--tesla-gray);
    padding: 0 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ==========================================
   BUTTONS
   ========================================== */

.tesla-button {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.tesla-button.primary {
    background: var(--tesla-red);
    color: var(--tesla-white);
}

.tesla-button.primary:hover:not(:disabled) {
    background: var(--tesla-red-dark);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.tesla-button.secondary {
    background: transparent;
    color: var(--tesla-white);
    border: 2px solid var(--tesla-gray-light);
}

.tesla-button.secondary:hover:not(:disabled) {
    border-color: var(--tesla-red);
    color: var(--tesla-red);
}

.tesla-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.tesla-button.small {
    width: auto;
    padding: 10px 20px;
    font-size: 0.75rem;
}

.tesla-button.active {
    background: var(--tesla-green);
    border-color: var(--tesla-green);
    color: var(--tesla-black);
}

.btn-text {
    position: relative;
    z-index: 1;
}

.btn-loader {
    display: none;
}

.tesla-button.loading .btn-text {
    opacity: 0;
}

.tesla-button.loading .btn-loader {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==========================================
   CHART SECTION
   ========================================== */

.chart-section {
    background: var(--tesla-gray);
    border: 1px solid var(--tesla-gray-light);
    border-radius: var(--border-radius);
    padding: 32px;
    margin-bottom: 40px;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--tesla-white);
}

.chart-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ==========================================
   CHART WITH PANEL LAYOUT
   ========================================== */

.chart-with-panel {
    display: flex;
    gap: 24px;
}

.chart-container {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--border-radius-sm);
    padding: 20px;
    height: 450px;
    position: relative;
}

#d3-chart {
    width: 100%;
    height: 100%;
}

#d3-chart svg {
    display: block;
}

/* ==========================================
   SELECTED POINTS PANEL
   ========================================== */

.selected-points-panel {
    width: 280px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--tesla-gray-light);
    border-radius: var(--border-radius-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(232, 33, 39, 0.1);
    border-bottom: 1px solid var(--tesla-gray-light);
}

.panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--tesla-white);
}

.panel-count {
    background: var(--tesla-red);
    color: var(--tesla-white);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    min-width: 28px;
    text-align: center;
}

.panel-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--tesla-gray-light);
}

.panel-button {
    flex: 1;
    padding: 8px 12px;
    background: var(--tesla-gray-light);
    border: none;
    border-radius: 6px;
    color: var(--tesla-text);
    font-size: 0.75rem;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.panel-button:hover {
    background: var(--tesla-red);
    color: var(--tesla-white);
}

.selected-points-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--tesla-text-muted);
}

.empty-state p {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.empty-hint {
    font-size: 0.75rem;
    opacity: 0.7;
}

.selected-point-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--tesla-gray);
    border-radius: 6px;
    margin-bottom: 8px;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.point-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.point-index {
    font-size: 0.65rem;
    color: var(--tesla-red);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.point-coords {
    font-size: 0.8rem;
    color: var(--tesla-text);
    font-family: monospace;
}

.remove-point-btn {
    background: transparent;
    border: none;
    color: var(--tesla-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: var(--transition-fast);
}

.remove-point-btn:hover {
    background: var(--tesla-red);
    color: var(--tesla-white);
}

/* ==========================================
   D3 CHART STYLES
   ========================================== */

.axis path,
.axis line {
    stroke: var(--tesla-gray-light);
}

.axis text {
    fill: var(--tesla-text-muted);
    font-size: 11px;
    font-family: var(--font-primary);
}

.grid line {
    stroke: rgba(255, 255, 255, 0.05);
}

.grid path {
    stroke-width: 0;
}

.dot {
    transition: all 0.15s ease;
    cursor: pointer;
}

.dot.selected {
    stroke: var(--tesla-green);
    stroke-width: 3px;
}

.dot.selection-mode:hover {
    cursor: crosshair;
}

/* ==========================================
   STATS CONTAINER
   ========================================== */

.stats-container {
    display: flex;
    gap: 20px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.stat-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 16px 24px;
    border-radius: var(--border-radius-sm);
    border-left: 3px solid var(--tesla-red);
    flex: 1;
    min-width: 120px;
}

.stat-item:nth-child(2) {
    border-left-color: var(--tesla-green);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--tesla-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--tesla-white);
}

/* ==========================================
   TOOLTIP
   ========================================== */

.d3-tooltip {
    position: fixed;
    background: var(--tesla-dark);
    border: 1px solid var(--tesla-gray-light);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--tesla-text);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 1000;
    box-shadow: var(--shadow-card);
}

.d3-tooltip.visible {
    opacity: 1;
}

.d3-tooltip .tooltip-title {
    color: var(--tesla-red);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.d3-tooltip .tooltip-content {
    line-height: 1.5;
}

.d3-tooltip .tooltip-content strong {
    color: var(--tesla-white);
}

.d3-tooltip .tooltip-hint {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--tesla-gray-light);
    font-size: 0.7rem;
    color: var(--tesla-green);
    display: none;
}

.d3-tooltip.selection-mode .tooltip-hint {
    display: block;
}

/* ==========================================
   RESULTS SECTION
   ========================================== */

.results-section {
    margin-bottom: 40px;
    animation: fadeInUp 0.6s ease 0.2s both;
}

.result-message {
    padding: 16px 20px;
    border-radius: var(--border-radius-sm);
    font-size: 0.9rem;
    margin-bottom: 12px;
    display: none;
    border-left: 4px solid;
    white-space: pre-line;
}

.result-message:not(:empty) {
    display: block;
}

.result-message.info {
    background: rgba(33, 150, 243, 0.1);
    border-color: #2196F3;
    color: #64B5F6;
}

.result-message.error {
    background: rgba(232, 33, 39, 0.1);
    border-color: var(--tesla-red);
    color: #EF5350;
}

.result-message.success {
    background: rgba(0, 200, 83, 0.1);
    border-color: #00C853;
    color: #69F0AE;
}

/* ==========================================
   FOOTER
   ========================================== */

.tesla-footer {
    text-align: center;
    padding: 40px;
    color: var(--tesla-text-muted);
    font-size: 0.85rem;
}

/* ==========================================
   NOTIFICATIONS
   ========================================== */

#notification-container {
    position: fixed;
    top: 30px;
    right: 30px;
    z-index: 9999;
}

.notification {
    background: var(--tesla-gray);
    border: 1px solid var(--tesla-gray-light);
    border-radius: var(--border-radius-sm);
    padding: 16px 24px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-card);
    transform: translateX(120%);
    transition: var(--transition-smooth);
    max-width: 350px;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    border-left: 4px solid #00C853;
}

.notification.error {
    border-left: 4px solid var(--tesla-red);
}

.notification-text {
    font-size: 0.9rem;
    color: var(--tesla-text);
}

/* ==========================================
   SCROLLBAR
   ========================================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--tesla-black);
}

::-webkit-scrollbar-thumb {
    background: var(--tesla-gray-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--tesla-red);
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .chart-with-panel {
        flex-direction: column;
    }
    
    .selected-points-panel {
        width: 100%;
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .main-container {
        padding: 80px 20px 40px;
    }
    
    .logo-container {
        top: 20px;
        left: 20px;
    }
    
    .tesla-logo {
        height: 35px;
    }
    
    .hero-section {
        padding: 40px 0 60px;
    }
    
    .tool-card {
        padding: 24px;
    }
    
    .chart-container {
        height: 350px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-controls {
        width: 100%;
    }
    
    .chart-controls .tesla-button {
        flex: 1;
    }
    
    .stats-container {
        justify-content: center;
    }
    
    #notification-container {
        left: 20px;
        right: 20px;
    }
    
    .notification {
        max-width: none;
    }
}

.config-panel {
    margin-bottom: 30px;
    border-left: 4px solid var(--tesla-red);
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.config-item label {
    display: block;
    font-size: 0.8rem;
    color: var(--tesla-text-muted);
    margin-bottom: 8px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--tesla-gray-light);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--tesla-red);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.2);
    padding: 10px 15px;
    border-radius: 8px;
}

.toggle-item label { margin-bottom: 0; }

.button-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tesla-button.outline {
    background: transparent;
    border: 1px dashed var(--tesla-text-muted);
    color: var(--tesla-text-muted);
}

.tesla-button.outline:hover:not(:disabled) {
    border-color: var(--tesla-white);
    color: var(--tesla-white);
    background: rgba(255,255,255,0.05);
}

.preview-line {
    fill: none;
    stroke: #555;
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}
.brush .selection {
    fill: var(--tesla-red);
    fill-opacity: 0.15;
    stroke: var(--tesla-red);
    stroke-width: 1px;
    stroke-dasharray: 4;
    shape-rendering: crispEdges;
}

.brush .handle {
    display: none; 
}

.box-zoom-active {
    cursor: crosshair !important;
}