/* =============================================================================
   Weilo Finans — Mobil katman (tüm sayfalarda en son yüklenir)
   Masaüstü görünümü değiştirmez; yalnızca ≤ 768px ekranlarda devreye girer.
   Tasarım dili korunur: düz renkler, köşe yarıçapı yok, gradyan yok.
   ============================================================================= */

@media (max-width: 768px) {
    html, body { overflow-x: clip; max-width: 100%; }
    body { -webkit-text-size-adjust: 100%; }
    img, canvas, svg, video { max-width: 100%; }
    canvas { height: auto !important; }

    /* iOS'ta odaklanınca sayfanın yakınlaşmasını önler (16px altı yazı tipleri zoom yaptırır) */
    input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; max-width: 100%; }
    input[type=date], input[type=month] { min-width: 0; }

    /* Dokunma hedefleri */
    button, .btn, a.btn, [role=button] { min-height: 34px; }

    /* Genel kapsayıcılar */
    .container, .page, .wrap, .wrapper, .main, .content, main { padding-left: 10px !important; padding-right: 10px !important; max-width: 100% !important; }

    /* ---------- Dokunma hedefleri ---------- */
    .m-kapat { min-width: 44px !important; min-height: 44px !important; font-size: 22px !important; line-height: 1 !important;
               display: inline-flex !important; align-items: center; justify-content: center; opacity: 1 !important; color: #2c2c2c !important; }
    button { min-width: 34px; }
    input[type=checkbox], input[type=radio] { width: 22px !important; height: 22px !important; }
    .pill, .pill-group > *, .chip, .filter-btn, .quick-dates button, .tab, .tabs > *, [class*="filtre"] > button {
        min-height: 36px !important; display: inline-flex !important; align-items: center; justify-content: center;
    }
    .breadcrumb a, .breadcrumbs a, .page-nav a { display: inline-block; padding: 10px 4px; }
    select { min-height: 36px; }

    /* ---------- Üst menü ---------- */
    #wf-nav { padding: 0 10px !important; }
    #wf-nav .wf-brand { margin-right: 8px !important; }
    #wf-nav .wf-role, #wf-nav .wf-sep { display: none !important; }
    #wf-nav .wf-uname { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #wf-nav .wf-user { gap: 4px !important; }
    #wf-nav .wf-act { padding: 8px 6px !important; font-size: 12px !important; }
    #wf-nav .wf-link { font-size: 14px !important; height: 44px !important; }
    #wf-ham { min-height: 40px; min-width: 40px; }

    /* ---------- Tablolar ---------- */
    .m-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .m-scroll > table { min-width: 100%; }

    /* Kart görünümü: her satır bir kart, her hücre "etiket — değer" */
    table.m-cards, table.m-cards > tbody, table.m-cards > tfoot,
    table.m-cards > tbody > tr, table.m-cards > tfoot > tr { display: block !important; width: 100% !important; }
    table.m-cards { border: 0 !important; background: transparent !important; min-width: 0 !important; table-layout: auto !important; }
    table.m-cards > thead { display: none !important; }
    table.m-cards > tbody > tr, table.m-cards > tfoot > tr {
        background: #fff; border: 1px solid #d4d4c8 !important; margin: 0 0 8px; padding: 6px 12px;
        height: auto !important;
    }
    table.m-cards > tfoot > tr { background: #f5f5f0; border-top: 2px solid #1a5c3a !important; }
    table.m-cards > tbody > tr > td, table.m-cards > tfoot > tr > td,
    table.m-cards > tbody > tr > th, table.m-cards > tfoot > tr > th {
        display: flex !important; justify-content: space-between; align-items: flex-start; gap: 12px;
        width: auto !important; min-width: 0 !important; max-width: none !important;
        padding: 5px 0 !important; border: 0 !important; border-bottom: 1px solid #f0f0ea !important;
        text-align: right !important; white-space: normal !important; word-break: break-word;
        position: static !important; height: auto !important;
    }
    table.m-cards > tbody > tr > td:last-child, table.m-cards > tfoot > tr > td:last-child { border-bottom: 0 !important; }
    table.m-cards > tbody > tr > td::before, table.m-cards > tfoot > tr > td::before,
    table.m-cards > tbody > tr > th::before {
        content: attr(data-label);
        flex: 0 0 38%; text-align: left; font-size: 11px; font-weight: 600; color: #8a8a80;
        text-transform: uppercase; letter-spacing: .03em; line-height: 1.6;
    }
    table.m-cards > tbody > tr > td[data-label=""]::before,
    table.m-cards > tbody > tr > td.m-nolabel::before { display: none; }
    table.m-cards > tbody > tr > td[data-label=""], table.m-cards > tbody > tr > td.m-nolabel { justify-content: flex-start; text-align: left !important; }
    /* İlk hücre kartın başlığı */
    table.m-cards > tbody > tr > td.m-title { font-weight: 600; font-size: 14px; color: #2c2c2c; }
    /* Tam satır (colspan) hücreler: boş durum, grup başlığı */
    table.m-cards > tbody > tr > td[colspan] { display: block !important; text-align: center !important; }
    table.m-cards > tbody > tr > td[colspan]::before { display: none; }
    table.m-cards > tbody > tr:has(> td[colspan]:only-child) { padding: 4px 12px; }
    /* Karmaşık hücreler: etiket üstte, içerik tam genişlikte altta */
    table.m-cards > tbody > tr > td.m-stack { flex-direction: column !important; align-items: stretch !important; text-align: left !important; gap: 4px; }
    table.m-cards > tbody > tr > td.m-stack::before { flex-basis: auto; }
    table.m-cards > tbody > tr > td.m-stack > * { max-width: 100%; }
    table.m-cards > tbody > tr > td.m-stack table { width: 100% !important; }
    table.m-cards > tbody > tr > td.m-stack textarea { width: 100% !important; }
    table.m-cards > tbody > tr > td.m-stack > div { display: flex; flex-wrap: wrap; gap: 4px; }
    /* Sıra no sütunu kartta gereksiz; onay kutusu satırı sıkı */
    table.m-cards > tbody > tr > td.m-hide { display: none !important; }
    table.m-cards > tbody > tr > td.m-check { border-bottom: 0 !important; padding: 2px 0 0 !important; justify-content: flex-end !important; }
    table.m-cards > tbody > tr > td.m-check::before { display: none; }
    table.m-cards > tbody > tr > td.m-check input { width: 20px; height: 20px; }
    /* Kart içindeki boş hücreleri gizle */
    table.m-cards > tbody > tr > td.m-empty { display: none !important; }

    /* ---------- Modallar / tam ekran katmanlar ---------- */
    .m-sheet { padding: 0 !important; align-items: stretch !important; justify-content: stretch !important; }
    .m-sheet > .m-sheet-box {
        width: 100% !important; max-width: 100% !important; min-width: 0 !important;
        max-height: 100% !important; margin: 0 !important; border-radius: 0 !important;
        overflow-y: auto !important; -webkit-overflow-scrolling: touch;
        left: auto !important; top: auto !important; transform: none !important;
    }
    .m-sheet > .m-sheet-box.m-sheet-full { height: 100% !important; }
    /* Kendi kendine ortalanmış sabit kutular (overlay'siz) */
    .m-fixed-box { left: 0 !important; right: 0 !important; width: 100% !important; max-width: 100% !important; transform: none !important; top: auto !important; bottom: 0 !important; max-height: 90dvh !important; overflow-y: auto !important; }

    /* Tek kaydırma alanı: tam ekran modalda iç içe kaydırılan kutular (max-height + overflow) kaldırılır,
       tüm modal tek parça kayar. Alt boşluk iPhone Safari alt çubuğunun altında içerik kalmasın diye. */
    .m-sheet > .m-sheet-box { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px) !important; }
    .m-sheet-box .modal-body, .m-sheet-box .modal-content, .m-sheet-box .m-ic-kaydirma {
        max-height: none !important; height: auto !important; flex: none !important; overflow-y: visible !important;
    }
    .m-sheet-box div[style*="max-height"]:not([style*="position:absolute"]):not([style*="position: absolute"]):not(.m-scroll) {
        max-height: none !important; height: auto !important; overflow-y: visible !important;
    }
    /* JS ile 2 sütuna indirilen ızgaralar */
    .m-izgara2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .m-izgara2 > * { min-width: 0 !important; }
    .m-izgara2 select, .m-izgara2 input { min-width: 0 !important; width: 100% !important; }
    table.m-cards > tbody > tr > td.m-sayi { flex-wrap: wrap !important; column-gap: 10px; }
    table.m-cards > tbody > tr > td.m-sayi > * { white-space: nowrap !important; }
    /* Kart satırındaki işlem düğmeleri yan yana */
    table.m-cards > tbody > tr > td.m-butonlar { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)) !important; gap: 6px !important; align-items: stretch !important; }
    table.m-cards > tbody > tr > td.m-butonlar::before { grid-column: 1 / -1; }
    table.m-cards > tbody > tr > td.m-butonlar > * { width: 100% !important; margin: 0 !important; min-height: 40px; justify-content: center; text-align: center; }

    /* Hariç Tutulan Cariler panosu: sütunlar yan yana kaydırılan tam genişlik kartlar */
    .kanban-toolbar { flex-wrap: wrap !important; gap: 10px !important; padding: 12px !important; }
    .kanban-toolbar > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
    .kanban-toolbar > div:last-child > button { flex: 1 1 auto; min-height: 40px; }
    .kanban-toolbar-left { flex-wrap: wrap !important; gap: 8px 16px !important; width: 100%; }
    .kanban-toolbar-stats { flex-wrap: wrap !important; gap: 6px 14px !important; }
    .kanban-container { display: flex !important; overflow-x: auto !important; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
                        gap: 10px !important; padding: 12px !important; min-height: 0 !important; }
    .kanban-col { flex: 0 0 84% !important; max-width: 84% !important; scroll-snap-align: start; }
    .kanban-card-title { white-space: normal !important; }

    /* Modal içi dokunma hedefleri */
    .m-sheet-box button, .m-fixed-box button { min-height: 40px; }
    .m-sheet-box input:not([type=checkbox]):not([type=radio]), .m-sheet-box select,
    .m-fixed-box input:not([type=checkbox]):not([type=radio]), .m-fixed-box select { min-height: 38px; }
    .m-sheet-box a[href^="tel:"], .m-sheet-box a[href^="mailto:"], .m-sheet-box a[onclick] { display: inline-block; padding: 8px 0; }
    /* Ortalanmış küçük pencereler (hariç tut vb.) telefonda tam genişlik */
    div[style*="position: fixed"][style*="align-items: center"] > div[style*="max-width: 450px"],
    div[style*="position: fixed"][style*="align-items: center"] > div[style*="max-width: 500px"] { width: calc(100% - 20px) !important; max-height: 92dvh; overflow-y: auto; }

    html.m-modal-acik #wf-nav { display: none !important; }
    html.m-modal-acik body { overflow: hidden !important; padding-top: 0 !important; }
    /* Bilinen modal sınıfları (JS gelmeden önce de doğru görünsün) */
    .modal-overlay, .modal-back { padding: 0 !important; }
    .modal-box, .modal-overlay > .modal, .modal-back > .modal, .mikro-modal-large, .modal-large {
        width: 100% !important; max-width: 100% !important; margin: 0 !important; max-height: 100dvh !important;
    }
    .modal-header, .modal-head { position: sticky; top: 0; z-index: 2; background: inherit; }
    .modal-close { min-width: 40px; min-height: 40px; }
    .modal-body { padding: 12px !important; }

    /* ---------- Sık kullanılan ızgaralar ---------- */
    .detail-grid, .info-card-grid, .bakiye-grid, .grid-2, .grid-3, .grid-25 { grid-template-columns: 1fr !important; }

    /* Araç çubukları ve filtreler sarılsın */
    .toolbar, .filters, .filter-bar, .actions, .btn-group, .tabs, .timeline-filters, .quick-dates, .header-actions {
        flex-wrap: wrap !important; gap: 6px !important;
    }
    .tabs { overflow-x: auto; flex-wrap: nowrap !important; -webkit-overflow-scrolling: touch; }
    .tabs > * { flex: 0 0 auto; }

    /* ---------- Dashboard (index.php) ---------- */
    .header { padding: 12px !important; gap: 10px !important; }
    .header h1 { font-size: 1.1rem !important; }
    .date-inputs { display: grid !important; grid-template-columns: 1fr 1fr; gap: 6px 8px !important; width: 100%; }
    .date-inputs > * { min-width: 0; width: 100% !important; margin: 0 !important; }
    .date-inputs label { font-size: 12px; }
    .quick-dates { overflow-x: auto; flex-wrap: nowrap !important; justify-content: flex-start !important; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
    .quick-dates button { flex: 0 0 auto; }
    .summary-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .summary-card { padding: 12px !important; }
    .summary-card .value, .summary-card .summary-value { font-size: 1.4rem !important; }
    .summary-card .icon, .summary-card .summary-icon { margin-bottom: 4px !important; }
    .module-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .module-card { padding: 10px !important; min-height: 0 !important; }
    .timeline-header { flex-direction: column; align-items: stretch !important; gap: 8px; }

    /* ---------- Belge düzenli sayfalar (ekstre, cari/müşteri raporu, paylaşılan ekstre) ---------- */
    .summary-boxes { grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; }
    .summary-box { padding: 10px !important; }
    .summary-box .value { font-size: 1rem !important; word-break: break-word; }
    .cari-info { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
    .company-info h1 { font-size: 1.2rem !important; }
    .document-info { text-align: left !important; }
    .header:has(.company-info), .header:has(.document-info) { flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; }
    .footer { flex-direction: column !important; gap: 8px !important; }
    .filter-bar { flex-wrap: wrap !important; gap: 6px !important; }
    .filter-bar input[type=date] { flex: 1 1 140px; }
    /* faturalar.php istatistik kutuları, stok-durumu filtre grupları */
    .stats { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .stat-box { padding: 12px !important; min-width: 0; }
    .stat-box .value { font-size: 1.1rem !important; word-break: break-word; }
    .pill-group { flex-wrap: wrap !important; max-width: 100%; }
    .pill-group > * { flex: 1 1 auto; }
    .grid-4, .ozet-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .grid-4 > *, .ozet-grid > *, .grid-3 > * { min-width: 0; }
    .header-top { flex-wrap: wrap !important; gap: 8px !important; }
    .header-top > * { min-width: 0; }
    .pdf-btn { top: auto !important; bottom: 14px !important; right: 14px !important; z-index: 900; }
}

@media (max-width: 380px) {
    .module-grid { grid-template-columns: 1fr 1fr !important; }
    table.m-cards > tbody > tr > td::before { flex-basis: 42%; }
}

/* =============================================================================
   MASAÜSTÜ MODALLAR — içerik modalları ekranın %94'üne kadar genişler,
   yükseklik ekrana göre ayarlanır. Küçük onay pencereleri (≤620px) olduğu gibi kalır.
   ============================================================================= */
@media (min-width: 769px) {
    /* index.php ana modalı */
    .modal-overlay { padding-top: 60px !important; padding-bottom: 20px !important; }   /* üstte 42px sabit menü var */
    .modal-overlay > .modal:not([style*="max-width:4"]):not([style*="max-width:5"]):not([style*="max-width:6"]) {
        width: min(1320px, 94vw) !important; max-width: 94vw !important;
    }
    .modal-overlay > .modal.modal-large, .mikro-modal-large { width: min(1600px, 96vw) !important; max-width: 96vw !important; }
    .modal-overlay > .modal > .modal-body { max-height: calc(100vh - 190px) !important; }
    /* cariler / paylasim / stok-durumu / banka eşleştirme içerik modalları */
    .modal-overlay > .modal-box:not([style*="max-width:4"]):not([style*="max-width:5"]):not([style*="max-width:6"]),
    .modal-back > .modal:not([style*="max-width:4"]):not([style*="max-width:5"]):not([style*="max-width:6"]) {
        width: min(1400px, 94vw) !important; max-width: 94vw !important; max-height: calc(100vh - 80px) !important;
    }
    .modal-back { padding-top: 60px !important; }
    /* index'te JS ile açılan satır içi stilli büyük pencereler */
    div[style*="position:fixed"] > div[style*="max-width:900px"], div[style*="position: fixed"] > div[style*="max-width: 900px"],
    div[style*="position:fixed"] > div[style*="max-width:800px"], div[style*="position: fixed"] > div[style*="max-width: 800px"],
    div[style*="position:fixed"] > div[style*="max-width:1000px"], div[style*="position: fixed"] > div[style*="max-width: 1000px"] {
        max-width: min(1320px, 94vw) !important; width: 94vw !important;
    }

    /* Modal içi tablolar: rakamlar ve başlıklar alt satıra kaymaz, ürün/cari adı okunur genişlikte */
    .modal table th, .modal-box table th { white-space: nowrap; }
    .modal table td[style*="text-align:right"], .modal table td[style*="text-align: right"],
    .modal-box table td[style*="text-align:right"], .modal-box table td[style*="text-align: right"],
    .modal table td.num, .modal-box table td.num, .modal table td > code, .modal-box table td > code { white-space: nowrap; }
    .modal table td:has(> strong), .modal-box table td:has(> strong) { min-width: 200px; }
}

/* Yazdırma/PDF: kart dönüşümü yazdırmaya yansımasın */
/* Tüm ekranlar: geniş tablolar modal içinde kesilmesin, yatay kaysın */
.modal-overlay .modal-body, .modal-back .modal-body, #raporPrintArea { overflow-x: auto !important; }
/* Bölge eşik ayarı: 3 kutu yan yana sığsın */
.esik-item input { width: 100% !important; min-width: 0 !important; box-sizing: border-box !important; }
/* Masaüstü: bir modal/katman açıkken üst menü katmanın altında kalır (başlık menünün altında kesilmesin) */
html.m-katman-acik #wf-nav { z-index: 90 !important; }

/* Tüm ekranlar: theme.css adında "card" geçen her öğeye çerçeve veriyordu; pano kartının iç satırları çerçevesiz */
.kanban-cards, .kanban-card-header, .kanban-card-title, .kanban-card-code, .kanban-card-amount, .kanban-card-remove {
    border: 0 !important; background: transparent !important;
}
.kanban-cards { padding: 8px !important; display: flex; flex-direction: column; gap: 8px; }
.kanban-card { padding: 10px !important; }
.kanban-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.kanban-card-title { font-weight: 600; }

/* Tüm ekranlar: Hariç Tutulanlar "Liste" düğmesi açık gri zemin üstünde açık gri yazıydı */
.kanban-btn-secondary { color: #2c2c2c !important; }

@media print {
    table.m-cards > thead { display: table-header-group !important; }
}
