@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* --- DEFAULT DESIGN SYSTEM TOKENS (SLATE MINIMAL) --- */
:root {
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-header: 'Outfit', var(--font-sans);

    /* Backgrounds & Panels */
    --bg-app: #f8fafc;
    --bg-surface: #ffffff;
    --bg-sidebar: #0f172a;
    --bg-input: #f1f5f9;

    /* Text & Colors */
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    --text-accent: #6366f1;
    /* Indigo */

    /* Borders, Shadows, Sizing */
    --border-main: #e2e8f0;
    --border-focus: #cbd5e1;
    --border-radius-lg: 16px;
    --border-radius-md: 8px;
    --border-radius-sm: 4px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
    --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);

    /* Transition timings */
    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;

    /* Chart Color Palette (CSS Variable bridge to Chart.js) */
    --chart-color-1: #6366f1;
    /* Indigo */
    --chart-color-2: #ec4899;
    /* Pink */
    --chart-color-3: #10b981;
    /* Emerald */
    --chart-color-4: #f59e0b;
    /* Amber */
    --chart-color-5: #3b82f6;
    /* Blue */
    --chart-color-6: #8b5cf6;
    /* Purple */
    --chart-color-7: #64748b;
    /* Slate */

    --chart-grid-line: #f1f5f9;
    --chart-text-color: #64748b;
    --chart-tooltip-bg: rgba(15, 23, 42, 0.95);
    --chart-tooltip-text: #ffffff;
    --chart-bubble-text: var(--text-main);
}

/* --- THEME OVERRIDES --- */

/* Theme: Emerald Corporate */
body.theme-emerald-corporate {
    --bg-app: #f4f7f6;
    --bg-surface: #ffffff;
    --bg-sidebar: #064e3b;
    /* Deep Forest Green */
    --text-main: #062f21;
    --text-muted: #4b6b60;
    --text-accent: #059669;
    /* Emerald Primary */
    --border-main: #e1e9e6;

    --chart-color-1: #059669;
    /* Emerald */
    --chart-color-2: #2563eb;
    /* Cobalt Blue */
    --chart-color-3: #d97706;
    /* Warm Amber */
    --chart-color-4: #7c3aed;
    /* Deep Purple */
    --chart-color-5: #0d9488;
    /* Teal */
    --chart-grid-line: #edf3f0;
    --chart-bubble-text: var(--text-main);
}

/* Theme: BrandRank.AI (Futuristic Executive Dark AI Theme) */
body.theme-brandrank-ai {
    --bg-app: #0b1329;
    --bg-surface: #1e293b;
    --bg-sidebar: #070d19;
    --bg-input: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-accent: #3898ff;
    /* Lighter Electric AI Blue */
    --border-main: #2a374a;
    --border-focus: #3898ff;

    --chart-color-1: #3898ff;
    /* Electric Light Blue */
    --chart-color-2: #22d3ee;
    /* Cyan Glow */
    --chart-color-3: #818cf8;
    /* Indigo AI */
    --chart-color-4: #f472b6;
    /* Neon Pink */
    --chart-color-5: #34d399;
    /* Emerald Mint */
    --chart-grid-line: #2a374a;
    --chart-text-color: #cbd5e1;
    --chart-tooltip-bg: rgba(11, 19, 41, 0.98);
    --chart-bubble-text: var(--text-main);
}

body.theme-brandrank-ai .dashboard-card {
    border-top: 3px solid #3898ff;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

body.theme-brandrank-ai .dashboard-card:hover {
    box-shadow: 0 12px 30px -5px rgba(56, 152, 255, 0.25);
}

body.theme-brandrank-ai .card-header {
    background: linear-gradient(180deg, rgba(56, 152, 255, 0.14) 0%, rgba(30, 41, 59, 0) 100%);
    border-bottom: 1px solid rgba(56, 152, 255, 0.25);
}

body.theme-brandrank-ai .card-title-text {
    color: #3898ff;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* Theme: Midnight Tech (Sleek Dark Mode) */
body.theme-midnight-tech {
    --bg-app: #090d16;
    --bg-surface: #111827;
    --bg-sidebar: #030712;
    --bg-input: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-accent: #06b6d4;
    /* Cyan */
    --border-main: #374151;
    --border-focus: #4b5563;

    --chart-color-1: #06b6d4;
    /* Cyan */
    --chart-color-2: #f43f5e;
    /* Rose Neon */
    --chart-color-3: #10b981;
    /* Emerald */
    --chart-color-4: #a855f7;
    /* Neon Violet */
    --chart-color-5: #eab308;
    /* Neon Yellow */
    --chart-grid-line: #1f2937;
    --chart-text-color: #9ca3af;
    --chart-tooltip-bg: rgba(3, 7, 18, 0.98);
    --chart-bubble-text: var(--text-main);
}

/* Theme: Sapphire Executive */
body.theme-sapphire-executive {
    --bg-app: #f0f4f8;
    --bg-surface: #ffffff;
    --bg-sidebar: #1e3a8a;
    /* Navy Blue */
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-accent: #2563eb;
    /* Sapphire */
    --border-main: #cbd5e1;

    --chart-color-1: #2563eb;
    /* Sapphire */
    --chart-color-2: #d97706;
    /* Executive Gold */
    --chart-color-3: #0284c7;
    /* Sky */
    --chart-color-4: #b45309;
    /* Bronze */
    --chart-color-5: #475569;
    /* Slate Accent */
    --chart-grid-line: #e2e8f0;
    --chart-bubble-text: var(--text-main);
}

/* Theme: Crimson Warm */
body.theme-crimson-warm {
    --bg-app: #faf8f6;
    --bg-surface: #ffffff;
    --bg-sidebar: #450a0a;
    /* Dark Crimson */
    --text-main: #272525;
    --text-muted: #78716c;
    --text-accent: #dc2626;
    /* Crimson */
    --border-main: #f0e9e4;

    --chart-color-1: #dc2626;
    /* Crimson */
    --chart-color-2: #ea580c;
    /* Warm Orange */
    --chart-color-3: #d97706;
    /* Gold */
    --chart-color-4: #854d0e;
    /* Ochre */
    --chart-color-5: #57534e;
    /* Charcoal */
    --chart-grid-line: #f5ebe6;
    --chart-bubble-text: var(--text-main);
}

/* --- RESET & BASIC STYLES --- */
* {
    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;
    display: flex;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-header);
    font-weight: 600;
    letter-spacing: -0.02em;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

a {
    text-decoration: none;
    color: var(--text-accent);
}

/* --- LANDING / DASHBOARD SELECTION VIEW --- */
.landing-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100vw;
    min-height: 100vh;
    padding: 40px 20px;
    background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(236, 72, 153, 0.05) 0%, transparent 40%),
        var(--bg-app);
}

.landing-container {
    width: 100%;
    max-width: 1000px;
    text-align: center;
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.landing-header {
    margin-bottom: 48px;
}

.landing-logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text-accent);
    font-family: var(--font-header);
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 16px;
}

.landing-tagline {
    font-size: 18px;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.dashboard-select-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-lg);
    padding: 32px 24px;
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 220px;
    position: relative;
    overflow: hidden;
}

.dashboard-select-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--text-accent), var(--chart-color-2));
    opacity: 0;
    transition: var(--transition-fast);
}

.dashboard-select-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-premium);
    border-color: var(--text-accent);
}

.dashboard-select-card:hover::before {
    opacity: 1;
}

.card-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-md);
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    transition: var(--transition-smooth);
}

.dashboard-select-card:hover .card-icon-wrapper {
    background: var(--text-accent);
    color: var(--text-inverse);
}

.dashboard-select-card.custom-card .card-icon-wrapper {
    background: rgba(236, 72, 153, 0.1);
    color: #ec4899;
}

.dashboard-select-card.custom-card:hover .card-icon-wrapper {
    background: #ec4899;
    color: var(--text-inverse);
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

.card-desc {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 12px;
    flex-grow: 1;
}

.card-footer-info {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-main);
    padding-top: 12px;
}

.delete-dashboard-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.delete-dashboard-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.landing-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-main);
    border-radius: var(--border-radius-lg);
    padding: 40px;
    background: var(--bg-surface);
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: var(--shadow-sm);
}

.landing-upload-area:hover,
.landing-upload-area.dragover {
    border-color: var(--text-accent);
    background: rgba(99, 102, 241, 0.02);
}

.upload-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
    transition: var(--transition-smooth);
}

.landing-upload-area:hover .upload-icon {
    color: var(--text-accent);
    transform: translateY(-2px);
}

/* --- MAIN DASHBOARD WORKSPACE --- */
.workspace-layout {
    display: flex;
    width: 100vw;
    min-height: 100vh;
    position: relative;
}

/* --- SIDEBAR PANEL --- */
aside.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    transition: var(--transition-smooth);
    z-index: 50;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-inverse);
    font-family: var(--font-header);
    font-weight: 700;
    font-size: 20px;
}

.sidebar-collapse-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.sidebar-collapse-btn:hover {
    color: var(--text-inverse);
}

/* --- SIDEBAR PANEL COLLAPSED STATE --- */
aside.sidebar.collapsed {
    width: 64px;
}

aside.sidebar.collapsed .sidebar-header {
    padding: 20px 12px;
    justify-content: center;
}

aside.sidebar.collapsed .sidebar-logo span {
    display: none;
}

aside.sidebar.collapsed .sidebar-body {
    padding: 20px 8px;
    align-items: center;
}

aside.sidebar.collapsed .sidebar-section-title {
    display: none;
}

aside.sidebar.collapsed .sidebar-menu-list {
    width: 100%;
}

aside.sidebar.collapsed .sidebar-menu-item {
    padding: 10px 0;
    justify-content: center;
}

aside.sidebar.collapsed .sidebar-menu-item span {
    display: none;
}

aside.sidebar.collapsed .sidebar-upload-box {
    padding: 10px;
    justify-content: center;
}

aside.sidebar.collapsed .sidebar-upload-box p {
    display: none;
}

aside.sidebar.collapsed .theme-selector-grid {
    grid-template-columns: 1fr;
    gap: 10px;
}

aside.sidebar.collapsed .theme-button {
    padding: 8px;
    justify-content: center;
}

aside.sidebar.collapsed .theme-button span:not(.theme-swatch) {
    display: none;
}

aside.sidebar.collapsed .sidebar-footer {
    padding: 16px 8px;
    justify-content: center;
}

aside.sidebar.collapsed .sidebar-footer span {
    display: none;
}

.sidebar-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #64748b;
    margin-bottom: 12px;
    font-weight: 700;
}

.sidebar-menu-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition-fast);
}

.sidebar-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-inverse);
}

.sidebar-menu-item.active {
    background: var(--text-accent);
    color: var(--text-inverse);
}

/* Sidebar Custom Upload Area */
.sidebar-upload-box {
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-md);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.sidebar-upload-box:hover {
    border-color: var(--text-accent);
    background: rgba(255, 255, 255, 0.02);
}

.sidebar-upload-box p {
    font-size: 12px;
    margin-top: 8px;
    color: #64748b;
}

.sidebar-upload-box:hover p {
    color: #94a3b8;
}

/* Sidebar Styling Drawer Controls */
.theme-selector-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.theme-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 11px;
    color: #94a3b8;
    transition: var(--transition-fast);
    text-align: center;
    gap: 4px;
}

.theme-button:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-inverse);
}

.theme-button.active {
    border-color: var(--text-accent);
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-inverse);
    font-weight: 600;
}

.theme-swatch {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 12px;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- CORE WORKSPACE CONTAINER --- */
.main-workspace {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    transition: var(--transition-smooth);
}

/* Header */
.workspace-header {
    height: 80px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-main);
    padding: 0 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.back-to-landing-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-main);
    padding: 8px 12px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition-fast);
}

.back-to-landing-btn:hover {
    background: var(--border-main);
}

.dashboard-title-wrapper {
    display: flex;
    flex-direction: column;
}

.dashboard-title-header {
    font-size: 20px;
    color: var(--text-main);
    font-weight: 700;
}

.dashboard-subtitle-header {
    font-size: 13px;
    color: var(--text-muted);
}

/* Dashboard Switcher Dropdown in Header */
.header-switcher {
    position: relative;
    margin-left: 8px;
}

.switcher-trigger {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition-fast);
}

.switcher-trigger:hover {
    background: var(--bg-input);
    border-color: var(--border-focus);
}

.switcher-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 240px;
    max-height: 320px;
    overflow-y: auto;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: var(--transition-smooth);
    z-index: 60;
}

.switcher-dropdown.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.switcher-option {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-main);
}

.switcher-option:last-child {
    border-bottom: none;
}

.switcher-option:hover {
    background: var(--bg-input);
}

.switcher-option.active {
    color: var(--text-accent);
    font-weight: 600;
    background: rgba(99, 102, 241, 0.04);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.action-btn:hover {
    background: var(--bg-input);
    border-color: var(--border-focus);
}

.action-btn.primary {
    background: var(--text-accent);
    color: var(--text-inverse);
    border: 1px solid var(--text-accent);
}

.action-btn.primary:hover {
    background: opacity(0.9);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

/* Workspace Canvas Content */
.workspace-content {
    padding: 40px;
    flex-grow: 1;
}

/* Dashboard Interactive Customization bar (if layout edit is enabled) */
.dashboard-alert-bar {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--border-radius-md);
    padding: 12px 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.dashboard-alert-actions {
    display: flex;
    gap: 12px;
}

/* --- THE CANVAS GRID --- */
.canvas-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-auto-rows: 140px;
    gap: 24px;
    align-content: start;
}

/* --- CARDS & WIDGETS --- */
.dashboard-card {
    grid-column: span var(--cols, 4);
    grid-row: span var(--rows, 2);
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
    position: relative;
    min-height: 120px;
}

.dashboard-card:hover {
    box-shadow: var(--shadow-lg);
}

/* Card Header */
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
}

.card-drag-handle {
    cursor: grab;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    opacity: 0.3;
    transition: var(--transition-fast);
}

.dashboard-card:hover .card-drag-handle {
    opacity: 0.8;
}

.card-drag-handle:active {
    cursor: grabbing;
}

/* Card Actions */
.card-actions-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: var(--transition-fast);
}

.dashboard-card:hover .card-actions-menu {
    opacity: 1;
}

.card-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

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

/* Dragging visual overrides */
.dashboard-card.dragging {
    opacity: 0.5;
    border: 2px dashed var(--text-accent);
    box-shadow: var(--shadow-premium);
}

.card-body {
    padding: 24px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    justify-content: center;
    min-height: 0;
}

/* Type: Metric visual style */
.metric-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.metric-top {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
}

.metric-value {
    font-family: var(--font-header);
    font-size: 32px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.metric-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
}

.metric-change.up {
    color: #059669;
    background: rgba(5, 150, 105, 0.1);
}

.metric-change.down {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.metric-change.neutral {
    color: #4b5563;
    background: rgba(75, 85, 99, 0.1);
}

.metric-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    gap: 16px;
}

.metric-subtext {
    font-size: 12px;
    color: var(--text-muted);
    flex-grow: 1;
}

/* Canvas overlay for charts */
.chart-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 120px;
    flex-grow: 1;
}

/* Sparklines inside metrics */
.metric-sparkline-wrapper {
    width: 90px;
    height: 35px;
    flex-shrink: 0;
}

.table-wrapper {
    width: 100%;
    overflow: auto;
    flex-grow: 1;
    min-height: 0;
}

.table-element {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

.table-element th {
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-main);
    background: var(--bg-app);
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-element td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-main);
    color: var(--text-main);
}

.table-element tr:hover td {
    background: rgba(0, 0, 0, 0.01);
}

body.theme-midnight-tech .table-element tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* --- SIDEBAR EDITING DRAWER / OVERRIDES DIALOG --- */
.custom-styles-panel {
    position: fixed;
    right: -360px;
    top: 80px;
    width: 340px;
    height: calc(100vh - 80px);
    background: var(--bg-surface);
    border-left: 1px solid var(--border-main);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 35;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.custom-styles-panel.open {
    right: 0;
}

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

.css-editor-textarea {
    width: 100%;
    height: 240px;
    background: var(--bg-app);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    font-family: monospace;
    font-size: 12px;
    padding: 12px;
    color: var(--text-main);
    resize: vertical;
}

/* --- DIALOG MODALS (Upload / Error Details) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.open {
    display: flex;
}

.modal-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-premium);
    width: 90%;
    max-width: 500px;
    padding: 32px;
    position: relative;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-header {
    margin-bottom: 20px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

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

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Input boxes in form templates */
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    margin-top: 8px;
    transition: var(--transition-fast);
}

.form-input:focus {
    border-color: var(--text-accent);
    outline: none;
}

/* Validation error panel */
.error-panel {
    background: rgba(220, 38, 38, 0.05);
    border: 1px solid rgba(220, 38, 38, 0.15);
    border-radius: var(--border-radius-md);
    padding: 16px;
    color: #dc2626;
    font-size: 13px;
    font-family: monospace;
    overflow-x: auto;
    white-space: pre-wrap;
    margin-top: 12px;
    line-height: 1.5;
}

/* Global full-window Drag and Drop Overlay */
.global-drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(99, 102, 241, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.global-drag-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.global-drag-overlay h2 {
    font-size: 32px;
    margin-bottom: 12px;
}

.global-drag-overlay p {
    font-size: 18px;
    opacity: 0.8;
}

/* --- ANIMATIONS --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(16px);
        opacity: 0;
    }

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

/* --- LANDSCAPE PRINT LAYOUT STYLES --- */
@media print {
    @page {
        size: A4 landscape;
        margin: 15mm;
    }

    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        min-height: auto !important;
        font-size: 12pt;
    }

    /* Hide all interactive, sidebar, and landing panels */
    aside.sidebar,
    .workspace-header,
    .back-to-landing-btn,
    .header-actions,
    .card-actions-menu,
    .dashboard-alert-bar,
    .custom-styles-panel,
    .modal-overlay,
    .global-drag-overlay {
        display: none !important;
    }

    .workspace-layout {
        width: 100% !important;
        display: block !important;
    }

    .main-workspace {
        display: block !important;
        height: auto !important;
        overflow-y: visible !important;
    }

    .workspace-content {
        padding: 0 !important;
    }

    /* Print Title block */
    .print-header {
        display: block !important;
        margin-bottom: 30px;
        border-bottom: 2px solid #000000;
        padding-bottom: 10px;
    }

    /* Dashboard Title and Subtitle */
    .print-header h1 {
        font-size: 24pt;
        font-family: 'Outfit', sans-serif;
        color: #000000;
        margin-bottom: 5px;
    }

    .print-header p {
        font-size: 12pt;
        color: #555555;
    }

    /* Grid settings optimized for Print */
    .canvas-grid {
        display: grid !important;
        grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
        gap: 20px !important;
        width: 100% !important;
        page-break-inside: avoid;
    }

    .dashboard-card {
        border: 1px solid #cccccc !important;
        box-shadow: none !important;
        background: #ffffff !important;
        page-break-inside: avoid;
        break-inside: avoid;
        min-height: auto !important;
    }

    .table-element th {
        background: #eeeeee !important;
        border-bottom: 1px solid #999999 !important;
        color: #000000 !important;
    }

    .table-element td {
        border-bottom: 1px solid #dddddd !important;
        color: #000000 !important;
    }

    .metric-change {
        border: 1px solid #cccccc !important;
    }
}

/* Hide print header during normal viewing */
.print-header {
    display: none;
}

/* --- AUTHENTICATION & MULTI-TENANCY INTERFACE --- */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-app);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(10px);
}

.auth-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-premium);
    width: 90%;
    max-width: 400px;
    padding: 40px;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h2 {
    font-family: var(--font-header);
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.invite-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: var(--text-accent);
    color: white;
    border-radius: 9999px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.invite-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-input);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    padding: 14px 18px;
}

.invite-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.invite-actions {
    display: flex;
    gap: 8px;
}

/* --- DATA LIBRARY & DROPZONE STYLES --- */
.file-dropzone {
    border: 2px dashed var(--text-accent);
    background: var(--bg-surface);
    border-radius: var(--border-radius-lg);
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.file-dropzone:hover,
.file-dropzone.hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--text-accent);
}

.data-file-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-main);
    border-radius: var(--border-radius-md);
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.data-file-card:hover {
    box-shadow: var(--shadow-md);
}

.card-warning-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 16px;
    text-align: center;
    background: rgba(239, 68, 68, 0.05);
    border: 1px dashed rgba(239, 68, 68, 0.3);
    border-radius: var(--border-radius-md);
    color: #ef4444;
}