:root {
    /* CINETIQUE LIGHT THEME */
    --bg-app: #f3f4f6;
    /* Light Gray background */
    --bg-panel: #ffffff;
    /* White panels */
    --text-main: #1f2937;
    /* Dark Gray text */
    --text-muted: #64748b;
    /* Muted text */
    --accent: #2563eb;
    /* Blue-600 */
    --accent-hover: #1d4ed8;
    /* Blue-700 */
    --border: #e2e8f0;
    /* Light border */
    --success: #16a34a;
    /* Green-600 */
    --danger: #dc2626;
    /* Red-600 */
    --warning: #ca8a04;
    /* Yellow-600 */

    --primary: var(--accent);
    --primary-light: #3b82f6;
    --secondary: var(--warning);
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-800: #1e293b;
    --slate-900: #0f172a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
}

/* MAIN CONTAINER (Flex Column: Buffer Header + Content) */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* HEADER */
.app-header {
    height: 60px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.icon-box {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent);
}

h1 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.05em;
}

/* MAIN GRID */
.app-grid {
    flex: 1;
    display: grid;
    /* Sidebar | Center | Right */
    grid-template-columns: 280px 1fr 1fr;
    /* Top Row (60%) | Bottom Row (40%) */
    grid-template-rows: 60% 40%;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow: hidden;
}

/* CARDS */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-label {
    position: absolute;
    top: 0.75rem;
    left: 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    z-index: 10;
    text-transform: uppercase;
}

/* SIDEBAR CONTROLS */
.sidebar {
    grid-column: 1;
    grid-row: 1 / 3;
    /* Full Height */
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

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

.label-small {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* SWITCH BUTTON */
.btn-switch {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f1f5f9;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.btn-switch:hover {
    background: #e2e8f0;
    border-color: var(--text-muted);
}

.btn-switch.charge {
    border-color: rgba(37, 99, 235, 0.5);
    /* Blue-600 */
    color: #58a6ff;
    /* Accent Blue */
    background: rgba(37, 99, 235, 0.1);
}

.btn-switch.discharge {
    border-color: rgba(234, 88, 12, 0.5);
    /* Orange-600 */
    color: #fca311;
    /* Bright Orange */
    background: rgba(234, 88, 12, 0.1);
}

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

.group-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-main);
}

.value-tag {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.75rem;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    background: #f1f5f9;
    border: 1px solid var(--border);
}

.value-tag.blue {
    color: var(--accent);
    border-color: rgba(37, 99, 235, 0.3);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* INFO CARD */
.info-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    text-align: center;
}

.val-big {
    font-family: 'Roboto Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0.5rem 0;
}

.sub-text {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* MICRO SECTION */
.micro-section {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* SPLIT GRAPHS */
.split-graphs {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1.5rem 0.5rem 0.5rem 0.5rem;
    gap: 0.5rem;
}

.graph-container {
    flex: 1;
    position: relative;
    border-bottom: 1px solid var(--border);
    min-height: 0;
}

.graph-container:last-child {
    border-bottom: none;
}

.graph-label {
    position: absolute;
    top: 0;
    right: 0;
    font-size: 0.6rem;
    font-weight: 700;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 2px 4px;
    border-radius: 4px;
}

/* BADGES */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge.charge {
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent);
    border: 1px solid var(--accent);
}

.badge.discharge {
    background: rgba(202, 138, 4, 0.1);
    color: var(--warning);
    border: 1px solid var(--warning);
}

.visual-card {
    grid-column: 3;
    grid-row: 1;
}

/* 4. PHASE (Center - Bottom) */
.phase-card {
    grid-column: 2;
    grid-row: 2;
}

/* 5. ENERGY (Right - Bottom) */
.energy-card {
    grid-column: 3;
    grid-row: 2;
    padding: 1rem;
    justify-content: center;
}

/* CANVAS WRAPPER */
.canvas-wrapper {
    width: 100%;
    height: 100%;
    padding: 1.5rem 0.5rem 0.5rem 0.5rem;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* CONTROLS UI */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.group-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 600;
}

.value-tag {
    color: var(--blue-primary);
    font-family: monospace;
    font-size: 0.8rem;
}

input[type=range] {
    width: 100%;
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    accent-color: var(--blue-primary);
}

.switch-section {
    background: #f8fafc;
    /* Darker than panel */
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.label-small {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
}

.btn-switch {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f1f5f9;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.btn-switch:hover {
    background: #e2e8f0;
    border-color: var(--text-muted);
}

.btn-switch.charge {
    border-color: rgba(37, 99, 235, 0.5);
    /* Blue-600 */
    color: #58a6ff;
    /* Accent Blue */
    background: rgba(37, 99, 235, 0.1);
}

.btn-switch.discharge {
    border-color: rgba(234, 88, 12, 0.5);
    /* Orange-600 */
    color: #fca311;
    /* Bright Orange */
    background: rgba(234, 88, 12, 0.1);
}

.info-card {
    margin-top: auto;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.val-big {
    font-size: 1.4rem;
    font-family: monospace;
    font-weight: 700;
    color: var(--text-main);
}

.sub-text {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* TABS (Legacy removed, keeping clean) */
.tab-header {
    display: none;
}

.tab-btn {
    display: none;
}

.tab-content {
    width: 100%;
    height: 100%;
    padding-top: 1.5rem;
}

.view-layer {
    width: 100%;
    height: 100%;
    display: none;
}

.view-layer.active {
    display: block;
}

/* ENERGY BARS */
.energy-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.energy-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.energy-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
}

.bar-track {
    height: 12px;
    background: #e2e8f0;
    /* Very dark track */
    border-radius: 6px;
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.1s linear;
}

.bar-fill.blue {
    background-color: var(--accent);
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.4);
}

.bar-fill.orange {
    background-color: var(--warning);
    box-shadow: 0 0 8px rgba(210, 153, 34, 0.4);
}

.note {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 0.5rem;
    font-style: italic;
}

/* MEDIA QUERY */
@media (max-width: 900px) {

    body,
    html {
        height: auto !important;
        overflow-y: auto !important;
    }

    .app-container {
        height: auto !important;
        overflow: visible !important;
    }

    .app-grid {
        display: flex;
        flex-direction: column;
        overflow: visible !important;
        height: auto !important;
        gap: 1rem;
    }

    /* Reorder: Visuals First, Controls (Sidebar) Second? 
       Actually user complained console not accessible. 
       If it is first, it should be top. 
       Let's keep DOM order (Sidebar first) but ensure it scrolls.
    */

    .sidebar {
        min-height: auto;
        /* Optional: limit height of sidebar components if needed */
    }

    .card {
        min-height: 300px;
        /* Give graphs enough space */
    }

    /* Adjust Micro View Canvas height on mobile */
    .micro-section canvas {
        height: 100px;
    }
}