:root {
    --bg-color: #121212;
    --sidebar-bg: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-light: #e0e0e0;
    --input-bg: #2a2a2a;
    --primary-color: #4CAF50;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --border-color: #333;
    --panel-radius: 12px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 350px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

/* Custom Scrollbar for Sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Sidebar Header & Big Centered Logo */
.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 100%;
    margin-bottom: 6px;
}

.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 4px 0 6px 0;
}

.app-logo {
    width: 100%;
    max-width: 250px;
    height: auto;
    max-height: 135px;
    object-fit: contain;
    border-radius: 8px;
    transition: transform 0.25s ease;
}

.app-logo-dark {
    display: block;
}

.app-logo-light {
    display: none;
}

body.light-theme .app-logo-dark {
    display: none;
}

body.light-theme .app-logo-light {
    display: block;
}

.app-logo:hover {
    transform: scale(1.03);
}

.header-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    width: 100%;
    margin: 4px 0 8px 0;
    padding: 5px 6px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

body.light-theme .header-actions-bar {
    background: #f8fafc;
}

.user-auth-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 95px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.user-auth-btn:hover {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.08);
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.quick-action-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: rgba(59, 130, 246, 0.1);
}

.quick-save-btn {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.35);
    color: #34d399;
}

.quick-save-btn:hover {
    background: rgba(16, 185, 129, 0.25);
    border-color: #10b981;
    color: #6ee7b7;
}

body.light-theme .quick-save-btn {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #059669;
}

body.light-theme .quick-save-btn:hover {
    background: #d1fae5;
    border-color: #10b981;
    color: #047857;
}

.theme-toggle-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}

.color-preview.custom-shades-preview {
    background: linear-gradient(90deg, #deebf7, #3182bd);
}

.color-preview.custom-solid-preview {
    background: #3b82f6;
}

/* Theater Mode (Canvas Only View) */
body.theater-mode .sidebar {
    display: none;
}

body.theater-mode .playback-bar {
    display: none;
}

body.theater-mode .workspace {
    padding: 0;
}

body.theater-mode .chart-container {
    border-radius: 0;
}

.theater-close-area {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    z-index: 9999;
    justify-content: center;
    align-items: flex-start;
}

body.theater-mode .theater-close-area {
    display: flex;
}

.bar, .slice, .racer-token, .bubble-circle, .line-path, .lane {
    opacity: var(--chart-element-opacity, 1);
}

.label-name, .label-value, .tick text {
    fill: var(--chart-text-color, #ffffff);
}

.theater-close-btn {
    transform: translateY(-100%);
    transition: transform 0.3s ease, background 0.2s ease;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 24px;
    border-radius: 0 0 8px 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.theater-close-area:hover .theater-close-btn {
    transform: translateY(0);
}

.theater-close-btn:hover {
    background: rgba(225, 29, 72, 0.9);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--input-bg);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.control-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Custom Select and Grid Controls */
select {
    width: 100%;
    padding: 8px;
    background-color: var(--input-bg);
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9em;
    font-family: inherit;
    cursor: pointer;
}

/* Template Grid */
.template-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 5px;
}
.template-btn {
    background: var(--input-bg);
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 10px 5px;
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    text-align: center;
    transition: all 0.2s;
    font-family: inherit;
}
.template-btn:hover {
    background: #3a3a45;
}
.template-btn.active {
    border-color: var(--primary-color);
    background: rgba(76, 175, 80, 0.2);
}
.template-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.control-group input[type="file"],
.control-group select {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 6px;
    font-family: inherit;
    outline: none;
}

.control-group select:focus {
    border-color: var(--accent-color);
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status-text {
    font-style: italic;
    margin-top: 4px;
}

.button-row {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
    font-family: inherit;
    color: white;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
}
.btn-primary:hover {
    background-color: #388e3c;
}

.btn-secondary {
    background-color: #4b5563;
    flex: 1;
}
.btn-secondary:hover {
    background-color: #374151;
}

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

.btn-icon {
    background: transparent;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
}
.btn-icon:hover {
    background: rgba(255,255,255,0.1);
}

/* Workspace & Chart Area */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 16px 20px 20px 20px;
}

/* Workspace Top Project Bar */
.workspace-project-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    margin-bottom: 12px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--panel-radius);
    min-height: 44px;
    transition: all 0.2s ease;
}

body.light-theme .workspace-project-bar {
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.project-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.project-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
    flex-shrink: 0;
}

.project-indicator.unsaved {
    background: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

.project-title-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.project-bar-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
}

body.light-theme .project-bar-title {
    color: #0f172a;
}

.btn-icon-tiny {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.15s ease;
}

.btn-icon-tiny:hover {
    color: var(--accent-color);
    background: rgba(255, 255, 255, 0.08);
}

body.light-theme .btn-icon-tiny:hover {
    background: #e2e8f0;
}

.project-bar-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
    text-transform: capitalize;
    white-space: nowrap;
}

body.light-theme .project-bar-badge {
    background: #eff6ff;
    color: #2563eb;
    border-color: #bfdbfe;
}

.project-saved-status {
    font-size: 0.75rem;
    color: #10b981;
    font-weight: 600;
    white-space: nowrap;
}

.project-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-bar-action {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-bar-action:hover {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.06);
}

body.light-theme .btn-bar-action {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #1e293b;
}

body.light-theme .btn-bar-action:hover {
    background: #f1f5f9;
    border-color: #3b82f6;
}

.btn-bar-save {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.4);
    color: #34d399;
}

.btn-bar-save:hover {
    background: #10b981;
    color: #ffffff;
    border-color: #10b981;
}

body.light-theme .btn-bar-save {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #059669;
}

body.light-theme .btn-bar-save:hover {
    background: #10b981;
    color: #ffffff;
}

/* In theater mode, hide project bar */
body.theater-mode .workspace-project-bar {
    display: none;
}

.chart-container {
    flex: 1;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--chart-bg-color, var(--bg-surface));
}

.chart-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: var(--chart-bg-image, none);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: var(--chart-bg-opacity, 1);
    z-index: 0;
}

.chart-container > svg,
.chart-container > .empty-state {
    position: relative;
    z-index: 1;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
}
.empty-state h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* Playback Bar */
.playback-bar {
    height: 60px;
    margin-top: 20px;
    background-color: var(--sidebar-bg);
    border-radius: var(--panel-radius);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
}

.timeline-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
}

.timeline-container span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

input[type="range"] {
    flex: 1;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.date-display {
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 120px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* D3 Chart Specific Styles */
text {
    font-family: 'Inter', sans-serif;
}
.bar {
    transition: y 0.1s linear, width 0.1s linear; /* Smooth hardware accel transition */
}

/* Icon Background Styles */
.icon-bg {
    fill: var(--icon-bg-color, transparent);
    stroke: var(--icon-border-color, #000000);
    stroke-width: var(--icon-border-width, 0px);
    transform-box: fill-box;
    transform-origin: center;
    transform: scale(1.3);
}

/* Hide Icons Globally */
html.hide-icons .icon-bg,
html.hide-icons .bar-image,
html.hide-icons .slice-image,
html.hide-icons .racer-image,
html.hide-icons image {
    display: none !important;
}

/* Hide broken images if no URL provided */
image:not([href]), image[href=""] {
    display: none !important;
}
.icon-shape-circle .icon-bg {
    rx: 100px;
    ry: 100px;
}
.icon-shape-square .icon-bg {
    rx: 0;
    ry: 0;
}
.icon-shape-rounded .icon-bg {
    rx: 6px;
    ry: 6px;
}
.icon-shape-none .icon-bg {
    display: none !important;
}

/* Light Theme Variables & Overrides */
body.light-theme {
    --bg-color: #f1f5f9;
    --sidebar-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-light: #334155;
    --input-bg: #f8fafc;
    --border-color: #e2e8f0;
}

body.light-theme .theme-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

body.light-theme .tabs-nav {
    background-color: #f1f5f9;
    border: 1px solid #e2e8f0;
}

body.light-theme .tab-btn {
    color: #64748b;
}

body.light-theme .tab-btn:hover {
    color: #0f172a;
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .tab-btn.active {
    background: var(--primary-color);
    color: #ffffff;
}

body.light-theme .template-btn,
body.light-theme .color-tile-btn {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #334155;
}

body.light-theme .template-btn:hover,
body.light-theme .color-tile-btn:hover {
    background: #f1f5f9;
}

body.light-theme .template-btn.active,
body.light-theme .color-tile-btn.active {
    border-color: var(--primary-color);
    background: rgba(76, 175, 80, 0.12);
}

body.light-theme select,
body.light-theme input[type="text"],
body.light-theme input[type="number"],
body.light-theme input[type="file"] {
    background-color: #ffffff;
    color: #0f172a;
    border-color: #cbd5e1;
}

body.light-theme .btn-secondary {
    background-color: #e2e8f0;
    color: #1e293b;
}

body.light-theme .btn-secondary:hover {
    background-color: #cbd5e1;
}

body.light-theme .playback-bar {
    background-color: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

body.light-theme .btn-icon:hover {
    background: rgba(0, 0, 0, 0.06);
}

body.light-theme .modal-content {
    background-color: #ffffff;
    color: #0f172a;
    border-color: #e2e8f0;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

body.light-theme .modal-header {
    background-color: #f8fafc;
    border-color: #e2e8f0;
}

body.light-theme .modal-header h2 {
    color: #0f172a;
}

body.light-theme .close-modal {
    color: #64748b;
}

body.light-theme .close-modal:hover {
    color: #0f172a;
}

body.light-theme .modal-sub-tabs {
    background-color: #f1f5f9;
    border-color: #e2e8f0;
}

body.light-theme .modal-tab-btn:hover {
    color: #0f172a;
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .modal-form input,
body.light-theme .modal-form textarea,
body.light-theme .modal-form select {
    background-color: #ffffff;
    color: #0f172a;
    border-color: #cbd5e1;
}

body.light-theme .saved-item {
    background-color: #f8fafc;
    border-color: #e2e8f0;
    color: #0f172a;
}

body.light-theme .saved-item:hover {
    background-color: #f1f5f9;
}

body.light-theme .chart-container {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
