/* ATS Cloud — dashboard tema (ATS Cloud share design'dan uyarlandı) */

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

@media (max-width: 600px) {
    .mud-main-content {
        padding: 8px !important;
        padding-top: 64px !important;
    }
}

.ats-dash {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 96px);
}

.ats-dash .mono {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-feature-settings: 'zero' on, 'cv01' on;
}

.ats-dash .grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    padding: 14px 18px;
    flex: 1;
    min-height: 0;
}

.ats-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    height: 100%;
    box-sizing: border-box;
}

.ats-card-row {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-3);
}

.ats-card-label {
    font-size: 11.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ats-card-value-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
}

/* Değer + birim: küçülmez (flex-shrink:0). Büyük enerji sayıları (on milyonlar) satırı
   taşırıp birimin üstüne biniyordu; taşan tarafın sparkline olması gerekir, rakamın değil. */
.ats-card-value-group {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex: 0 0 auto;
    min-width: 0;
}

/* Esneyen taraf: yer daraldıkça sparkline daralır, gerekirse tamamen kaybolur.
   Eğilim kıvrımı olmadan kart hâlâ okunur; kırpılmış bir tüketim değeri okunmaz. */
.ats-card-spark {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
}

.ats-card-value {
    font-size: 21px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.015em;
}

.ats-card-unit {
    font-size: 11px;
    color: var(--ink-3);
    font-weight: 500;
}

.ats-card-trend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    color: var(--ink-3);
}

.ats-card-trend .pos { color: var(--good); font-weight: 500; }
.ats-card-trend .neg { color: var(--bad); font-weight: 500; }

.ats-pill {
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ats-pill.good { background: var(--good-soft); color: var(--good); }
.ats-pill.warn { background: var(--warn-soft); color: var(--warn); }
.ats-pill.bad  { background: var(--bad-soft); color: var(--bad); }

.ats-chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
}

.ats-chart-title { font-size: 13px; font-weight: 600; }
.ats-chart-sub { font-size: 10.5px; color: var(--ink-3); }

.ats-energy-chart-host {
    flex: 1;
    min-height: 0;
    width: 100%;
}

.ats-energy-chart-host > div,
.ats-energy-chart-host .apexcharts-canvas {
    max-height: 100%;
}

.ats-range-group {
    display: flex;
    gap: 0;
    padding: 2px;
    background: var(--surface-2);
    border-radius: 7px;
    border: 1px solid var(--line);
}

.ats-range-btn {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: transparent;
    color: var(--ink-3);
    font-family: inherit;
}

.ats-range-btn.active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.ats-stat-strip {
    display: flex;
    gap: 20px;
    margin-bottom: 4px;
    align-items: center;
}

.ats-stat-label {
    font-size: 9.5px;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ats-stat-value {
    font-size: 13px;
    font-weight: 600;
}

.ats-bar-info {
    margin-top: 8px;
    padding: 7px 10px;
    background: var(--surface-2);
    border-radius: 6px;
    font-size: 10.5px;
    color: var(--ink-2);
    display: flex;
    align-items: center;
    gap: 7px;
}

.ats-area-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 32px 1fr;
    grid-template-rows: 1fr 18px;
    column-gap: 4px;
}

.ats-y-ticks {
    grid-column: 1; grid-row: 1;
    display: flex; flex-direction: column; justify-content: space-between;
    font-size: 9px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    color: var(--ink-3);
    text-align: right;
    padding-right: 4px;
}

.ats-area-host {
    grid-column: 2; grid-row: 1;
    position: relative;
    min-height: 0;
}

.ats-area-host .gridline {
    position: absolute; left: 0; right: 0;
    border-top: 1px dashed var(--line);
    pointer-events: none;
}

.ats-area-host .gridline.bottom {
    border-top: 1px solid var(--line-strong);
}

.ats-x-labels {
    grid-column: 2; grid-row: 2;
    position: relative;
    font-size: 10px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    color: var(--ink-3);
}

.ats-x-labels span {
    position: absolute;
    transform: translateX(-50%);
    top: 5px;
    white-space: nowrap;
}

.ats-bar-groups { display: flex; gap: 8px; flex: 1; align-items: stretch; min-height: 0; }

.ats-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    min-height: 0;
}

.ats-bar-group .head {
    font-size: 10.5px; color: var(--ink-3); font-weight: 500;
}

/* PowerFactor & Imbalance shared sizing matches a KPI card */
.ats-gauge-svg { width: 44px; height: 44px; }

.ats-bar-line {
    height: 4px; background: var(--surface-2);
    border-radius: 999px; overflow: hidden;
    position: relative; margin-top: 2px;
}

.ats-bar-line > .fill { height: 100%; border-radius: 999px; }
.ats-bar-line > .marker {
    position: absolute; top: -2px; width: 1.5px; height: 8px;
    background: var(--ink-4);
}

.ats-spark { display: block; }

/* ============================
   RESPONSIVE
   ============================ */

.ats-chart-span { grid-column: 1 / span 3; }
.ats-phase-span { grid-column: 4 / span 2; }
.ats-risk-span { grid-column: 1 / -1; }

/*
 * Desktop dashboard height contract:
 * 1–2 KPI rows, 3 reactive-risk row, 4 charts using all remaining height.
 * The explicit fourth row prevents the charts from becoming an oversized
 * implicit grid row whenever the optional risk card is visible.
 */
@media (min-width: 961px) and (min-height: 760px) {
    .ats-dash {
        height: calc(100dvh - 96px);
        min-height: 0;
    }

    .ats-dash .grid {
        grid-template-rows: auto auto auto minmax(280px, 1fr);
        overflow: hidden;
    }

    .ats-risk-span {
        grid-row: 3;
    }

    .ats-chart-span,
    .ats-phase-span {
        grid-row: 4;
        min-height: 0;
        overflow: hidden;
    }
}

/* DeviceDetails — 4 grafik paneli (Enerji/Donut/Reaktif/Güç Faktörü) */
.device-chart-panel {
    width: calc(50% - 8px);
    height: 400px;
}

/* BlazorBootstrap DoughnutChart sabit 390px canvas çiziyor — CSS ile görüntü boyutunu küçült */
.donut-chart-shell canvas {
    max-width: 100%;
    height: auto !important;
}

@media (max-width: 960px) {
    .ats-dash {
        height: auto;
        min-height: calc(100vh - 80px);
    }

    .ats-dash .grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
        overflow: visible;
    }

    .ats-risk-span,
    .ats-chart-span,
    .ats-phase-span {
        grid-column: 1 / -1;
        grid-row: auto;
    }

    .device-chart-panel {
        width: 100%;
        height: 340px;
    }
}

@media (max-width: 600px) {
    .ats-dash .grid {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 8px;
    }

    .ats-stat-strip {
        gap: 12px;
        flex-wrap: wrap;
    }

    .ats-card-value {
        font-size: 18px;
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Anomali ekranları (/anomaliler + cihaz detayındaki panel)

   Renkler MudBlazor paletinden DEĞİL projenin kendi token'larından alınır
   (--bad/--warn/--good/--accent): bunlar ats-tokens.css'te koyu tema için ayrıca
   tanımlı, dolayısıyla grafik ve tablo gösterge paneliyle aynı tonu tutuyor.
   ───────────────────────────────────────────────────────────────────────────── */

/* Yenileme sırasında içerik SÖKÜLMEZ, yalnızca soluklaşır. İçeriği kaldırmak her
   filtre değişiminde sayfayı zıplatıyor, kullanıcının baktığı satır kayboluyordu. */
.ats-busy {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity var(--ats-dur-short, 200ms) var(--ats-ease-exit, ease);
}

.ats-anom-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}

.ats-anom-card {
    position: relative;
    display: flex;
    flex-direction: column;
    /* Tarayıcı <button>'a display:flex verildiğinde align-items:center uyguluyor; belirtilmezse
       kart içeriği ortalanıyor ve sola hizalı okunması gereken satırlar dağılıyor. */
    align-items: stretch;
    gap: 4px;
    padding: 11px 13px 11px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--warn);
    border-radius: var(--r-md);
    cursor: pointer;
    text-align: left;
    width: 100%;
    font: inherit;
    color: inherit;
    transition: border-color var(--ats-dur-micro, 120ms) ease,
                background var(--ats-dur-micro, 120ms) ease,
                transform var(--ats-dur-micro, 120ms) ease;
}

.ats-anom-card.crit { border-left-color: var(--bad); }

.ats-anom-card:hover {
    background: var(--surface-2);
    border-color: var(--line-strong);
    transform: translateY(-1px);
}


.ats-anom-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ats-anom-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ats-anom-card-name {
    font-size: var(--ats-t-sm, 13px);
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sayı rozeti: ciddiyet rengi dolgu değil kenarlıkla verilir — kart zaten sol
   şeritle işaretli, ikinci bir dolu blok görsel gürültü oluyordu. */
.ats-anom-badge {
    flex: none;
    font-family: var(--ats-font-data, monospace);
    font-size: var(--ats-t-micro, 10px);
    font-weight: 600;
    line-height: 1;
    padding: 4px 7px;
    border-radius: var(--r-pill, 999px);
    background: var(--warn-soft);
    color: var(--warn);
    border: 1px solid var(--warn);
}

.ats-anom-badge.crit {
    background: var(--bad-soft);
    color: var(--bad);
    border-color: var(--bad);
}

.ats-anom-card-meta {
    font-size: var(--ats-t-micro, 10px);
    color: var(--ink-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ats-anom-card-meta .mono {
    font-family: var(--ats-font-data, monospace);
}

/* Yön oku: "beklenenden yüksek mi düşük mü" bilgisi genel bakış tablosunda
   hiçbir sütunda yoktu (açıklama sütunu yalnızca cihaz panelinde var). */
.ats-anom-dir {
    font-family: var(--ats-font-data, monospace);
    font-weight: 700;
    margin-right: 3px;
}

.ats-anom-dir.up { color: var(--bad); }
.ats-anom-dir.down { color: var(--accent); }

/* Kritik satırı taramayı kolaylaştıran sol şerit. */
.ats-anom-table tr.crit td:first-child {
    box-shadow: inset 3px 0 0 var(--bad);
}

.ats-anom-table tr.warnrow td:first-child {
    box-shadow: inset 3px 0 0 var(--warn);
}

.ats-anom-table td.num {
    font-family: var(--ats-font-data, monospace);
    text-align: right;
    white-space: nowrap;
}

/* Seçili bulgu — tabloda tıklanan satır grafikte işaretleniyor, bağ görünür olmalı. */
.ats-anom-table tr.picked {
    background: var(--accent-soft) !important;
}

.ats-anom-help {
    font-size: var(--ats-t-label, 12px);
    color: var(--ink-3);
    line-height: 1.5;
}

.ats-anom-help b { color: var(--ink-2); font-weight: 600; }

/*
 * Baseline ısı haritası (BaselineHeatmap.razor).
 *
 * .ats-heatmap-scroll taşır YATAY KAYDIRMAYI — 3×24 hücre 390px'te asla sığmaz, hücreleri
 * ezip okunaksız yapmak yerine ızgara kendi içinde kaydırılır. Sayfa gövdesi ASLA yatay kaymaz:
 * dıştaki .ats-heatmap sabit genişlikte kalır, taşan yalnızca bu iç kapsayıcıdır.
 */
.ats-heatmap-scroll {
    overflow-x: auto;
    padding-bottom: 2px;
}

.ats-heatmap-grid {
    display: grid;
    grid-template-columns: 68px repeat(24, minmax(26px, 1fr));
    grid-auto-rows: 26px;
    gap: 2px;
    min-width: 700px;
}

.ats-heat-corner { }

.ats-heat-hourlabel,
.ats-heat-rowlabel {
    display: flex;
    align-items: center;
    font-family: var(--ats-font-data, monospace);
    font-size: 10px;
    color: var(--ink-3);
}

.ats-heat-hourlabel {
    justify-content: center;
}

.ats-heat-rowlabel {
    justify-content: flex-end;
    padding-right: 6px;
    font-family: var(--ats-font-ui, inherit);
    font-weight: 500;
    color: var(--ink-2);
    white-space: nowrap;
}

/*
 * Hücre rengi = medyan, YALNIZCA medyan (color-mix ile --accent karışım oranı, C# tarafında
 * satır içi style — bkz. BaselineHeatmap.CellStyle). Bilerek TEK değişken: aydınlık/lightness
 * kanalına ikinci bir değişken (örnek sayısı, bayatlık, ...) binerse "düşük değer" ile "düşük
 * güven" ayırt edilemez hale gelir — ikisi de soluk görünür. Diğer iki durum bu yüzden RENKTEN
 * BAĞIMSIZ, birbirinden de görsel olarak ayrık kanallarda taşınır:
 *   .ats-heat-empty   → dolgu deseni (çizgili desen)  — kova hiç dolmadı, veri yok
 *   .ats-heat-lowconf → kenar deseni (iç kesikli çerçeve) — kova doldu ama örnek azınlıkta
 * Bir hücre ikisi olamaz aynı anda (boşsa zaten medyanı yok, "az örnek" hesaba giremez), yine de
 * dolgu vs kenar ayrımı kasıtlı: ikisi çakışsa bile karışmazlardı.
 */
.ats-heat-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 3px;
    cursor: default;
    transition: border-color var(--ats-dur-micro, 120ms) var(--ats-ease-enter, ease);
}

.ats-heat-cell:hover,
.ats-heat-cell:focus-visible {
    border-color: var(--accent);
    z-index: 2;
}

/* "Veri yok" — kova örnek eşiğine hiç ulaşmadı. Legend'daki swatch AYNI sınıfı kullanır. */
.ats-heat-cell.ats-heat-empty,
.ats-heat-legend-swatch.ats-heat-empty {
    background-image: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 4px, var(--line) 4px, var(--line) 5px);
}

/* "Az örnek" — kova doldu ama bu ızgaradaki en düşük örnek sayısına yakın (bkz.
   BaselineHeatmap._lowConfidenceCutoff). İç kesikli çerçeve: rengi/dolguyu değiştirmeden,
   ayrı bir kanaldan "bu sayıya o kadar güvenme" der. Legend'daki swatch AYNI sınıfı kullanır. */
.ats-heat-cell.ats-heat-lowconf::before,
.ats-heat-legend-swatch.ats-heat-lowconf::before {
    content: "";
    position: absolute;
    inset: 2px;
    border: 1.5px dashed var(--ink-3);
    border-radius: 2px;
    pointer-events: none;
}

/* Hücre başına MudTooltip yerine saf CSS ipucu: hover VE klavye odağında aynı davranır,
   72 ayrı MudTooltip örneği oluşturmaktan ucuz. */
.ats-heat-cell:hover::after,
.ats-heat-cell:focus-visible::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 4px;
    padding: 4px 7px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm, 4px);
    font-size: 11px;
    font-family: var(--ats-font-ui, inherit);
    white-space: nowrap;
    box-shadow: 0 4px 12px rgb(0 0 0 / 18%);
    z-index: 5;
    pointer-events: none;
}

.ats-heat-legend {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 11px;
    color: var(--ink-3);
}

.ats-heat-legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ats-heat-legend-label {
    font-family: var(--ats-font-data, monospace);
}

.ats-heat-legend-ramp {
    display: inline-block;
    width: 96px;
    height: 10px;
    border-radius: var(--r-sm, 4px);
    border: 1px solid var(--line);
    background: linear-gradient(to right, var(--surface-2), var(--accent));
}

/* Legend'daki durum örnekleri — ızgaradaki hücrelerle AYNI .ats-heat-empty/.ats-heat-lowconf
   sınıflarını taşır (yukarıda tanımlı), böylece bir okuyucu hücrede gördüğü işareti burada
   birebir bulur. */
.ats-heat-legend-swatch {
    position: relative;
    display: inline-block;
    width: 14px;
    height: 14px;
    flex: none;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--surface-2);
}

.ats-heat-legend-note {
    color: var(--ink-3);
}

.ats-heat-note {
    display: block;
    margin-top: 4px;
    color: var(--ink-3) !important;
    line-height: 1.5;
}

.ats-heat-note b { color: var(--ink-2); font-weight: 600; }

@media (max-width: 600px) {
    .ats-anom-cards {
        grid-template-columns: 1fr;
    }
}
