:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --accent: #ff5f38;
    --accent-hover: #e04f2a;
    --accent-light: #fff0eb;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 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);
    --success: #10b981;
    --success-bg: #ecfdf5;
    --error: #ef4444;
    --error-bg: #fef2f2;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --chart-grid: rgba(17, 24, 39, 0.06);
}

:root.dark {
    --bg-primary: #0a0b0d;
    --bg-secondary: #111317;
    --bg-tertiary: #1b1e24;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #ff7554;
    --accent-hover: #ff8c70;
    --accent-light: #2d1813;
    --border-color: #22252a;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --success: #34d399;
    --success-bg: #064e3b;
    --error: #f87171;
    --error-bg: #7f1d1d;
    --warning: #fbbf24;
    --warning-bg: #451a03;
    --chart-grid: rgba(255, 255, 255, 0.08);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    padding-bottom: 4rem;
}

h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--text-primary);
}

a {
    color: inherit;
    text-decoration: none;
}

.demo-container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.demo-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.demo-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 0.5rem 0.9rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.back-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.back-link svg {
    width: 1rem;
    height: 1rem;
}

.demo-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    background-color: var(--accent-light);
    padding: 0.3rem 0.7rem;
    border-radius: 9999px;
}

.demo-theme-toggle {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.demo-theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.demo-theme-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
}

.demo-theme-toggle .moon-icon { display: none; }
.dark .demo-theme-toggle .sun-icon { display: none; }
.dark .demo-theme-toggle .moon-icon { display: block; }

.demo-header {
    padding: 2.5rem 0 2rem;
}

.demo-header h1 {
    font-size: 2rem;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.demo-header p {
    color: var(--text-secondary);
    max-width: 640px;
    font-size: 1rem;
}

.demo-note {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.demo-note svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.control-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tab-group {
    display: flex;
    background-color: var(--bg-tertiary);
    padding: 0.25rem;
    border-radius: 10px;
    gap: 0.2rem;
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 0.45rem 0.9rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    border-radius: 7px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.tab-btn.active {
    background-color: var(--bg-primary);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.tab-btn:focus-visible, .chip-btn:focus-visible, .back-link:focus-visible,
.demo-theme-toggle:focus-visible, .expand-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chip-btn .chip-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.5;
}

.chip-btn.active {
    border-color: var(--chip-color, var(--accent));
    color: var(--chip-color, var(--accent));
    background-color: var(--chip-bg, var(--accent-light));
}

.chip-btn.active .chip-dot {
    opacity: 1;
}

.search-input {
    flex: 1;
    min-width: 180px;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 9px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.4rem;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 1.85rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.stat-change {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
}

.stat-change svg { width: 0.85rem; height: 0.85rem; }
.stat-change.positive { background-color: var(--success-bg); color: var(--success); }
.stat-change.negative { background-color: var(--error-bg); color: var(--error); }
.stat-change.neutral { background-color: var(--warning-bg); color: var(--warning); }

.panel-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.panel {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.75rem;
}

.panel h2 {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
}

.chart-wrap {
    position: relative;
    height: 300px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 0.65rem 0.6rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table .cell-strong {
    color: var(--text-primary);
    font-weight: 600;
}

.expand-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.expand-row:hover {
    background-color: var(--bg-tertiary);
}

.expand-detail {
    display: none;
    background-color: var(--bg-tertiary);
}

.expand-detail.open {
    display: table-row;
}

.expand-detail td {
    padding: 1rem;
}

.mini-bars {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 60px;
}

.mini-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.mini-bar {
    width: 100%;
    border-radius: 3px 3px 0 0;
    background-color: var(--accent);
    opacity: 0.85;
}

.mini-bar-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    color: var(--text-muted);
}

.stock-pill {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
}

.stock-pill.ok { background-color: var(--success-bg); color: var(--success); }
.stock-pill.low { background-color: var(--warning-bg); color: var(--warning); }
.stock-pill.critical { background-color: var(--error-bg); color: var(--error); }

.slider-block {
    margin-bottom: 1.5rem;
}

.slider-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.slider-row .slider-value {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent);
    font-size: 0.95rem;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--border-color);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-primary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-primary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
}

.result-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.4rem;
    border-radius: 14px;
    margin-top: 1rem;
    font-family: var(--font-heading);
}

.result-banner.good { background-color: var(--success-bg); color: var(--success); }
.result-banner.warn { background-color: var(--warning-bg); color: var(--warning); }
.result-banner.bad { background-color: var(--error-bg); color: var(--error); }

.result-banner svg { width: 1.5rem; height: 1.5rem; flex-shrink: 0; }

.result-banner .result-title {
    font-weight: 700;
    font-size: 1rem;
    display: block;
}

.result-banner .result-sub {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.82rem;
    opacity: 0.85;
}

@media (max-width: 900px) {
    .panel-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .demo-header h1 { font-size: 1.6rem; }
    .control-bar { flex-direction: column; align-items: stretch; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

.custom-bar-chart {
    width: 100%;
    height: 100%;
    min-height: 200px;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 0.75rem;
    padding-top: 1.5rem;
    padding-bottom: 2rem;
    position: relative;
    border-bottom: 1.5px solid var(--border-color);
}

.custom-chart-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    position: relative;
}

.custom-chart-seg {
    width: 100%;
    border-radius: 3px 3px 0 0;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.85;
}

.custom-chart-seg:hover {
    opacity: 1;
    filter: brightness(1.05);
}

.custom-chart-bar {
    width: 100%;
    border-radius: 6px 6px 0 0;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.85;
}

.custom-chart-bar:hover {
    opacity: 1;
    filter: brightness(1.05);
}

.custom-chart-label {
    position: absolute;
    bottom: -1.75rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

#roiChart, #cashChart, #salesChart, #inventoryChart {
    position: relative;
    width: 100%;
    height: 100%;
}

.chart-active-dot {
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: #ffffff;
    border: 3px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 10;
    transition: left 0.15s ease, top 0.15s ease;
}

.chart-active-dot:hover {
    transform: translate(-50%, -50%) scale(1.2);
}

@media (max-width: 600px) {
    .chart-wrap {
        height: 180px !important;
    }
    .custom-bar-chart {
        min-height: 150px !important;
        padding-top: 1rem;
        padding-bottom: 1.5rem;
    }
    .custom-chart-label {
        font-size: 0.55rem;
        bottom: -1.25rem;
    }
}
