/* Maliyet Hesabı modül stilleri — sahibi: public/js/costing.js
   Yalnızca .cs- önekli kurallar; ortak sınıflar (.card, .data-table, .btn, .input, .pill, .notice…) styles.css'tedir.
   Düzenleyici yerleşimi kap sorgularıyla (container queries) çalışır:
     .cs-duzen  (sayfa genişliği)  ≥ 1000 px → iki sütun: form + yapışkan "Hesap Özeti"; altında tek sütun + alta yapışan fiyat çubuğu
     .cs-ana    (form sütunu)      ≤ 640 px  → malzeme / operasyon satırları etiketli kartlara dönüşür (telefon)
   Kap sorgusunu desteklemeyen tarayıcıda tek sütun + geniş satır yerleşimi kalır. */

.cs-btn-ikon { display: inline-flex; align-items: center; }
.cs-btn-ikon svg { width: 18px; height: 18px; }
.cs-alt { font-size: 12px; color: var(--muted); }
.cs-zorunlu { color: var(--danger); }
.cs-durum { margin-left: 6px; vertical-align: middle; }
.cs-teklif-link { font-weight: 600; color: var(--blue); white-space: nowrap; }
.cs-teklif-link:hover { text-decoration: underline; }
.cs-btn-sil { color: var(--danger); border-color: #F3B4B4; }
.cs-btn-sil:hover { color: var(--danger); background: var(--tone-red-soft); border-color: var(--danger); }

/* ------------------------------------------------------------------ LİSTE */
.cs-liste-kart { overflow: hidden; }
.cs-liste-ust {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 4px 16px; flex-wrap: wrap;
  padding: 4px 16px 0; border-bottom: 1px solid var(--line);
}
.cs-sekme-yeri { min-width: 0; flex: 1 1 auto; }
.cs-liste-ust .tabbar { border-bottom: 0; margin-bottom: 0; }
.cs-liste-ust .search-box { flex: 0 1 320px; margin: 8px 0 10px; }
.cs-liste-kart .table-wrap { border: 0; border-radius: 0; }
.cs-liste-kart .data-table { min-width: 960px; }
.cs-liste-kart .data-table th, .cs-liste-kart .data-table td { padding-left: 10px; padding-right: 10px; }
.cs-liste-kart .data-table th:first-child, .cs-liste-kart .data-table td:first-child { padding-left: 16px; }
.cs-liste-kart .data-table th:last-child, .cs-liste-kart .data-table td:last-child { padding-right: 16px; }
.cs-liste-alt { padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.cs-no strong { color: var(--heading); font-weight: 700; white-space: nowrap; }
.cs-baslik { min-width: 150px; }
.cs-baslik-ad { font-weight: 600; color: var(--ink); }
.cs-fiyat { color: var(--heading); }

/* ------------------------------------------------------------------ DÜZENLEYİCİ YERLEŞİMİ */
.cs-duzen { container: csduzen / inline-size; }
.cs-izgara { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.cs-ana { container: csana / inline-size; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cs-yan { min-width: 0; }
.cs-uyari { margin: 0; }

@container csduzen (min-width: 1000px) {
  .cs-izgara { grid-template-columns: minmax(0, 1fr) 340px; }
  .cs-duzen .cs-mbar { display: none; }
}
/* Özet kartı ~720 px: yalnızca sığacak yükseklikte yapışkan; kısa ekranda (ör. 1366×768 dizüstü) yapışmaz,
   onun yerine alttaki fiyat çubuğu görünür (Kaydet her zaman erişilebilir kalsın). */
@media (min-height: 820px) {
  @container csduzen (min-width: 1000px) {
    .cs-yan { position: sticky; top: calc(var(--topbar-h, 72px) + 16px); }
  }
}
@media (max-height: 819px) {
  @container csduzen (min-width: 1000px) {
    .cs-duzen .cs-mbar { display: flex; }
  }
}
@container csduzen (max-width: 999px) {
  .cs-yan { width: 100%; max-width: 560px; margin-left: auto; }
}

/* Kart başlığı: renkli ikon karesi + başlık / açıklama + sağda ara toplam */
.cs-kart .card-head.cs-kart-bas { padding: 16px 20px 12px; flex-wrap: wrap; }
.cs-kart-baslik { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cs-ikon {
  width: 36px; height: 36px; border-radius: var(--radius-sm); flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; background: var(--tone-soft); color: var(--tone);
}
.cs-ikon svg { width: 20px; height: 20px; }
.cs-kart-metin { min-width: 0; }
.cs-kart-aciklama { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.cs-kart-meta { font-size: 12.5px; color: var(--muted); }
.cs-ara-toplam {
  font-size: 13px; font-weight: 700; color: var(--heading); white-space: nowrap; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px;
}

/* Hesap bilgileri formu: 6 sütunlu ızgara */
.cs-form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 16px; }
.cs-form .field, .cs-param-izgara .field { margin: 0; min-width: 0; }
.cs-s1 { grid-column: span 1; }
.cs-s2 { grid-column: span 2; }
.cs-s3 { grid-column: span 3; }
.cs-s6 { grid-column: 1 / -1; }

/* Sayı girdileri: sağa yaslı, döndürme okları yok */
.cs-sayi { text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.cs-sayi::-webkit-outer-spin-button, .cs-sayi::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Kilitli hesap: devre dışı alanlar okunur kalsın */
.cs-kilitli .cs-ana .input:disabled { color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
.cs-kilitli .cs-ana .input:disabled::placeholder { color: transparent; -webkit-text-fill-color: transparent; }

/* ------------------------------------------------------------------ SATIRLAR */
.cs-satirlar { display: flex; flex-direction: column; gap: 8px; }
.cs-satir { display: grid; gap: 8px; align-items: center; }
.cs-satir-bas { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 2px; }
.cs-satir-bas .num { text-align: right; padding-right: 4px; }
.cs-satir-mal { grid-template-columns: minmax(0, 1fr) 84px 72px 104px 104px 44px; }
.cs-satir-tutar { grid-template-columns: minmax(0, 1fr) 160px 44px; }
.cs-hucre { min-width: 0; }
.cs-hucre-etiket { display: none; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-tutar { text-align: right; font-weight: 700; color: var(--heading); white-space: nowrap; font-variant-numeric: tabular-nums; padding: 0 4px; }
.cs-sil { color: var(--muted); }
.cs-sil:hover { color: var(--danger); background: var(--tone-red-soft); }
.cs-sil svg { width: 18px; height: 18px; }
.cs-bos { padding: 14px; text-align: center; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); }
.cs-ekle {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 44px; margin-top: 10px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: transparent; color: var(--primary-d);
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.cs-ekle:hover { background: var(--tone-green-soft); border-color: var(--primary); }

/* Operasyon bloğu: iki satır (tür · ad · tezgah / hazırlık · çevrim · ücret · formül + tutar) */
.cs-op { display: block; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.cs-op .cs-hucre-etiket { display: block; }
.cs-op-ust, .cs-op-alt { display: grid; gap: 8px 10px; align-items: end; }
.cs-op-ust {
  grid-template-columns: 28px minmax(120px, 0.9fr) minmax(130px, 1.2fr) minmax(140px, 1fr) 44px;
  grid-template-areas: "sira tur ad tezgah sil";
}
.cs-op-alt {
  margin-top: 10px;
  grid-template-columns: 28px 110px 124px 132px minmax(0, 1fr);
  grid-template-areas: ". hazirlik cevrim ucret sonuc";
}
.cs-op-sira {
  grid-area: sira; width: 28px; height: 28px; margin-bottom: 6px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tone-blue-soft); color: var(--blue); font-size: 13px; font-weight: 700;
}
.cs-o-tur { grid-area: tur; }
.cs-o-ad { grid-area: ad; }
.cs-o-tezgah { grid-area: tezgah; }
.cs-op .cs-sil { grid-area: sil; }
.cs-o-hazirlik { grid-area: hazirlik; }
.cs-o-cevrim { grid-area: cevrim; }
.cs-o-ucret { grid-area: ucret; }
.cs-o-sonuc {
  grid-area: sonuc; min-height: 40px; display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; gap: 2px; text-align: right;
}
.cs-op-formul { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cs-op-tutar { font-size: 15px; color: var(--heading); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Stok kalemi seçici (arama listeli açılır kutu) */
.cs-ac { position: relative; }
.cs-ac.bagli .input { padding-right: 96px; }
.cs-stok-etiket {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); pointer-events: none;
  max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 2px 8px; border-radius: 999px; background: var(--tone-teal-soft); color: var(--tone-teal-ink); font-size: 11.5px; font-weight: 700;
}
.cs-ac-liste {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(480px, 86vw);
  max-height: 300px; overflow-y: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.cs-ac-oge {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center;
  min-height: 40px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
}
.cs-ac-oge:hover, .cs-ac-oge.aktif { background: var(--hover-bg); }
.cs-ac-kod { font-weight: 700; color: var(--heading); white-space: nowrap; }
.cs-ac-ad { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.cs-ac-fiyat { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cs-ac-oge.kaldir { grid-template-columns: minmax(0, 1fr); border-bottom: 1px solid var(--line); border-radius: var(--radius-sm) var(--radius-sm) 0 0; margin-bottom: 4px; }
.cs-ac-oge.kaldir .cs-ac-ad { color: var(--danger); font-weight: 600; }
@media (pointer: coarse) { .cs-ac-oge { min-height: 44px; } }

/* ------------------------------------------------------------------ GENEL GİDER VE KÂR */
.cs-param-izgara { display: grid; grid-template-columns: 170px 170px minmax(0, 1fr); gap: 12px 20px; align-items: start; }
.cs-yuzde { position: relative; }
.cs-yuzde .input { padding-right: 34px; }
.cs-yuzde-isaret { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.cs-param-bilgi {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.cs-param-bilgi strong { color: var(--heading); font-size: 15px; }
.cs-varsayilan { font-size: 13px; }

/* ------------------------------------------------------------------ HESAP ÖZETİ */
.cs-ozet .card-body { padding-top: 4px; }
.cs-dagilim { display: flex; gap: 2px; height: 10px; margin: 2px 0 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.cs-dagilim-dilim { min-width: 3px; background: var(--tone); }
.cs-dagilim-bos { flex: 1 1 auto; }
.cs-oz-liste { display: flex; flex-direction: column; }
.cs-oz-satir { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.cs-oz-nokta { width: 10px; height: 10px; border-radius: 3px; background: var(--tone); }
.cs-oz-nokta.yok { background: transparent; }
.cs-oz-etiket { color: var(--ink); min-width: 0; }
.cs-oz-deger { color: var(--heading); font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cs-oz-ara, .cs-oz-maliyet { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.cs-oz-maliyet .cs-oz-etiket, .cs-oz-maliyet .cs-oz-deger { font-weight: 700; }
.cs-oz-fiyat {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 10px; padding: 14px 16px;
  border-radius: var(--radius); background: var(--tone-green-soft); color: var(--primary-d); font-weight: 700;
}
.cs-oz-fiyat .cs-oz-fiyat-deger { font-size: 22px; color: var(--primary-d); }
.cs-oz-birim { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.cs-oz-kutu { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.cs-oz-kutu > span:first-child { font-size: 12px; color: var(--muted); }
.cs-oz-kutu .cs-oz-deger { text-align: left; font-size: 15px; font-weight: 700; }
.cs-oz-kutu.vurgu { border-color: var(--primary); background: var(--panel); }
.cs-oz-adet { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.cs-ozet .card-foot.cs-oz-eylem { flex-direction: column; align-items: stretch; gap: 8px; }
.cs-oz-durum { margin: 2px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.cs-kirli .cs-oz-durum { color: var(--amber-ink); }

/* Alta yapışan fiyat çubuğu (tek sütunlu yerleşim) */
.cs-mbar {
  position: sticky; bottom: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 16px; padding: 10px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.08);
}
.cs-mbar-bilgi { display: flex; flex-direction: column; min-width: 0; }
.cs-mbar-etiket { font-size: 12px; color: var(--muted); }
.cs-mbar-fiyat { font-size: 18px; color: var(--primary-d); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cs-mbar-birim { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ------------------------------------------------------------------ DAR FORM SÜTUNU (telefon) */
@container csana (max-width: 640px) {
  .cs-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cs-s3, .cs-s6 { grid-column: 1 / -1; }
  .cs-s1, .cs-s2 { grid-column: span 1; }

  .cs-satir-bas.cs-satir-mal { display: none; }
  .cs-satir-mal {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; align-items: end;
    padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  }
  .cs-satir-mal .cs-hucre-etiket { display: block; }
  .cs-satir-mal .cs-h-ad { grid-column: 1 / 3; grid-row: 1; }
  .cs-satir-mal .cs-sil { grid-column: 3; grid-row: 1; }
  .cs-satir-mal .cs-h-miktar { grid-column: 1; }
  .cs-satir-mal .cs-h-birim { grid-column: 2 / 4; }
  .cs-satir-mal .cs-h-bm { grid-column: 1; }
  .cs-satir-mal .cs-h-tutar { grid-column: 2 / 4; }
  .cs-satir-mal .cs-tutar { min-height: 40px; display: flex; align-items: center; justify-content: flex-end; }
  .cs-satir-tutar { grid-template-columns: minmax(0, 1fr) 118px 44px; }

  .cs-op-ust { grid-template-columns: 28px minmax(0, 1fr) 44px; grid-template-areas: "sira tur sil" "ad ad ad" "tezgah tezgah tezgah"; }
  .cs-op-alt { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "hazirlik cevrim" "ucret ucret" "sonuc sonuc"; }
  .cs-o-sonuc { flex-direction: row; flex-wrap: wrap; align-items: baseline; justify-content: space-between; min-height: 0; text-align: left; }

  .cs-ac-liste { width: 100%; max-width: none; }
  .cs-ac-oge { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "kod fiyat" "ad ad"; row-gap: 2px; }
  .cs-ac-kod { grid-area: kod; }
  .cs-ac-fiyat { grid-area: fiyat; }
  .cs-ac-ad { grid-area: ad; white-space: normal; }
  .cs-ac-oge.kaldir { grid-template-columns: minmax(0, 1fr); grid-template-areas: "ad"; }
  .cs-param-izgara { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .cs-param-bilgi { grid-column: 1 / -1; }
}

.cs-mob-etiket { display: none; }

@media (max-width: 640px) {
  .cs-liste-ust { padding: 4px 12px 0; }
  .cs-liste-ust .search-box { flex: 1 1 100%; max-width: none; }
  /* Liste satırları telefonda kart: no + durum / başlık / müşteri + toplam fiyat / adet · birim fiyat · teklif */
  .cs-liste-kart .data-table { min-width: 0; }
  .cs-liste-kart .data-table thead { display: none; }
  .cs-liste-kart .data-table tbody tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
    padding: 12px 14px; border-bottom: 1px solid var(--line);
  }
  .cs-liste-kart .data-table tbody tr:last-child { border-bottom: 0; }
  .cs-liste-kart .data-table tbody td,
  .cs-liste-kart .data-table tbody td:first-child,
  .cs-liste-kart .data-table tbody td:last-child { display: block; padding: 0; border: 0; background: none; }
  .cs-liste-kart .data-table tbody td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .cs-liste-kart .data-table tbody td:nth-child(8) { grid-column: 3; grid-row: 1; justify-self: end; }
  .cs-liste-kart .data-table tbody td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .cs-liste-kart .data-table tbody td:nth-child(3) { grid-column: 1 / 3; grid-row: 3; color: var(--muted); }
  .cs-liste-kart .data-table tbody td:nth-child(7) { grid-column: 3; grid-row: 3; }
  .cs-liste-kart .data-table tbody td:nth-child(4) { grid-column: 1; grid-row: 4; text-align: left; font-size: 13px; color: var(--muted); }
  .cs-liste-kart .data-table tbody td:nth-child(5) { display: none; }
  .cs-liste-kart .data-table tbody td:nth-child(6) { grid-column: 2; grid-row: 4; text-align: left; font-size: 13px; color: var(--muted); }
  .cs-liste-kart .data-table tbody td:nth-child(9) { grid-column: 3; grid-row: 4; justify-self: end; }
  .cs-liste-kart .data-table tbody td.empty-cell { grid-column: 1 / -1; grid-row: auto; text-align: center; }
  .cs-liste-kart .cs-no { display: flex; align-items: baseline; gap: 8px; }
  .cs-liste-kart .cs-baslik { min-width: 0; }
  .cs-mob-etiket { display: inline; }
  .cs-liste-kart .cs-teklif-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; }
  .cs-kart .card-head.cs-kart-bas { padding: 14px 14px 10px; }
  .cs-kart .card-body { padding-left: 14px; padding-right: 14px; }
  .cs-ozet .card-foot { padding-left: 14px; padding-right: 14px; }
  .cs-mbar .btn { min-height: 44px; }
}

/* ------------------------------------------------------------------ YAZDIRMA (Yazdır düğmesi / Ctrl+P) */
.cs-print { display: none; }
@media print {
  .cs-page > :not(.cs-print) { display: none !important; }
  .cs-print { display: block; color: #000; font-size: 10.5pt; line-height: 1.4; }
  .cs-b-ust { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 2px solid #0D884F; }
  .cs-b-firma { display: flex; align-items: flex-start; gap: 12px; font-size: 9pt; }
  .cs-b-firma strong { font-size: 11pt; }
  .cs-b-logo { height: 46px; width: auto; }
  .cs-b-belge { text-align: right; font-size: 9.5pt; }
  .cs-b-tur { font-size: 15pt; font-weight: 800; letter-spacing: 0.04em; color: #0A6E40; }
  .cs-b-no { font-size: 12pt; font-weight: 700; }
  .cs-b-bilgi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 16px; margin-bottom: 8px; padding: 8px 10px; border: 1px solid #CBD5E1; border-radius: 6px; }
  .cs-b-bilgi-oge span { display: block; font-size: 8.5pt; color: #475569; }
  .cs-b-bolum { margin-top: 12px; break-inside: avoid; }
  .cs-b-bolum h3 { margin: 0 0 4px; font-size: 11pt; }
  .cs-b-tablo { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .cs-b-tablo th { text-align: left; padding: 4px 6px; font-weight: 600; border-bottom: 1px solid #94A3B8; background: #F1F5F9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cs-b-tablo td { padding: 4px 6px; border-bottom: 1px solid #E2E8F0; }
  .cs-b-tablo .num { text-align: right; white-space: nowrap; }
  .cs-b-ozet { width: 55%; margin-left: auto; }
  .cs-b-not { margin: 0; white-space: pre-wrap; }
  .cs-b-alt { margin-top: 16px; padding-top: 6px; border-top: 1px solid #CBD5E1; font-size: 8pt; color: #475569; }
}
