/* ===== Roast Chart Theme Variables ===== */
:root {
    --chart-bg: #ffffff;
    --chart-text: #333333;
    --chart-text-muted: #888888;
    --chart-grid: #e5e5e5;
    --chart-card-bg: #f8f9fa;
    --chart-border: #dee2e6;
    --chart-card-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

html[data-coffee-dark="true"] {
    --chart-bg: #1a1a2e;
    --chart-text: #e0e0e0;
    --chart-text-muted: #8888aa;
    --chart-grid: #333355;
    --chart-card-bg: #16213e;
    --chart-border: #2a2a4a;
    --chart-card-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ===== Page Layout ===== */
.roast-chart-page {
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    /* AppBar 64px + MudMainContent padding 24px top + 24px bottom + 8px buffer */
    height: calc(100vh - 120px);
}

/* Main body: chart left + info panel right */
.roast-chart-body {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.roast-chart-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow: hidden;
}

/* ===== Header ===== */
.roast-chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: var(--chart-card-bg);
    border-radius: 0.5rem;
    border: 1px solid var(--chart-border);
    box-shadow: var(--chart-card-shadow);
    min-height: 2rem;
    flex-shrink: 0;
}

.roast-chart-header h4 {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    color: var(--chart-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

/* ===== Chart Container ===== */
.roast-chart-container {
    width: 100%;
    flex: 1;
    min-height: 0;
    background: var(--chart-card-bg);
    border-radius: 0.5rem;
    border: 1px solid var(--chart-border);
    box-shadow: var(--chart-card-shadow);
    padding: 0.25rem;
    box-sizing: border-box;
    overflow: hidden;
}

.roast-chart-container > div {
    height: 100% !important;
}

.roast-chart-container .apexcharts-canvas {
    max-width: 100% !important;
    height: 100% !important;
}

.roast-chart-container .apexcharts-svg {
    max-width: 100% !important;
}

/* ===== Right Panel (Info + Controls) ===== */
.roast-right-panel {
    width: 260px;
    min-width: 260px;
}

.roast-info-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    scrollbar-width: thin;
    flex: 1;
}

.info-section {
    background: var(--chart-card-bg);
    border: 1px solid var(--chart-border);
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    box-shadow: var(--chart-card-shadow);
}

.info-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--chart-text-muted);
    margin-bottom: 0.4rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--chart-border);
}

/* Timer */
.timer-section {
    text-align: center;
    padding: 0.75rem;
}

.info-icon {
    font-size: 1.2rem;
    margin-bottom: 0.15rem;
}

.timer-display {
    font-size: 1.8rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--chart-text);
    letter-spacing: 0.02em;
    line-height: 1.1;
}

.info-sublabel {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--chart-text-muted);
    margin-top: 0.15rem;
}

/* Temp cards */
.temp-row {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.temp-row:last-child {
    margin-bottom: 0;
}

.temp-card {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border-radius: 0.4rem;
    text-align: center;
}

.temp-card .temp-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.9;
}

.temp-card .temp-value {
    font-size: 1.15rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.temp-card .temp-unit {
    font-size: 0.6rem;
    font-weight: 500;
    opacity: 0.7;
    margin-left: 1px;
}

.et-card {
    background: rgba(204, 15, 80, 0.1);
    border: 1px solid rgba(204, 15, 80, 0.25);
    color: #cc0f50;
}

.bt-card {
    background: rgba(10, 92, 144, 0.1);
    border: 1px solid rgba(10, 92, 144, 0.25);
    color: #0a5c90;
}

.delta-et-card {
    background: rgba(255, 140, 0, 0.1);
    border: 1px solid rgba(255, 140, 0, 0.25);
    color: #ff8c00;
}

.delta-bt-card {
    background: rgba(44, 160, 44, 0.1);
    border: 1px solid rgba(44, 160, 44, 0.25);
    color: #2ca02c;
}

html[data-coffee-dark="true"] .et-card {
    background: rgba(204, 15, 80, 0.15);
    border-color: rgba(204, 15, 80, 0.35);
}

html[data-coffee-dark="true"] .bt-card {
    background: rgba(10, 92, 144, 0.15);
    border-color: rgba(10, 92, 144, 0.35);
}

html[data-coffee-dark="true"] .delta-et-card {
    background: rgba(255, 140, 0, 0.15);
    border-color: rgba(255, 140, 0, 0.35);
}

html[data-coffee-dark="true"] .delta-bt-card {
    background: rgba(44, 160, 44, 0.15);
    border-color: rgba(44, 160, 44, 0.35);
}

/* Events list */
.events-list {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.event-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid var(--chart-border);
}

.event-row:last-child {
    border-bottom: none;
}

.event-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.event-name {
    font-weight: 600;
    color: var(--chart-text);
    flex: 1;
}

.event-time {
    font-variant-numeric: tabular-nums;
    color: var(--chart-text-muted);
    font-size: 0.72rem;
}

.event-temp {
    font-weight: 600;
    color: var(--chart-text);
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: right;
}

/* Phase rows */
.phase-rows {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.phase-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.2rem 0;
}

.phase-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.phase-name {
    font-weight: 600;
    color: var(--chart-text);
    flex: 1;
}

.phase-info {
    font-variant-numeric: tabular-nums;
    color: var(--chart-text-muted);
}

.phase-pct {
    font-weight: 700;
    color: var(--chart-text);
    min-width: 38px;
    text-align: right;
}

/* Info rows */
.info-rows {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    padding: 0.15rem 0;
}

.info-key {
    color: var(--chart-text-muted);
}

.info-val {
    font-weight: 700;
    color: var(--chart-text);
    font-variant-numeric: tabular-nums;
}

/* ===== Phase Statistics Bar ===== */
.phase-stats-bar {
    display: flex;
    border-radius: 0.5rem;
    overflow: hidden;
    height: 1.75rem;
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--chart-border);
    box-shadow: var(--chart-card-shadow);
    width: 100%;
}

.phase-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    color: #fff;
    padding: 0 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.phase-segment.drying { background: #4CAF50; }
.phase-segment.maillard { background: #E8A317; }
.phase-segment.development { background: #795548; }
.phase-segment .phase-label { font-weight: 700; }
.phase-segment .phase-time { opacity: 0.9; }
.phase-segment .phase-percent { opacity: 0.85; font-size: 0.72rem; }

/* ===== RoR Config Panel ===== */
.ror-config-panel {
    background: var(--chart-card-bg);
    border-radius: 0.5rem;
    border: 1px solid var(--chart-border);
    box-shadow: var(--chart-card-shadow);
    padding: 0.75rem;
    width: 100%;
    box-sizing: border-box;
}

.ror-config-panel .config-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--chart-text);
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
}

.ror-config-panel .config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem 1rem;
}

.config-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.config-item label {
    font-size: 0.78rem;
    color: var(--chart-text);
    min-width: 75px;
}

.config-item input[type="range"] {
    flex: 1;
    min-width: 60px;
}

.config-item .value-badge {
    font-size: 0.72rem;
    background: var(--chart-border);
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    min-width: 1.5rem;
    text-align: center;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    background: none;
    border: 1px solid var(--chart-border);
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--chart-text);
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--chart-border);
}

/* ===== Responsive ===== */

/* Tablet landscape & small desktop (<=1024px) */
@media (max-width: 1024px) {
    .roast-right-panel {
        width: 220px;
        min-width: 220px;
    }
}

/* Tablet portrait (<=900px): stack chart + info vertically */
@media (max-width: 900px) {
    .roast-chart-page {
        height: auto;
        min-height: calc(100vh - 120px);
        overflow-y: auto;
    }

    .roast-chart-body {
        flex-direction: column;
    }

    .roast-right-panel {
        width: 100%;
        min-width: unset;
    }

    .roast-info-panel {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-y: visible;
    }

    .roast-info-panel .info-section {
        flex: 1;
        min-width: 200px;
    }

    .roast-info-panel .timer-section {
        min-width: 140px;
        flex: 0;
    }

    .roast-chart-container {
        min-height: 300px;
    }

    .roast-chart-header {
        gap: 0.3rem;
        padding: 0.3rem 0.5rem;
    }
}

/* Small tablet / large phone (<=600px) */
@media (max-width: 600px) {
    .roast-chart-page {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .roast-chart-header {
        flex-direction: column;
        align-items: stretch;
    }

    .roast-chart-header h4 {
        font-size: 0.9rem;
    }

    .roast-chart-container {
        min-height: 250px;
    }

    .roast-info-panel .info-section {
        min-width: 150px;
    }

    .timer-display {
        font-size: 1.4rem;
    }

    .temp-card .temp-value {
        font-size: 1rem;
    }

    .phase-stats-bar {
        height: 1.5rem;
        font-size: 0.68rem;
    }

    .info-section-title {
        font-size: 0.65rem;
    }

    .event-row, .phase-row, .info-row {
        font-size: 0.7rem;
    }
}

/* Phone (<=480px) */
@media (max-width: 480px) {
    .roast-chart-page {
        padding: 0.2rem;
    }

    .roast-chart-header h4 {
        font-size: 0.85rem;
    }

    .roast-chart-container {
        min-height: 220px;
    }

    .ror-config-panel .config-grid {
        grid-template-columns: 1fr;
    }

    .roast-info-panel {
        flex-direction: column;
    }

    .roast-info-panel .info-section {
        min-width: unset;
    }

    .temp-row {
        gap: 0.25rem;
    }

    .temp-card {
        padding: 0.3rem 0.4rem;
    }

    .temp-card .temp-value {
        font-size: 0.9rem;
    }

    .timer-display {
        font-size: 1.2rem;
    }
}
