/* =============================================================
   SunMonitor — Diagnostics Page Styles v1.1
   ============================================================= */

.diag-page {
    max-width: 1320px;
    margin: 0 auto;
    padding: 1rem 0.9rem 2rem;
}

/* --- Controls ----------------------------------------------- */
.diag-controls {
    background: var(--card-bg, #fff);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 18px;
    padding: 1.15rem;
    margin-bottom: 1rem;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.diag-controls-row {
    display: grid;
    grid-template-columns: 1.1fr 1fr 1.2fr 0.7fr;
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.diag-select-group {
    flex: 1;
    min-width: 180px;
}

.diag-panel-group {
    flex: 1.4;
    min-width: 260px;
}

.diag-select-group label {
    display: block;
    font-size: 0.69rem;
    font-weight: 700;
    color: var(--text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.35rem;
}

.diag-select-group select {
    width: 100%;
    min-height: 40px;
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    background: var(--input-bg, #fff);
    color: var(--text, #1f2937);
    font-size: 0.875rem;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
}

.diag-select-group select:focus,
.diag-option input:focus,
.diag-option select:focus {
    outline: none;
    border-color: rgba(37, 99, 235, 0.55);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.diag-field-meta {
    margin-top: 0.4rem;
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--text-muted, #6b7280);
    word-break: break-word;
}

/* --- Mode Tabs ---------------------------------------------- */
.diag-mode-tabs {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    padding-top: 1rem;
}

.diag-mode-tab {
    flex: 1;
    padding: 0.72rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 14px;
    background: linear-gradient(180deg, #fff, #f8fafc);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-muted, #6b7280);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.diag-mode-tab:hover {
    border-color: rgba(37, 99, 235, 0.35);
    color: #1d4ed8;
    transform: translateY(-1px);
}

.diag-mode-tab.active {
    border-color: rgba(37, 99, 235, 0.4);
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.09), rgba(37, 99, 235, 0.03));
    color: #1d4ed8;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

/* --- Upload Zone -------------------------------------------- */
.diag-panel {
    background: var(--card-bg, #fff);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    padding: 1.1rem;
    margin-bottom: 1rem;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.diag-upload-zone {
    border: 1.5px dashed rgba(148, 163, 184, 0.45);
    border-radius: 16px;
    padding: 1.8rem 1.4rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.9), rgba(255, 255, 255, 0.96));
}

.diag-upload-zone:hover,
.diag-upload-zone.drag-over {
    border-color: rgba(37, 99, 235, 0.45);
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.9), rgba(255, 255, 255, 0.98));
}

.upload-title { font-weight: 700; color: var(--text, #111827); margin: 0.25rem 0; }
.upload-sub   { font-size: 0.82rem; color: var(--text-muted, #6b7280); margin: 0; }

.diag-csv-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.9rem;
    margin-top: 1rem;
}

.diag-option { min-width: 0; text-align: left; }

.diag-option label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.25rem;
}

.diag-option input,
.diag-option select {
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.7rem;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 12px;
    font-size: 0.85rem;
    background: var(--input-bg, #fff);
    color: var(--text, #1f2937);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
}

/* --- Status messages ---------------------------------------- */
.diag-status {
    margin-top: 0.75rem;
    padding: 0.72rem 0.85rem;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.18);
}
.diag-loading { color: #1d4ed8; font-weight: 600; }
.diag-success { color: #15803d; font-weight: 600; }
.diag-error   { color: #b91c1c; font-weight: 600; }

/* --- Modbus Form -------------------------------------------- */
.diag-form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.diag-form-row .diag-option { flex: 1; min-width: 130px; }

.diag-modbus-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border, #e5e7eb);
}

.btn { padding: 0.5rem 1.25rem; border: none; border-radius: 8px; font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: opacity 0.2s; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--primary, #3b82f6); color: #fff; }
.btn-danger  { background: #ef4444; color: #fff; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-dot.online  { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.status-dot.offline { background: #6b7280; }

/* --- Results Section ---------------------------------------- */
.diag-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.1rem 0.1rem 0.35rem;
}

.diag-results-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text, #111827);
}

.diag-results-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.meta-badge {
    font-size: 0.74rem;
    font-weight: 700;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: var(--text-muted, #6b7280);
}
.meta-badge.source { background: rgba(37, 99, 235, 0.1); color: #1d4ed8; }

/* --- Summary Cards ------------------------------------------ */
.diag-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.diag-lead {
    background:
        radial-gradient(circle at top right, rgba(37, 99, 235, 0.08), transparent 32%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.96));
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 16px;
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.diag-lead-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text, #111827);
    margin-bottom: 0.3rem;
}

.diag-lead-text {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted, #4b5563);
}

.diag-summary-card {
    min-width: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.95));
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-left: 4px solid #6b7280;
    border-radius: 14px;
    padding: 0.85rem 0.9rem;
    text-align: left;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.summary-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.summary-icon {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 0.84rem;
    font-weight: 800;
    flex-shrink: 0;
}

.summary-count { font-size: 1.45rem; font-weight: 800; color: var(--text, #111827); line-height: 1; }
.summary-label { font-size: 0.76rem; color: var(--text-muted, #6b7280); margin-top: 0.55rem; line-height: 1.35; font-weight: 600; }

/* --- Table -------------------------------------------------- */
.diag-table-wrap {
    overflow-x: auto;
    background: var(--card-bg, #fff);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    margin-bottom: 1.25rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.diag-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.diag-table th {
    text-align: left;
    padding: 0.62rem 0.78rem;
    font-size: 0.67rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #6b7280);
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    white-space: nowrap;
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
}

.diag-table td {
    padding: 0.5rem 0.78rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    color: var(--text, #1f2937);
    white-space: nowrap;
}

.diag-table tr:hover td { background: rgba(248, 250, 252, 0.96); }
.diag-table tr.row-healthy td { opacity: 0.7; }

.cell-string { font-weight: 600; font-family: monospace; }

.diag-state-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.48rem;
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
}
.diag-state-pill.good  { background: rgba(34, 197, 94, 0.12);   color: #166534; }
.diag-state-pill.warn  { background: rgba(234, 179, 8, 0.14);   color: #92400e; }
.diag-state-pill.bad   { background: rgba(239, 68, 68, 0.12);   color: #991b1b; }
.diag-state-pill.muted { background: rgba(107, 114, 128, 0.12); color: #374151; }

.diag-subtle {
    font-size: 0.7rem;
    color: var(--text-muted, #6b7280);
    line-height: 1.45;
    margin-top: 0.22rem;
    white-space: normal;
}

/* --- Fault Badge -------------------------------------------- */
.fault-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.18rem 0.55rem;
    border-radius: 6px;
    border: 1px solid;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.fault-badge.large { font-size: 1rem; padding: 0.4rem 1rem; }

/* --- Confidence Bar ----------------------------------------- */
.confidence-bar {
    display: inline-block;
    width: 60px;
    height: 6px;
    background: var(--bg-muted, #e5e7eb);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
    margin-right: 0.4rem;
}
.confidence-fill { display: block; height: 100%; border-radius: 3px; transition: width 0.3s; }
.confidence-text { font-size: 0.72rem; font-weight: 600; }

/* --- Detail Button ------------------------------------------ */
.btn-detail {
    background: #fff;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
    font-size: 0.72rem;
    color: #1d4ed8;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.15s;
}
.btn-detail:hover { background: rgba(37, 99, 235, 0.08); border-color: rgba(37, 99, 235, 0.3); }

/* --- Detail Modal ------------------------------------------- */
.diag-modal-content {
    max-width: 640px;
    width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
    margin: 0;
    border-radius: 18px;
}

.detail-diagnosis { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.confidence-large { font-size: 1.25rem; font-weight: 700; color: var(--text, #1f2937); }

.detail-text {
    color: var(--text-muted, #4b5563);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
}

.detail-callout {
    margin-bottom: 1rem;
    padding: 0.95rem 1rem;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.85), rgba(248, 250, 252, 0.96));
    border: 1px solid rgba(191, 219, 254, 0.75);
}
.detail-callout-title { font-size: 1rem; font-weight: 700; color: var(--text, #1f2937); margin-bottom: 0.4rem; }
.detail-callout-text  { font-size: 0.88rem; line-height: 1.5; color: var(--text-muted, #4b5563); }

.detail-chip-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 1rem; }

.detail-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: var(--text, #374151);
    font-size: 0.76rem;
    font-weight: 600;
}

.detail-features,
.detail-scores { margin-bottom: 1.25rem; }

/* --- Feature Bars ------------------------------------------- */
.feature-row,
.score-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0; }

.feature-label { width: 180px; font-size: 0.8rem; color: var(--text-muted, #6b7280); flex-shrink: 0; }
.score-label   { width: 140px; font-size: 0.82rem; flex-shrink: 0; }

.feature-bar-wrap,
.score-bar-wrap {
    flex: 1;
    height: 8px;
    background: var(--bg-muted, #e5e7eb);
    border-radius: 4px;
    overflow: hidden;
}
.feature-bar,
.score-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }

.feature-val,
.score-val { width: 70px; text-align: right; font-size: 0.78rem; font-weight: 600; color: var(--text, #374151); flex-shrink: 0; }

/* --- Stats -------------------------------------------------- */
.detail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; font-size: 0.85rem; color: var(--text, #374151); }

/* --- I-V Curve Chart (volledig redesign, passend bij rest UI) */
.diag-chart-section {
    background: var(--card-bg, #fff);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    padding: 0;
    margin-top: 1rem;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.diag-chart-section-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.diag-chart-section-hd h4 {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.diag-chart-legend {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-muted, #6b7280);
    font-weight: 600;
}

.diag-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-line-iv {
    display: inline-block;
    width: 18px;
    height: 2.5px;
    border-radius: 2px;
    background: #3b82f6;
}

.legend-line-pv {
    display: inline-block;
    width: 18px;
    height: 2.5px;
    border-radius: 2px;
    background: #f97316;
    opacity: 0.75;
}

.legend-dot-wp {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6b7280;
}

.diag-chart-body {
    padding: 1rem 1.15rem 1.15rem;
}

#diag-ref-chart {
    width: 100% !important;
    min-height: 420px;
    max-height: 480px;
    display: block;
}

#diag-results-section {
    margin-top: 0.35rem;
}

/* --- Responsive --------------------------------------------- */
@media (max-width: 768px) {
    .diag-controls-row   { grid-template-columns: 1fr; }
    .diag-form-row       { flex-direction: column; }
    .diag-csv-options    { grid-template-columns: 1fr; }
    .diag-summary        { grid-template-columns: 1fr 1fr; }
    .detail-stats        { grid-template-columns: 1fr; }
    .feature-label       { width: 130px; font-size: 0.72rem; }
    .score-label         { width: 110px; }

    .diag-table-wrap { overflow-x: visible; border: none; background: transparent; }
    .diag-table,
    .diag-table tbody,
    .diag-table tr,
    .diag-table td      { display: block; width: 100%; }
    .diag-table thead   { display: none; }
    .diag-table tr {
        background: var(--card-bg, #fff);
        border: 1px solid rgba(148, 163, 184, 0.2);
        border-radius: 14px;
        margin-bottom: 0.85rem;
        padding: 0.35rem 0;
        box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
    }
    .diag-table td {
        display: grid;
        grid-template-columns: 108px minmax(0, 1fr);
        gap: 0.65rem;
        align-items: center;
        padding: 0.45rem 0.8rem;
        white-space: normal;
        border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    }
    .diag-table td:last-child { border-bottom: none; }
    .diag-table td::before {
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted, #6b7280);
    }
    .diag-table td:nth-child(1)::before { content: "String"; }
    .diag-table td:nth-child(2)::before { content: "Oordeel"; }
    .diag-table td:nth-child(3)::before { content: "Diagnose"; }
    .diag-table td:nth-child(4)::before { content: "Betrouwbaarheid"; }
    .diag-table td:nth-child(5)::before { content: "Vermogen"; }
    .diag-table td:nth-child(6)::before { content: "Spanning"; }
    .diag-table td:nth-child(7)::before { content: "Stroom"; }
    .diag-table td:nth-child(8)::before { content: "Details"; }
    .cell-string    { word-break: break-word; }
    .confidence-bar { width: 52px; margin-right: 0.3rem; }
    .btn-detail     { width: 100%; justify-content: center; padding: 0.45rem 0.7rem; }

    .diag-chart-section    { border-radius: 12px; }
    .diag-chart-section-hd { padding: 0.6rem 0.85rem; }
    .diag-chart-body       { padding: 0.75rem 0.85rem; }
    #diag-ref-chart        { min-height: 280px; max-height: 320px; }
}

@media (max-width: 520px) {
    .diag-page             { padding-inline: 0.65rem; }
    .diag-summary          { grid-template-columns: 1fr; }
    .diag-results-header   { align-items: flex-start; }
    .diag-results-meta     { width: 100%; }
    .diag-chart-legend     { gap: 0.6rem; }
}
