/* ===== Design Tokens & Theming ===== */
:root {
    /* Light Theme (Default fallback but we default to dark class) */
    --bg-app: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-input: #ffffff;
    --bg-hover: #f1f5f9;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-dim: #94a3b8;

    --border: rgba(15, 23, 42, 0.1);
    --border-focus: #3b82f6;

    --primary: #3b82f6;
    --primary-hover: #2563eb;

    /* Chart Colors Array */
    --c1: #3b82f6;
    --c2: #10b981;
    --c3: #f59e0b;
    --c4: #ef4444;
    --c5: #8b5cf6;
    --c6: #ec4899;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-card: var(--shadow-md);
}

.dark {
    --bg-app: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.65);
    --bg-input: rgba(15, 23, 42, 0.6);
    --bg-hover: rgba(51, 65, 85, 0.5);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #475569;

    --border: rgba(255, 255, 255, 0.1);
    --border-focus: #60a5fa;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;

    --c1: #3b82f6;
    --c2: #34d399;
    --c3: #fbbf24;
    --c4: #f87171;
    --c5: #a78bfa;
    --c6: #f472b6;

    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);
}

:root {
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', monospace;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Resets & Base ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-main);
    min-height: 100vh;
    transition: background-color var(--transition), color var(--transition);
    /* Subtle animated gradient background */
    background-image:
        radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.1), transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(139, 92, 246, 0.1), transparent 40%);
}

.code-font {
    font-family: var(--font-mono);
}

.hidden {
    display: none !important;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0 auto;
    max-width: 1600px;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
}

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

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--c5));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.main-content {
    flex: 1;
    display: flex;
    gap: 24px;
    padding: 0 24px 24px 24px;
    min-height: 0;
}

@media (max-width: 992px) {
    .main-content {
        flex-direction: column;
        height: auto;
    }
}

/* ===== Cards & Glassmorphism ===== */
.card {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.glass {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.sidebar {
    width: 380px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

@media (max-width: 992px) {
    .sidebar {
        width: 100%;
    }
}

.panel-section {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

.panel-section:last-child {
    border-bottom: none;
    overflow-y: auto;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

/* ===== Form Controls ===== */
.input-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 150px;
    max-height: 300px;
}

textarea {
    flex: 1;
    width: 100%;
    resize: vertical;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition);
}

textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition);
}

.form-control:focus {
    border-color: var(--border-focus);
}

select[multiple].form-control {
    height: auto;
    min-height: 80px;
    padding: 4px;
}

select[multiple] option {
    padding: 8px;
    border-radius: 4px;
}

select[multiple] option:checked {
    background: var(--bg-hover) linear-gradient(0deg, var(--bg-hover) 0%, var(--bg-hover) 100%);
}

/* Chart Type Selector */
.chart-types {
    display: flex;
    gap: 8px;
}

.type-btn {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}

.type-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.type-btn.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    padding: 8px 16px;
    border: none;
    background: transparent;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-icon {
    padding: 8px;
    color: var(--text-muted);
}

.btn-icon:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: 1px solid transparent;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline {
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    border-color: var(--text-muted);
    background: var(--bg-hover);
}

.btn-upload {
    cursor: pointer;
}

/* ===== Preview Panel ===== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.canvas-wrapper {
    flex: 1;
    padding: 24px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chartCanvas {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-dim);
    text-align: center;
    padding: 40px;
}

.empty-state .empty-icon {
    opacity: 0.5;
}

/* Custom Tooltip */
.tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    color: var(--text-main);
    z-index: 1000;
    transition: opacity 150ms transform 100ms;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-main);
    color: var(--bg-app);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}