/**
 * Driftsovervaking Dashboard - Monitoring Control Room Style
 *
 * Layout: 3-column grid optimized for monitoring
 * - LEFT: Alarms (prominent)
 * - CENTER: Gauges and KPIs
 * - RIGHT: Plant status and charts
 */

/* ============================================
   BASE LAYOUT
   ============================================ */

body {
    background: var(--bg-page);
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.monitoring-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0.75rem;
    box-sizing: border-box;
    gap: 0.75rem;
}

/* ============================================
   HEADER
   ============================================ */

.monitoring-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-header);
    padding: 0.75rem 1.25rem;
    border-radius: 0;
    box-shadow: var(--shadow-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.monitoring-logo {
    height: 50px;
    width: auto;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.header-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
}

.header-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

.header-right {
    display: flex;
    align-items: center;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-details {
    text-align: right;
    color: white;
}

.status-text {
    font-size: 0.9rem;
    font-weight: 600;
}

.status-time {
    font-size: 0.7rem;
    opacity: 0.8;
}

/* Large System LED */
.status-led-large {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 10px var(--success), 0 0 20px rgba(16, 185, 129, 0.5);
    animation: led-pulse 2s infinite;
}

.status-led-large.warning {
    background: var(--warning);
    box-shadow: 0 0 10px var(--warning), 0 0 20px rgba(255, 184, 77, 0.5);
}

.status-led-large.offline,
.status-led-large.error {
    background: var(--error);
    box-shadow: 0 0 10px var(--error), 0 0 20px rgba(244, 114, 182, 0.5);
    animation: led-blink 1s infinite;
}

@keyframes led-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes led-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ============================================
   MAIN GRID - 3 COLUMNS
   ============================================ */

.monitoring-grid {
    display: grid;
    grid-template-columns: 280px 1fr 1fr;
    gap: 0.75rem;
    flex: 1;
    min-height: 0;
}

.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

/* ============================================
   LEFT COLUMN: ALARMS (Prominent)
   ============================================ */

.alarm-section {
    background: var(--bg-card);
    border-radius: 0;
    padding: 1rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Alarm Summary Counters */
.alarm-summary {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.alarm-counter {
    flex: 1;
    text-align: center;
    padding: 0.75rem 0.5rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.alarm-counter.critical {
    background: rgba(244, 114, 182, 0.15);
    border: 1px solid var(--error);
}

.alarm-counter.warning {
    background: rgba(255, 184, 77, 0.15);
    border: 1px solid var(--warning);
}

.alarm-counter.ok {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid var(--success);
}

.alarm-count-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
}

.alarm-counter.critical .alarm-count-value { color: var(--error); }
.alarm-counter.warning .alarm-count-value { color: var(--warning); }
.alarm-counter.ok .alarm-count-value { color: var(--success); }

.alarm-count-label {
    display: block;
    font-size: 0.6rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-top: 0.25rem;
}

/* LED Bank */
.alarm-led-bank {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.led-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: 0.5rem;
}

.led-row:last-child {
    margin-bottom: 0;
}

.alarm-led-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.alarm-led-item span {
    font-size: 0.55rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
}

.alarm-led {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--neutral-600);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.alarm-led.active {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
    animation: led-blink 1.5s infinite;
}

.alarm-led.error {
    background: var(--error);
    box-shadow: 0 0 8px var(--error);
    animation: led-blink 0.5s infinite;
}

.alarm-led.ok {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* Alarm List */
.alarm-list-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.alarm-list {
    flex: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 0.5rem;
}

.alarm-empty {
    text-align: center;
    padding: 1.5rem;
    color: var(--success);
    font-size: 0.85rem;
}

.alarm-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    margin-bottom: 0.35rem;
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid transparent;
    font-size: 0.75rem;
}

.alarm-item.warning {
    border-left-color: var(--warning);
    background: rgba(255, 184, 77, 0.1);
}

.alarm-item.error {
    border-left-color: var(--error);
    background: rgba(244, 114, 182, 0.1);
}

.alarm-item-icon {
    font-size: 1rem;
}

.alarm-item-text {
    color: var(--text-secondary);
}

/* ============================================
   CENTER COLUMN: GAUGES
   ============================================ */

.gauges-section {
    background: var(--bg-card);
    border-radius: 0;
    padding: 1rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow: hidden;
}

/* Gauge Panel */
.gauge-panel {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.gauge-container {
    flex: 1;
    text-align: center;
}

.gauge {
    width: 100%;
    max-width: 160px;
    height: auto;
}

.gauge-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 12;
    stroke-linecap: round;
}

.gauge-fill {
    fill: none;
    stroke: var(--success);
    stroke-width: 12;
    stroke-linecap: round;
    transition: stroke-dasharray 0.5s ease;
}

.gauge-fill.daily {
    stroke: var(--secondary-400);
}

.gauge-fill.warning {
    stroke: var(--warning);
}

.gauge-fill.critical {
    stroke: var(--error);
}

.gauge-tick {
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 2;
}

.gauge-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 0.5rem;
}

.gauge-label {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
}

.gauge-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.gauge-stat {
    text-align: center;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    min-width: 80px;
}

.gauge-stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-400);
}

.gauge-stat-label {
    display: block;
    font-size: 0.55rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-top: 0.15rem;
}

/* KPI Boxes */
.kpi-boxes {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

.kpi-box {
    flex: 1;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 0.75rem;
    text-align: center;
}

.kpi-box-value {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--secondary-400);
}

.kpi-box-label {
    font-size: 0.55rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-top: 0.25rem;
}

/* ============================================
   RIGHT COLUMN: PLANT STATUS + CHARTS
   ============================================ */

.status-section {
    background: var(--bg-card);
    border-radius: 0;
    padding: 1rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Plant Cards */
.plant-cards {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.plant-card {
    flex: 1;
    min-width: 140px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 0.75rem;
}

.plant-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.plant-card-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.plant-card-led {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.status-led {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--neutral-500);
}

.status-led.online {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-led.warning {
    background: var(--warning);
    box-shadow: 0 0 6px var(--warning);
}

.status-led.offline {
    background: var(--error);
    box-shadow: 0 0 6px var(--error);
}

.plant-card-status {
    font-size: 0.55rem;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.plant-card-metrics {
    display: flex;
    gap: 0.75rem;
}

.plant-metric {
    text-align: center;
}

.plant-metric-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.plant-metric-label {
    font-size: 0.5rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
}

/* Device Toggle Button */
.device-toggle-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1;
    letter-spacing: 0.02em;
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.3);
    text-underline-offset: 2px;
}

.device-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.4);
    color: var(--text-primary);
    text-decoration-color: rgba(255, 255, 255, 0.6);
}

/* Expandable Device Section */
.device-section {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.device-section.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

/* Device Card */
.device-card {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 3px;
    padding: 0.5rem;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

.device-card-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
}

.device-card-name {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex: 1;
}

.device-fault-badge {
    font-size: 0.5rem;
    background: var(--error);
    color: #fff;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    font-weight: 700;
    text-transform: uppercase;
}

.device-card-metrics {
    display: flex;
    gap: 0.75rem;
}

.device-metric {
    text-align: center;
}

.device-metric-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.device-metric-label {
    font-size: 0.45rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
}

/* Small status LED (for device cards) */
.status-led.small {
    width: 7px;
    height: 7px;
}

/* Chart Tabs */
.chart-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.chart-tab {
    flex: 1;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-light);
    border-radius: 0;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.chart-tab:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chart-tab.active {
    background: var(--primary-500);
    color: white;
    border-color: var(--primary-600);
}

/* Chart Panel */
.chart-panel {
    flex: 1;
    min-height: 150px;  /* Ensure chart has visible height */
    position: relative;
}

.chart-content {
    display: none;
    position: absolute;
    inset: 0;
}

.chart-content.active {
    display: block;
}

.chart-content canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================
   FOOTER
   ============================================ */

.monitoring-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    color: var(--text-tertiary);
    font-size: 0.65rem;
}

.footer-logo {
    height: 24px;
    width: auto;
}

/* ============================================
   PERFORMANCE RATIO CARD
   ============================================ */

.pr-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 1rem;
    border-left: 4px solid var(--neutral-500);
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.pr-card.pr-good {
    border-left-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

.pr-card.pr-warning {
    border-left-color: var(--warning);
    background: rgba(255, 184, 77, 0.1);
}

.pr-card.pr-poor {
    border-left-color: var(--error);
    background: rgba(244, 114, 182, 0.1);
}

.pr-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.pr-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pr-value-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.pr-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.pr-good .pr-value {
    color: var(--success);
}

.pr-warning .pr-value {
    color: var(--warning);
}

.pr-poor .pr-value {
    color: var(--error);
}

.pr-status {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-tertiary);
}

.pr-good .pr-status {
    color: var(--success);
    background: rgba(16, 185, 129, 0.2);
}

.pr-warning .pr-status {
    color: var(--warning);
    background: rgba(255, 184, 77, 0.2);
}

.pr-poor .pr-status {
    color: var(--error);
    background: rgba(244, 114, 182, 0.2);
}

.pr-details {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

.pr-expected {
    color: var(--text-tertiary);
}

/* ============================================
   TREND INDICATOR
   ============================================ */

.trend-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
}

.trend-indicator.up {
    color: var(--success);
    background: rgba(16, 185, 129, 0.15);
}

.trend-indicator.down {
    color: var(--error);
    background: rgba(244, 114, 182, 0.15);
}

.trend-indicator.flat {
    color: var(--text-tertiary);
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================
   STRING BALANCE ALERT
   ============================================ */

.string-alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 184, 77, 0.15);
    border-left: 4px solid var(--warning);
    border-radius: 4px;
}

.string-alert-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.string-alert-content {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.string-alert-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--warning);
}

.string-alert-details {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1200px) {
    .monitoring-grid {
        grid-template-columns: 250px 1fr;
    }

    /* Status-section flyttes under gauge-section i neste rad */
    .status-section {
        grid-column: 1 / -1;
        max-height: 350px;
    }
}

@media (max-width: 900px) {
    /* Enable scrolling on tablet/mobile */
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    .monitoring-layout {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .monitoring-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
    }

    .alarm-section,
    .gauges-section,
    .status-section {
        min-height: auto;
    }

    /* Overstyr grid-column fra 1200px-regelen */
    .status-section {
        display: flex;
        grid-column: auto;
        max-height: none;
    }

    /* Stack sections vertically - alarms first (most important) */
    .alarm-section { order: 1; }
    .gauges-section { order: 2; }
    .status-section { order: 3; }
}

/* Mobile-specific (phones) */
@media (max-width: 600px) {
    .monitoring-layout {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .monitoring-header {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-left {
        flex: 1;
        min-width: 200px;
    }

    .monitoring-logo {
        height: 36px;
    }

    .header-title {
        font-size: 0.9rem;
    }

    .header-subtitle {
        font-size: 0.65rem;
    }

    /* Gauges - single column */
    .gauge-panel {
        flex-direction: column;
        padding: 0.75rem;
    }

    .gauge-container {
        max-width: 200px;
        margin: 0 auto;
    }

    .gauge-stats {
        flex-direction: row;
        justify-content: center;
        gap: 1rem;
    }

    .gauge-value {
        font-size: 1.25rem;
    }

    /* KPI boxes - wrap */
    .kpi-boxes {
        flex-wrap: wrap;
    }

    .kpi-box {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 100px;
    }

    /* PR Card */
    .pr-value {
        font-size: 1.5rem;
    }

    /* Alarms - compact */
    .alarm-summary {
        flex-wrap: wrap;
    }

    .alarm-counter {
        flex: 1 1 calc(33% - 0.35rem);
        padding: 0.5rem;
    }

    .alarm-count-value {
        font-size: 1.2rem;
    }

    .alarm-led-bank {
        padding: 0.5rem;
    }

    .alarm-led {
        width: 12px;
        height: 12px;
    }

    /* Plant cards - stack vertikalt på smale skjermer */
    .plant-cards {
        flex-direction: column;
    }

    .plant-card {
        min-width: auto;
    }

    .plant-card-metrics {
        justify-content: space-around;
    }

    /* Charts - gi nok høyde */
    .chart-panel {
        min-height: 200px;
    }

    /* Footer */
    .monitoring-footer {
        padding: 0.75rem;
    }

    .footer-logo {
        height: 20px;
    }
}

/* ============================================
   TV MODE - Auto-scales via rem cascade
   html font-size is set by JS (autoScaleToFit) based on viewport.
   All rem-based sizes scale automatically. Only structural overrides here.
   ============================================ */

body[data-mode="tv"] {
    overflow: hidden !important;
    height: 100vh !important;
}

body[data-mode="tv"] .monitoring-layout {
    height: 100vh;
    overflow: hidden;
    padding: 0.5rem;
    gap: 0.5rem;
}

body[data-mode="tv"] .monitoring-grid {
    grid-template-columns: 15.625rem 1fr 1fr;
    gap: 0.5rem;
    overflow: hidden;
}

body[data-mode="tv"] .monitoring-header {
    padding: 0.4rem 0.75rem;
}

body[data-mode="tv"] .monitoring-logo {
    height: 2rem;
}

body[data-mode="tv"] .alarm-section {
    overflow: hidden;
}

body[data-mode="tv"] .alarm-list-container {
    overflow: hidden;
}

body[data-mode="tv"] .gauge-panel {
    padding: 0.5rem;
}

body[data-mode="tv"] .monitoring-footer {
    padding: 0.3rem 0.75rem;
}

body[data-mode="tv"] .footer-logo {
    height: 1.25rem;
}

/* TV: Hide low-priority components on small screens */
@media (max-height: 800px) {
    body[data-mode="tv"] .string-alert {
        display: none !important;
    }
    body[data-mode="tv"] .monitoring-footer span {
        display: none;
    }
}

@media (max-height: 650px) {
    body[data-mode="tv"] .pr-card {
        display: none !important;
    }
}
