:root {
    --sidebar-width: 250px;
    --primary: #2c6e49;
    --primary-dark: #1f5235;
    --sidebar-bg: #1e2a38;
    --sidebar-hover: #2c3e50;
    /* iOS Capacitor safe area */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: #f4f6f9; margin: 0; }

/* Sayfa geçişlerinde sidebar/logo "yenilenmiş" görünmesin: bu öğeyi
   sayfalar arasında aynı kabul edip varsayılan çapraz-geçiş animasyonunu
   devre dışı bırakıyoruz (yalnızca destekleyen tarayıcılarda etkili, diğerlerinde no-op). */
@view-transition { navigation: auto; }
.sidebar { view-transition-name: app-sidebar; }
::view-transition-old(app-sidebar),
::view-transition-new(app-sidebar) {
    animation: none;
    mix-blend-mode: normal;
}

/* ===================== Layout ===================== */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #c8d2dd;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    /* Sidebar arka planı status bar arkasını doldurur, içerik aşağı iner */
    padding-top: var(--sat);
    overflow-y: auto;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    font-size: 1.35rem; font-weight: 700; color: #fff;
    padding: 1rem 1rem; display: flex; align-items: center; justify-content: center; gap: .5rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { color: var(--primary); }
.sidebar-brand-logo {
    max-height: 72px; max-width: 100%; width: auto; object-fit: contain;
    background: #fff; padding: 8px 10px; border-radius: 10px;
}
.sidebar-menu { list-style: none; padding: .5rem 0; margin: 0; }
.sidebar-menu a {
    display: flex; align-items: center; gap: .65rem;
    padding: .7rem 1.25rem; color: #c8d2dd; text-decoration: none;
    font-size: .94rem; transition: background .15s, color .15s;
}
.sidebar-menu a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-menu a.active { background: var(--primary); color: #fff; }
.sidebar-menu a i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-subitem a {
    padding-left: 2.2rem;
    font-size: .88rem;
}
.sidebar-subitem a i {
    font-size: .95rem;
    opacity: .9;
}
.menu-label { flex: 1; min-width: 0; }
.menu-alert-badge {
    margin-left: auto;
    min-width: 1.45rem;
    height: 1.45rem;
    padding: 0 .38rem;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 700;
    line-height: 1;
}
.sidebar-heading {
    padding: .9rem 1.25rem .35rem; font-size: .72rem; text-transform: uppercase;
    letter-spacing: .06em; color: #6c7a89; font-weight: 600;
}

.main-content { flex: 1; margin-left: var(--sidebar-width); min-width: 0; }

.topbar {
    background: #fff; height: calc(60px + var(--sat)); display: flex; align-items: center; gap: .75rem;
    padding: var(--sat) 1.25rem 0; box-shadow: 0 1px 3px rgba(0,0,0,.06); position: sticky; top: 0; z-index: 1030;
}
.topbar-title { font-size: 1.15rem; font-weight: 600; margin: 0; color: #2c3e50; }
/* Alt: içerik Android/iOS sistem barının (gesture/nav) altında kalmasın */
.content { padding: 1.5rem; padding-bottom: calc(1.5rem + var(--sab)); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1035;
}

/* ===================== Cards ===================== */
.stat-card {
    border: none; border-radius: .75rem; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.06); height: 100%;
}
.stat-card .stat-icon { font-size: 1.75rem; opacity: .85; flex-shrink: 0; }
/* Büyük para rakamları (100.000+ ₺) dar kartı taşırmasın: genişliğe göre
   küçülen font + tek satır (₺ simgesi alt satıra düşmesin). */
.stat-card .stat-value { font-size: clamp(0.95rem, 4.2vw, 1.5rem); font-weight: 700; white-space: nowrap; line-height: 1.2; }
.stat-card .stat-label { font-size: .82rem; color: #6c757d; }
.stat-card .card-body > .d-flex > div:first-child { min-width: 0; }

.card { border: none; border-radius: .75rem; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.card-header { background: #fff; border-bottom: 1px solid #eef0f3; font-weight: 600; }

/* ===================== Tables ===================== */
.table-responsive { border-radius: .5rem; }
.table > :not(caption) > * > * { padding: .65rem .75rem; }
table thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: #6c757d; }

/* Mobilde (lg altı) "table-mobile-cards" tablolarını kompakt kartlara çevir.
   Her <td>'ye data-label ekle; ilk hücreye .cell-title, işlem hücresine
   .cell-actions ver. Masaüstünde normal tablo görünümü korunur. */
@media (max-width: 991.98px) {
    table.table-mobile-cards thead { display: none; }
    table.table-mobile-cards tbody,
    table.table-mobile-cards tr,
    table.table-mobile-cards td { display: block; width: 100%; }
    table.table-mobile-cards tr {
        border: 1px solid #eef0f3; border-radius: .6rem;
        margin-bottom: .6rem; padding: .35rem .7rem; background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,.04);
    }
    table.table-mobile-cards td {
        display: flex; justify-content: space-between; align-items: center;
        gap: 1rem; padding: .3rem 0; border: none; text-align: right;
    }
    table.table-mobile-cards td::before {
        content: attr(data-label); font-weight: 500; color: #6c757d;
        text-align: left; flex-shrink: 0;
    }
    table.table-mobile-cards td.cell-title {
        font-weight: 600; font-size: 1.02rem; text-align: left;
        display: flex; align-items: center; gap: .35rem;
        border-bottom: 1px solid #f1f3f5; padding-bottom: .4rem; margin-bottom: .25rem;
    }
    table.table-mobile-cards td.cell-title::before { content: none; }
    table.table-mobile-cards td.cell-actions { justify-content: flex-end; gap: .4rem; padding-top: .45rem; }
    table.table-mobile-cards td.cell-actions::before { content: none; }
    table.table-mobile-cards td:empty { display: none; }
    /* Akordiyon: başlık hücresine eklenen rol rozeti + chevron */
    .cell-title-badge { font-size: .72rem !important; flex-shrink: 0; }
    .cell-title-chevron { margin-left: auto; color: #6c757d; font-size: .85rem; flex-shrink: 0; transition: transform .2s ease; }
    .cell-title-chevron.rotated { transform: rotate(180deg); }
    /* Detail td'lerde değer metin node'unu saran span: tek satır + ellipsis */
    .cell-val-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; text-align: right; }
}

/* Mobilde daraltılabilir dashboard kartları (data-collapsible). Masaüstünde
   her zaman açık; mobilde başlığa dokununca aç/kapa. */
.collapse-chevron { transition: transform .2s ease; margin-left: auto; }
@media (min-width: 992px) {
    .card[data-collapsible] .collapse-chevron { display: none; }
}
@media (max-width: 991.98px) {
    .card[data-collapsible] > .card-header { cursor: pointer; user-select: none; display: flex; align-items: center; }
}

/* Buttons touch-friendly */
.btn { border-radius: .5rem; }
.btn-sm { padding: .35rem .6rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.text-primary { color: var(--primary) !important; }
a { color: var(--primary); }

/* ===================== Auth ===================== */
.auth-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e2a38, #2c6e49); padding: 1rem;
}
.auth-card {
    background: #fff; border-radius: 1rem; padding: 2.25rem; width: 100%; max-width: 410px;
    box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.auth-brand { text-align: center; margin-bottom: 1.75rem; }
.auth-brand i { font-size: 2.75rem; color: var(--primary); }
.auth-brand-logo {
    max-height: 96px; max-width: 280px; width: auto; object-fit: contain;
    margin-bottom: .75rem;
}
.auth-brand h1 { font-size: 1.6rem; font-weight: 700; margin: .35rem 0 .15rem; color: #1e2a38; }
.auth-brand p { color: #6c757d; font-size: .9rem; margin: 0; }
.auth-hint { text-align: center; margin-top: 1.25rem; }

/* ===================== Mobile ===================== */
@media (max-width: 767.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-overlay.show { display: block; }
    /* Alt boşluk: safe-area + Android nav bar için ekstra pay (içerik bar altında kalmasın) */
    .content { padding: 1rem; padding-bottom: calc(1rem + var(--sab) + 24px); }

    /* ----- Liste tabloları mobilde kart görünümü ----- */
    .table-responsive { overflow-x: visible; }
    .table-card thead { display: none; }
    .table-card, .table-card > tbody, .table-card > tbody > tr, .table-card > tbody > tr > td { display: block; width: 100%; }
    .table-card > tbody > tr {
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: .7rem;
        margin-bottom: .75rem;
        box-shadow: 0 1px 3px rgba(0,0,0,.06);
        overflow: hidden;
    }
    .table-card > tbody > tr > td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: .6rem .9rem;
        border: 0;
        border-bottom: 1px solid #f1f3f5;
        text-align: right;
        min-height: 46px;
    }
    .table-card > tbody > tr > td:last-child { border-bottom: 0; }
    .table-card > tbody > tr > td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: .8rem;
        text-align: left;
        flex: 0 0 40%;
        white-space: nowrap;
    }
    .table-card > tbody > tr > td[data-label=""]::before { content: none; }
    /* "Kayıt yok" gibi tek hücreli satırlar normal kalsın */
    .table-card > tbody > tr.no-card > td { display: block; text-align: center; color: #6b7280; }
    .table-card > tbody > tr.no-card > td::before { content: none; }
    /* Toplam satırları (tfoot) */
    .table-card tfoot, .table-card tfoot tr, .table-card tfoot td, .table-card tfoot th { display: block; text-align: right; }
}

/* ============ Yazdırma / PDF (raporlar) ============ */
.report-title-print { display: none; }
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin: 0 !important; }
    .content { padding: 0 !important; background: #fff !important; }
    .content .btn, .content button { display: none !important; }
    body, html { background: #fff !important; }
    .report-title-print { display: block !important; font-size: 1.3rem; margin: 0 0 14px; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
    .progress { border: 1px solid #bbb; }
    .stat-card { break-inside: avoid; }
    a[href]::after { content: "" !important; }
}
