/* maliyet.maiinsaat.com.tr — bütçe icmali / metraj ekranlarına özgü stiller.
 * Tokens ve temel bileşenler tokens.css + app.css'ten gelir; burada yalnızca
 * bu uygulamaya has parçalar var.
 */

/* ---------- Giriş sayfası ----------
 * app.css'te body 768px üstünde `grid-template-columns: 260px 1fr` alır (sidebar).
 * Giriş sayfasında sidebar YOK ama sütun duruyor; `body > main { grid-area: main }`
 * kartı sağdaki sütuna hapsedip tam 260px sağa kaydırıyordu. Her iki sütunu
 * kaplatınca ortalama gerçek viewport'a göre yapılır.
 */
main.auth { grid-column: 1 / -1; }

/* ---------- Bütçe başlık şeridi ---------- */
.budget-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.budget-bar__total {
    font-size: var(--text-2xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.budget-bar__label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-subtle);
}
.budget-bar__spacer { flex: 1 1 auto; }
.budget-bar__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- Maliyet kalemi (accordion) ---------- */
.cgroup {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-2);
    overflow: hidden;
}
.cgroup[open] { box-shadow: var(--shadow-sm); }
.cgroup[open] > .cgroup__head { border-bottom: 1px solid var(--border); }

.cgroup__head {
    display: grid;
    /* tutar sütunu 9-haneli TL + simge sığacak kadar geniş olmalı; dar kalırsa
       "12.556.400,00" ile "₺" alt alta düşüp satır yüksekliğini bozuyor */
    grid-template-columns: 2.5rem minmax(0, 1fr) auto 10rem 4rem;
    grid-template-areas: "no ad meta tutar pct" "bar bar bar bar bar";
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    list-style: none;
    user-select: none;
    /* app.css'teki `details summary { color: var(--primary); font-size: xs }`
       kuralını ezer — bunlar açılır etiket değil, tablo başlığı. */
    color: var(--text);
    font-size: var(--text-base);
}
.cgroup__head::-webkit-details-marker { display: none; }
.cgroup__head:hover { background: var(--bg-subtle); }
.cgroup__head:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.cgroup__no {
    grid-area: no;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem; height: 2rem;
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.cgroup__ad {
    grid-area: ad;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cgroup__meta { grid-area: meta; font-size: var(--text-xs); color: var(--text-subtle); white-space: nowrap; }
.cgroup__tutar {
    grid-area: tutar;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}
.cgroup__tutar--bos { color: var(--text-subtle); font-weight: 400; }
.cgroup__pct {
    grid-area: pct;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: var(--text-sm);
    color: var(--text-muted);
}
.cgroup__bar {
    grid-area: bar;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-subtle);
    overflow: hidden;
}
.cgroup__bar > i { display: block; height: 100%; background: var(--primary); border-radius: 2px; }
.cgroup__body { padding: 0; }

/* ---------- Poz tablosu ---------- */
.tbl-poz { width: 100%; border-collapse: collapse; }
.tbl-poz th, .tbl-poz td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.tbl-poz thead th {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-subtle);
    font-weight: 600;
    text-align: left;
    background: var(--bg-subtle);
    white-space: nowrap;
}
.tbl-poz .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl-poz .col-kod { width: 5.5rem; color: var(--text-subtle); font-size: var(--text-sm); }
/* düzenleme modunda buraya <select> giriyor: chevron + "yevmiye" gibi uzun birim sığmalı */
.tbl-poz .col-brm { width: 7rem; color: var(--text-muted); font-size: var(--text-sm); }
.tbl-poz .col-mik { width: 7rem; }
.tbl-poz .col-fiy { width: 8rem; }
.tbl-poz .col-tut { width: 9rem; font-weight: 600; }
.tbl-poz .col-act { width: 6.5rem; text-align: right; white-space: nowrap; }
.tbl-poz tbody tr:hover { background: var(--bg-subtle); }
.tbl-poz tbody tr:last-child td { border-bottom: none; }
.tbl-poz .row-eksik td { background: color-mix(in srgb, var(--warning-soft) 45%, transparent); }
.tbl-poz .row-edit td { background: var(--primary-soft); }

.tbl-poz .cell-input { width: 100%; min-width: 0; padding: var(--space-1) var(--space-2); }
.tbl-poz .cell-input.num { text-align: right; }

.poz-ad { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.poz-ad__not { font-size: var(--text-xs); color: var(--text-subtle); }

.eksik-rozet {
    display: inline-block;
    padding: 1px var(--space-2);
    border-radius: 999px;
    font-size: var(--text-xs);
    background: var(--warning-soft);
    color: var(--warning);
    white-space: nowrap;
}
.stale-rozet {
    display: inline-block;
    padding: 1px var(--space-2);
    border-radius: 999px;
    font-size: var(--text-xs);
    background: var(--info-soft);
    color: var(--info);
    white-space: nowrap;
}

/* Katalog arama sonuç listesi (yeni poz satırı içinde) */
.kat-sonuc { max-height: 15rem; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.kat-sonuc__item {
    display: flex; align-items: baseline; gap: var(--space-2);
    width: 100%; padding: var(--space-2) var(--space-3);
    background: none; border: none; border-bottom: 1px solid var(--border);
    text-align: left; cursor: pointer; color: var(--text);
}
.kat-sonuc__item:last-child { border-bottom: none; }
.kat-sonuc__item:hover, .kat-sonuc__item:focus-visible { background: var(--primary-soft); }
.kat-sonuc__kod { font-size: var(--text-xs); color: var(--text-subtle); min-width: 3.5rem; }
.kat-sonuc__ad { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kat-sonuc__fiyat { font-variant-numeric: tabular-nums; font-size: var(--text-sm); white-space: nowrap; }

/* ---------- Metraj / mahal ---------- */
.metraj-rozet {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px var(--space-2);
    border-radius: 999px;
    font-size: var(--text-xs);
    background: var(--info-soft);
    color: var(--info);
    text-decoration: none;
    white-space: nowrap;
}
.metraj-rozet:hover { text-decoration: underline; }
.metraj-rozet svg { width: 0.75rem; height: 0.75rem; }

.mahal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: var(--space-3);
}
.mahal-kart {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: var(--text);
}
.mahal-kart:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.mahal-kart__ust { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.mahal-kart__ad {
    font-weight: 600; flex: 1 1 auto; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mahal-kart__adet {
    padding: 1px var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.mahal-kart__meta { font-size: var(--text-xs); color: var(--text-subtle); }
.mahal-kart__tutar {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--space-2); flex-wrap: wrap;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.mahal-kart__birim { font-size: var(--text-xs); color: var(--text-subtle); }

.secili-poz {
    padding: var(--space-2) var(--space-3);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    min-height: 2.5rem;
    display: flex;
    align-items: center;
}
.secili-poz--bos { color: var(--text-subtle); font-style: italic; }

.form-not {
    display: flex;
    gap: var(--space-2);
    align-items: flex-start;
    margin: var(--space-3) 0;
    padding: var(--space-3);
    border-radius: var(--radius);
    background: var(--info-soft);
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: 1.5;
}
.form-not svg { flex: 0 0 auto; width: 1rem; height: 1rem; margin-top: 2px; color: var(--info); }
.form-not code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0 3px;
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
}

/* ---------- Dağılım listesi (pano) ---------- */
.dagilim { display: flex; flex-direction: column; gap: var(--space-3); }
.dagilim__row { display: grid; grid-template-columns: minmax(0,1fr) 7.5rem 3.5rem; gap: var(--space-3); align-items: center; }
.dagilim__ad { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dagilim__tutar { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dagilim__pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: var(--text-sm); }
.dagilim__bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--bg-subtle); overflow: hidden; margin-top: -6px; }
.dagilim__bar > i { display: block; height: 100%; background: var(--primary); }

/* Panodaki "henüz doldurulmamış kalemler" listesi — uzun bir metin bloğu,
   .empty-hint'in ortalı hizası burada okunmaz hale geliyordu. */
.bos-kalemler {
    margin: var(--space-4) 0 0;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
    text-align: left;
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--text-subtle);
}
.bos-kalemler strong { color: var(--text-muted); }

/* ---------- Malzeme ihtiyaç listesi (BOM) ---------- */
.tbl-bom td { vertical-align: top; }
.bom-dagilim-satir td { border-bottom: none !important; }

.bom-dagilim {
    margin: 0 0 var(--space-3);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    overflow: hidden;
}
.bom-dagilim__baslik {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--primary-soft);
    font-size: var(--text-sm);
}

.eksik-liste {
    margin: 0;
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--text-sm);
    line-height: 1.5;
}

/* ---------- Bütçe / gerçekleşen ---------- */
.ilerleme {
    height: 10px;
    border-radius: 5px;
    background: var(--bg-subtle);
    overflow: hidden;
    margin-top: var(--space-3);
}
.ilerleme > i { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.ilerleme > i.ilerleme--asim { background: var(--danger); }

.mini-bar {
    display: block;
    height: 4px;
    margin-top: 3px;
    border-radius: 2px;
    background: var(--bg-subtle);
    overflow: hidden;
}
.mini-bar > i { display: block; height: 100%; background: var(--primary); }
.mini-bar > i.ilerleme--asim { background: var(--danger); }

.tbl-sapma .row-asim td { background: color-mix(in srgb, var(--danger-soft) 45%, transparent); }
.tbl-sapma .row-bos td { color: var(--text-subtle); }

/* ---------- Fiyat tarihçesi ---------- */
.fiyat-degisim { font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.fiyat-degisim--artis { color: var(--danger); }
.fiyat-degisim--dusus { color: var(--success); }

/* ---------- Mobil ---------- */
/* ---------- Liste tablolarını mobilde karta indirme ----------
 * `.table--stack` işaretli tablolar dar ekranda yatay kaydırma yerine satır-kart
 * olur. Karşılaştırma tabloları (sapma, ihtiyaç) bilerek dışarıda: orada sütunları
 * yan yana görmek okumanın kendisi.
 * Her <td> `data-label` taşımalı; etiket ::before ile basılır.
 */
@media (max-width: 760px) {
    .table--stack thead { display: none; }
    .table--stack,
    .table--stack tbody,
    .table--stack tr,
    .table--stack td { display: block; width: auto; }

    .table--stack tr {
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--border);
    }
    .table--stack tr:last-child { border-bottom: none; }

    .table--stack td {
        border: none;
        padding: 2px 0;
        display: flex;
        gap: var(--space-2);
        align-items: baseline;
        justify-content: space-between;
        text-align: right;
    }
    .table--stack td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: var(--text-xs);
        color: var(--text-subtle);
        text-align: left;
    }
    /* Etiketsiz hücre (aksiyon butonları) tam genişlik kullansın */
    .table--stack td:not([data-label]) {
        justify-content: flex-start;
        text-align: left;
        padding-top: var(--space-2);
    }
    .table--stack td.is-numeric { text-align: right; }

    /* İlk hücre satırın başlığı gibi davransın */
    .table--stack td[data-label]:first-child {
        font-weight: 600;
        font-size: var(--text-base);
    }
    .table--stack td[data-label]:first-child::before { font-weight: 400; }

    /* Kaydırma kabı artık gereksiz; gölge/çerçeve bırakmasın */
    .table__wrap:has(> .table--stack) { overflow-x: visible; }
}

@media (max-width: 900px) {
    .cgroup__head {
        grid-template-columns: 2.25rem minmax(0, 1fr) auto;
        grid-template-areas: "no ad pct" "no tutar tutar" "bar bar bar";
        row-gap: var(--space-1);
    }
    .cgroup__meta { display: none; }
    .cgroup__tutar { text-align: left; }
    .cgroup__pct { align-self: start; }

    /* Poz tablosu mobilde kartlara iner — yatay scroll yerine okunur stack */
    .tbl-poz thead { display: none; }
    .tbl-poz, .tbl-poz tbody, .tbl-poz tr, .tbl-poz td { display: block; width: auto; }
    .tbl-poz tr {
        padding: var(--space-3) var(--space-4);
        border-bottom: 1px solid var(--border);
    }
    .tbl-poz td { border: none; padding: 2px 0; }
    .tbl-poz td[data-label]::before {
        content: attr(data-label) ": ";
        font-size: var(--text-xs);
        color: var(--text-subtle);
    }
    .tbl-poz .num { text-align: left; }
    .tbl-poz .col-act { text-align: left; padding-top: var(--space-2); }
    .tbl-poz .cell-input { width: 100%; }
}

@media print {
    .app-nav, .mobile-toggle, .budget-bar__actions, .col-act, .toolbar { display: none !important; }
    .cgroup { break-inside: avoid; border-color: #999; }
    .cgroup__body { display: block !important; }
}
