:root {
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --accent: #f59e0b;
    --content-bg: #eef2f7;
    --sidebar-w: 258px;
    --card-radius: 16px;
    font-size: 14px;
}

body {
    background: var(--content-bg);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #1e293b;
    margin: 0;
}

/* ===== Butonlar (indigo tema) ===== */
.btn-primary {
    --bs-btn-bg: #4f46e5; --bs-btn-border-color: #4f46e5;
    --bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
    --bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
}
.btn { border-radius: 9px; font-weight: 500; }
.btn-sm { border-radius: 7px; }

/* ===== Uygulama iskeleti ===== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    position: fixed; top: 0; bottom: 0; left: 0;
    background: linear-gradient(185deg, #1e293b 0%, #0f172a 100%);
    color: #cbd5e1;
    display: flex; flex-direction: column;
    z-index: 1045;
    transition: transform .25s ease;
    box-shadow: 2px 0 18px rgba(0,0,0,.18);
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 20px 16px;
    color: #fff; font-weight: 700; font-size: 1.15rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo {
    width: 38px; height: 38px; border-radius: 11px; object-fit: cover;
    box-shadow: 0 4px 12px rgba(79,70,229,.4);
}
.sidebar-nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.sidebar-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: #64748b; padding: 14px 12px 6px; font-weight: 600; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 13px; margin-bottom: 3px;
    color: #cbd5e1; text-decoration: none; border-radius: 10px;
    font-weight: 500; font-size: .92rem; transition: all .15s;
}
.sidebar-nav a .ico { font-size: 1.05rem; width: 22px; text-align: center; }
.sidebar-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav a.active {
    background: linear-gradient(90deg, rgba(79,70,229,.9), rgba(99,102,241,.75));
    color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.35);
}
.sidebar-user {
    border-top: 1px solid rgba(255,255,255,.08);
    padding: 14px; display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.sidebar-user .uname { color: #fff; font-size: .85rem; font-weight: 600;
    max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .urole { color: #94a3b8; font-size: .72rem; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column;
    transition: margin-left .25s ease; }

.topbar {
    height: 62px; background: #fff; position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; gap: 12px; padding: 0 16px;
    box-shadow: 0 1px 3px rgba(15,23,42,.08);
}
.topbar .page-title { font-weight: 600; font-size: 1.1rem; margin: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hamburger { display: grid; place-items: center; width: 40px; height: 40px;
    border: none; background: #f1f5f9; border-radius: 9px; font-size: 1.25rem;
    cursor: pointer; color: #334155; flex-shrink: 0; }
.hamburger:hover { background: #e2e8f0; }

.content { padding: 22px; flex: 1; }

/* Sidebar backdrop (mobil) */
.sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1040;
}

/* Masaüstünde menüyü aç/kapat (collapsed) */
@media (min-width: 992px) {
    .layout.collapsed .sidebar { transform: translateX(-100%); }
    .layout.collapsed .main { margin-left: 0; }
}

/* Mobil: menü üstte kayan panel */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .sidebar-backdrop.show { display: block; }
}

/* Sabit (sticky) filtre alanı — sadece masaüstünde (mobilde normal kayar) */
.filter-sticky { margin-bottom: 6px; }
@media (min-width: 992px) {
    .filter-sticky {
        position: sticky; top: 62px; z-index: 1015;
        background: var(--content-bg); padding: 8px 0;
    }
}

/* ===== Kartlar ===== */
.card {
    border: none; border-radius: var(--card-radius);
    box-shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}
.card-header {
    background: #fff; border-bottom: 1px solid #eef2f7;
    font-weight: 600; border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

/* ===== İstatistik kutucukları ===== */
.stat-tile {
    background: #fff; border-radius: var(--card-radius); padding: 18px 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: 0 1px 3px rgba(15,23,42,.08);
}
.stat-tile .stat-ico {
    width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
    font-size: 1.5rem; color: #fff; flex-shrink: 0;
}
.stat-tile .stat-val { font-size: 1.5rem; font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; min-width: 0; }
.stat-tile > div:last-child { min-width: 0; }
.stat-tile .stat-lbl { color: #64748b; font-size: .82rem; }
.ico-indigo { background: linear-gradient(135deg,#4f46e5,#6366f1); }
.ico-amber  { background: linear-gradient(135deg,#f59e0b,#fb923c); }
.ico-green  { background: linear-gradient(135deg,#10b981,#34d399); }
.ico-rose   { background: linear-gradient(135deg,#f43f5e,#fb7185); }

/* ===== Tablolar ===== */
.table > thead.table-dark th { background: #1e293b; border-color: #1e293b; font-weight: 600; }
.table { --bs-table-hover-bg: #f8fafc; }

/* Canlı izleme satır renkleri (Bootstrap hücre arka planını ezmek için td'ye) */
#grid tbody tr.satir-normal > td { background-color: #fff3a0 !important; }
#grid tbody tr.satir-iade   > td { background-color: #ff9a9a !important; }
#grid tbody tr:hover > td { filter: brightness(.96); }
#grid th, #grid td { white-space: nowrap; }

/* Mobil + tablet (iPad landscape dahil): tabloyu kart yapısına çevir (yatay kaydırma olmasın) */
@media (max-width: 1199.98px) {
    #grid, #grid tbody, #grid tfoot { display: block; width: 100%; }
    #grid thead { display: none; }
    #grid tr { display: block; margin-bottom: 12px; border-radius: 12px; padding: 8px 12px;
        border: 1px solid #e5e7eb; box-shadow: 0 1px 3px rgba(15,23,42,.10); }
    #grid tbody tr.satir-normal { background: #fff7cc; }
    #grid tbody tr.satir-iade   { background: #ffdcdc; }
    #grid tbody tr.satir-normal > td,
    #grid tbody tr.satir-iade   > td { background: transparent !important; }
    #grid td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
        border: none; padding: 3px 0; text-align: right; white-space: normal; }
    #grid td::before { content: attr(data-label); font-weight: 600; color: #475569; text-align: left; }
    #grid td[data-label="Sıra"] { font-weight: 700; font-size: 1rem;
        border-bottom: 1px solid rgba(0,0,0,.10); margin-bottom: 5px; padding-bottom: 6px; }
    #grid tfoot tr { background: #e9ecef; }
    #grid .tf-label, #grid .tf-empty { display: none; }
    .table-responsive { overflow-x: visible; }
}

/* Geniş grafikler mobilde okunur kalsın diye yatay kaydırılabilir kap */
@media (max-width: 767.98px) {
    .chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .chart-scroll > svg { min-width: 640px; }
}

/* Genel amaçlı responsive tablo: mobil+tablette kart yapısına döner (.rtable) */
@media (max-width: 991.98px) {
    table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
    table.rtable thead { display: none; }
    table.rtable tr { border: 1px solid #e5e7eb; border-radius: 12px; margin-bottom: 10px;
        padding: 8px 12px; background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.08); }
    table.rtable td { display: flex; justify-content: space-between; align-items: center; gap: 12px;
        border: none; padding: 5px 0; text-align: right; white-space: normal; }
    table.rtable td::before { content: attr(data-label); font-weight: 600; color: #475569; text-align: left; }
    table.rtable td.rtable-title { font-weight: 700; font-size: 1rem;
        border-bottom: 1px solid rgba(0,0,0,.08); margin-bottom: 4px; padding-bottom: 6px; }
    table.rtable td.rtable-actions { justify-content: flex-end; padding-top: 8px; }
    table.rtable td.rtable-title::before, table.rtable td.rtable-actions::before { content: ''; }
}

/* ===== CSS bar chart ===== */
.barchart { display: flex; flex-direction: column; gap: 9px; }
.barrow { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 10px; }
.barlabel { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bartrack { background: #eef2f7; border-radius: 6px; height: 20px; overflow: hidden; }
.barfill { height: 100%; background: linear-gradient(90deg,#4f46e5,#818cf8); border-radius: 6px; }
.barval { font-size: .8rem; font-weight: 600; white-space: nowrap; }

/* iOS: font 16px'ten küçük input'a odaklanınca sayfayı zoom'lar ve geri almaz.
   Mobil/tablette form alanlarını 16px yapıp bu otomatik zoom'u engelliyoruz.
   Ayrıca dokunma alanlarını (buton/input) büyütüp tıklamayı kolaylaştırıyoruz (~44px). */
@media (max-width: 991.98px) {
    input, select, textarea,
    .form-control, .form-control-sm, .form-select, .form-select-sm {
        font-size: 16px !important;
    }
    .form-control, .form-control-sm, .form-select, .form-select-sm { min-height: 44px; }
    .btn, .btn-sm { min-height: 44px; padding-top: 9px; padding-bottom: 9px; font-size: 15px; }
    .btn-group .btn { min-height: 44px; }
    .hamburger { width: 44px; height: 44px; font-size: 1.4rem; }
    .form-check-input { width: 1.3em; height: 1.3em; margin-top: .12em; }
    .form-switch .form-check-input { width: 2.5em; }
    .form-check-label { padding-left: 4px; line-height: 1.5em; }
    /* Kart içi işlem butonları rahat dursun */
    table.rtable td.rtable-actions .btn { margin-bottom: 4px; }
}

/* Yukarı çık butonu */
.to-top {
    position: fixed; bottom: 18px; right: 16px; z-index: 1500;
    width: 46px; height: 46px; border-radius: 50%; border: none;
    background: #4f46e5; color: #fff; font-size: 1.35rem; line-height: 1;
    box-shadow: 0 4px 14px rgba(79,70,229,.45); cursor: pointer;
    opacity: 0; visibility: hidden; transform: translateY(8px);
    transition: opacity .2s, visibility .2s, transform .2s;
}
.to-top.show { opacity: .92; visibility: visible; transform: none; }
.to-top:hover { opacity: 1; }
@media (min-width: 992px) { .to-top { bottom: 24px; right: 24px; } }

/* Global yükleme göstergesi (spinner) */
.app-loader {
    position: fixed; inset: 0; z-index: 3000;
    background: rgba(238, 242, 247, 0.6);
    display: none; align-items: center; justify-content: center;
}
.app-loader.show { display: flex; }
.app-loader .spinner {
    width: 54px; height: 54px; border-radius: 50%;
    border: 5px solid #cbd5e1; border-top-color: #4f46e5;
    animation: appspin .8s linear infinite;
}
.app-loader .sp-text { position: absolute; margin-top: 90px; color: #475569; font-size: .85rem; font-weight: 500; }
@keyframes appspin { to { transform: rotate(360deg); } }

/* Grafik açıklama (legend) */
.chart-legend { display: flex; flex-direction: column; gap: 5px; }
.chart-legend .leg { display: flex; align-items: center; gap: 8px; font-size: .82rem; }
.chart-legend .dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.chart-legend .lg-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend .lg-val { font-weight: 600; white-space: nowrap; }

/* ===== Giriş / auth ekranı ===== */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: linear-gradient(135deg,#4f46e5 0%, #7c3aed 50%, #0f172a 100%);
}
.auth-card {
    width: 100%; max-width: 410px; background: #fff; border-radius: 20px;
    box-shadow: 0 20px 55px rgba(15,23,42,.35); padding: 34px 30px; border-top: 5px solid var(--accent);
}
.auth-logo {
    width: 68px; height: 68px; border-radius: 18px; margin: 0 auto 14px; display: block; object-fit: cover;
    box-shadow: 0 8px 20px rgba(79,70,229,.45);
}
.pw-toggle { cursor: pointer; }
.form-control, .form-select { border-radius: 9px; }

@media (max-width: 576px) {
    :root { font-size: 13px; }
    .barrow { grid-template-columns: 92px 1fr auto; }
    .content { padding: 16px; }
}
