/* --- Global Variables & Theme Configuration --- */
:root {
    --bg-dark: #0f172a;       /* Base application background */
    --card-bg: #1e293b;       /* Surface color for UI cards */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-glow: rgba(99, 102, 241, 0.4);
    --input-bg: #0f172a;
    --border-color: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

/* --- Core Layout --- */
.dashboard-container {
    display: flex;
    gap: 2rem;
    width: 95%;
    max-width: 1400px;
    height: 85vh; /* LOCKED HEIGHT: Prevents the graph from stretching */
    min-height: 700px; /* Gives just enough room for the new inputs */
    margin: 2rem auto;
}

/* --- Component: Cards --- */
.card {
    background-color: var(--card-bg);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* --- Component: Sidebar --- */
.sidebar {
    width: 450px;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    height: 100%; 
    overflow: hidden; 
    flex-shrink: 0;
}

header h1 {
    font-family: 'Poppins', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Logo accent styling */
.dot {
    color: #a855f7;
}

header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    margin-bottom: 2.5rem;
}

/* --- Control Panel & Inputs --- */
.control-panel {
    display: flex;
    flex-direction: column;
    flex: 1; 
    min-height: 0; 
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input, select {
    width: 100%;
    padding: 1rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.3s ease;
    outline: none;
}

input::placeholder {
    color: #475569;
}

input:focus, select:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Custom Select Dropdown Implementation */
select {
    appearance: none;
    cursor: pointer;
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: "▼";
    font-size: 0.8rem;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* --- Main Data Visualization Area --- */
.chart-display {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.05), transparent 50%), var(--card-bg);
}

.canvas-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

/* --- Media Queries --- */
@media (max-width: 850px) {
    .dashboard-container {
        flex-direction: column;
        height: auto;
    }
    .sidebar {
        width: 100%;
    }
    .chart-display {
        height: 400px;
    }
}

/* --- Dynamic Data UI --- */
.data-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.data-header label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.add-btn {
    background: transparent;
    color: #a855f7;
    border: 1px dashed #a855f7;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-btn:hover {
    background: rgba(168, 85, 247, 0.1);
}

/* --- PERFECT SCROLLING CONTAINERS --- */
.categories-container,
.datasets-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto; 
    padding-right: 5px;
    scrollbar-width: thin;
    scrollbar-color: #475569 transparent;
}

/* Limit categories height so it doesn't push datasets off screen */
.categories-container {
    max-height: 180px; 
    margin-bottom: 0.5rem;
}

/* Let datasets take up the rest of the available sidebar space */
.datasets-container {
    flex: 1;
    min-height: 0;
    margin-bottom: 1rem;
}

/* Webkit custom scrollbars for the new containers */
.categories-container::-webkit-scrollbar,
.datasets-container::-webkit-scrollbar,
.tab-content::-webkit-scrollbar {
    width: 6px; 
}

.categories-container::-webkit-scrollbar-track,
.datasets-container::-webkit-scrollbar-track,
.tab-content::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3); 
    border-radius: 10px;
}

.categories-container::-webkit-scrollbar-thumb,
.datasets-container::-webkit-scrollbar-thumb,
.tab-content::-webkit-scrollbar-thumb {
    background-color: #475569; 
    border-radius: 10px;
}

.categories-container::-webkit-scrollbar-thumb:hover,
.datasets-container::-webkit-scrollbar-thumb:hover {
    background-color: #6366f1; 
}

/* Data Row Layout Constraints */
.data-row {
    display: flex;
    gap: 1rem;
    animation: fadeIn 0.3s ease;
    width: 100%;
}

.data-row > .data-label {
    flex: 1; 
}

.number-input-wrapper {
    flex: 1.5; 
    display: flex;
    align-items: center;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
    min-width: 100%;
}

/* Delegate input focus state to parent wrapper */
.number-input-wrapper:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.number-input-wrapper input {
    flex: 1; 
    min-width: 50px; 
    border: none;
    border-radius: 0;
    text-align: center;
    padding: 1.2rem 0;   
    font-size: 1.1rem;  
    font-weight: 600;   
    color: var(--text-main);
    background: transparent;
}

/* Disable native inner focus outline */
.number-input-wrapper input:focus {
    box-shadow: none;
    outline: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.data-row input {
    padding: 0.8rem;
    font-size: 0.9rem;
}

/* Action Utilities */
.remove-btn {
    background-color: transparent;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    width: 40px;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.remove-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* --- Custom Number Spinners Integration --- */
.number-input-wrapper input {
    flex: 1; 
    min-width: 15px; 
    border: none;
    border-radius: 0;
    text-align: center;
    padding: 1rem 0;
    color: var(--text-main);
    background: transparent;
    width: 100%;
}

.number-input-wrapper input:focus {
    box-shadow: none;
    outline: none;
}

/* Spinner control buttons */
.spin-btn {
    flex-shrink: 0; 
    width: 35px;    
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 0;
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spin-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.spin-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Hide Native Spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* --- Secondary Actions --- */
.action-buttons {
    display: flex;  
    gap: 1rem;
    margin-top: auto; 
    padding-top: 1rem;
    flex-shrink: 0;
}

/* Premium styling for the Download button */
.download-btn {
     width: 100%;
    margin-top: 0.4rem;
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 1.2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 10px 20px -5px var(--accent-glow);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3); /* Green glow */
    filter: brightness(1.1);
}

.download-btn:active {
    transform: translateY(0);
}

/* Make the arrow bounce slightly on hover */
.download-btn:hover svg {
    animation: bounceDown 0.6s infinite;
}

@keyframes bounceDown {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

.input-group, .action-buttons {
    flex-shrink: 0; 
}

/* --- Custom Color Picker Styling --- */
.data-color {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 45px;
    height: 45px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.data-color::-webkit-color-swatch {
    border-radius: 10px;
    border: 2px solid var(--border-color);
}

.data-color::-moz-color-swatch {
    border-radius: 10px;
    border: 2px solid var(--border-color);
}

.data-color:hover::-webkit-color-swatch {
    border-color: #6366f1;
}

/* --- Row Element Alignment Constraints --- */
.data-color,
.data-label,
.number-input-wrapper,
.remove-btn {
    height: 44px;
}

.data-row {
    gap: 0.5rem;
}

.data-label {
    flex: 3;
    min-width: 0px;
    padding: 0 0.8rem;
}

.number-input-wrapper input {
    height: 100%;
    padding: 0;
}

.data-color {
    width: 44px;
    padding: 0;
}

.data-color::-webkit-color-swatch-wrapper {
    padding: 0; 
}

.data-color::-webkit-color-swatch {
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* --- Theme Presets --- */

/* --- Theme: Light Mode --- */
body.light-theme {
    --bg-dark: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --input-bg: #f8fafc;
    --border-color: #e2e8f0;
}

/* --- Theme: Transparent --- */
/* This uses 'backdrop-filter' to blur whatever is behind the web app */
body.transparent-theme {
    --bg-dark: #0f172a; /* Keep the body dark so the glass pops */
    --card-bg: rgba(30, 41, 59, 0.7); /* 70% opacity for that glass effect */
    --border-color: rgba(255, 255, 255, 0.1);
}

body.transparent-theme .card {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: rgba(30, 41, 59, 0.4); /* Reduced opacity for better "glass" look */
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Tabbed Interface Styles --- */

/* Navigation bar at the top of the control panel */
.tab-navigation {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: rgba(15, 23, 42, 0.5);
    padding: 0.3rem;
    border-radius: 12px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

/* Highlight the active tab */
.tab-btn.active {
    background: var(--card-bg);
    color: var(--text-main);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Hidden by default, shown when active */
.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Critical for inner scrolling */
}

/* Ensure the data container takes max height when its tab is open */
#data-tab.active .data-points-container {
    flex-grow: 1;
}

/* Premium styling for the Share Link button */
.share-btn {
    width: 100%;
    margin-top: 0.4rem;
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 1.2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 10px 20px -5px var(--accent-glow);
}

.share-btn:hover {
    transform: translateY(-2px); /* Makes button feel "interactive" */
    box-shadow: 0 10px 15px -3px rgba(139, 92, 246, 0.3); /* Purple glow on hover */
    filter: brightness(1.1);
}

.share-btn:active {
    transform: translateY(0);
}

.share-btn svg {
    transition: transform 0.2s ease;
}

.share-btn:hover svg {
    transform: translateY(-2px); /* Icon bounces slightly */
}

/* --- Multi-Dataset UI Components --- */

/* Container for X-Axis category labels */
.categories-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Individual dataset card in the sidebar */
.dataset-block {
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
    flex-shrink: 0;
}

/* Header for the dataset block (Name, Color, Delete) */
.dataset-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}

.dataset-name-input {
    flex: 1;
    font-weight: 600;
    border-color: rgba(99, 102, 241, 0.3);
}

/* Grid for the actual data values inside a dataset */
.dataset-values-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two values per row to save space */
    gap: 0.8rem;
}

/* Individual value input group */
.value-input-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.value-input-item label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Align category labels in a row with the dataset values */
.category-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

/* Ensure the sidebar remains scrollable with more data */
.tab-content {
    max-height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
}

#data-tab {
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.categories-container {
    flex: auto; 
    height: auto; 
    overflow-y: auto;
    margin-bottom: 0.2rem;
    padding-right: 5px;
    padding-bottom: 2rem;
}

.datasets-container {
    flex: 1 1 auto; 
    height: auto; 
    overflow-y: auto;
    padding-right: 5px;
    padding-bottom: 0.2rem;
}

.categories-container::-webkit-scrollbar,
.datasets-container::-webkit-scrollbar,
.tab-content::-webkit-scrollbar {
    width: 3px;
}
