/*
 * Excel tarzı kompakt tablo görünümü (v3 — ayarlanabilir yoğunluk).
 * Sadece body'sinde .excel-page sınıfı olan sayfalarda etkindir
 * (ListShipments ve ListCustoms sayfaları $extraBodyAttributes ile ekler).
 *
 * Yoğunluk: body[data-excel-density] = normal | compact (varsayılan) | mini | nano
 * Sağ alttaki "Görünüm" seçicisi ile değiştirilir, localStorage'da saklanır
 * (public/js/app-helpers.js).
 */

body.excel-page {
    --xl-font: 12px;
    --xl-line: 1.3;
    --xl-pad-y: 0.2rem;
    --xl-pad-x: 0.5rem;
    --xl-head-font: 10.5px;
    --xl-head-pad-y: 0.3rem;
    --xl-badge-font: 10px;
    --xl-select-font: 12px;
    --xl-action-font: 11px;
}

body.excel-page[data-excel-density='normal'] {
    --xl-font: 13px;
    --xl-line: 1.45;
    --xl-pad-y: 0.5rem;
    --xl-pad-x: 0.65rem;
    --xl-head-font: 11.5px;
    --xl-head-pad-y: 0.55rem;
    --xl-badge-font: 11px;
    --xl-select-font: 13px;
    --xl-action-font: 12px;
}

body.excel-page[data-excel-density='mini'] {
    --xl-font: 10.5px;
    --xl-line: 1.15;
    --xl-pad-y: 0.05rem;
    --xl-pad-x: 0.35rem;
    --xl-head-font: 9.5px;
    --xl-head-pad-y: 0.15rem;
    --xl-badge-font: 9px;
    --xl-select-font: 10.5px;
    --xl-action-font: 10px;
}

body.excel-page[data-excel-density='nano'] {
    --xl-font: 9.5px;
    --xl-line: 1.05;
    --xl-pad-y: 0.02rem;
    --xl-pad-x: 0.25rem;
    --xl-head-font: 8.5px;
    --xl-head-pad-y: 0.08rem;
    --xl-badge-font: 8px;
    --xl-select-font: 9.5px;
    --xl-action-font: 9px;
}

/* ---------- Kapsayıcı: tablo içi scroll + ince scrollbar ---------- */
body.excel-page .fi-ta-content {
    max-height: calc(100vh - 13rem);
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

body.excel-page .fi-ta-content::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

body.excel-page .fi-ta-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 5px;
}

body.excel-page .fi-ta-content::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- Tablo temeli ---------- */
body.excel-page .fi-ta-table {
    font-size: var(--xl-font);
    line-height: var(--xl-line);
    border-collapse: separate;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
}

body.excel-page .fi-ta-table .text-sm {
    font-size: var(--xl-font) !important;
}

/* ---------- Başlık: gri, büyük harf, yapışkan ---------- */
body.excel-page .fi-ta-table thead {
    position: sticky;
    top: 0;
    z-index: 20;
}

body.excel-page .fi-ta-table thead th {
    background-color: #f1f5f9;
    padding-top: var(--xl-head-pad-y) !important;
    padding-bottom: var(--xl-head-pad-y) !important;
    border-bottom: 2px solid #cbd5e1;
    border-inline-end: 1px solid #e2e8f0;
    white-space: nowrap;
}

body.excel-page .fi-ta-header-cell-label {
    font-size: var(--xl-head-font) !important;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #334155;
}

body.excel-page .fi-ta-header-cell-sort-icon {
    height: 0.8rem;
    width: 0.8rem;
}

/* ---------- Satırlar: opak zemin (dondurulmuş kolonlar için şart) + zebra ---------- */
body.excel-page .fi-ta-row {
    background-color: #ffffff;
}

body.excel-page
    .fi-ta-row:nth-child(even):not(.bg-planned):not(.bg-completed):not(.bg-paid):not(.bg-all-paid) {
    background-color: #f8fafc;
}

/* ---------- Hücreler: ince padding + çizgiler; zemin satırdan miras ---------- */
body.excel-page .fi-ta-table td {
    border-inline-end: 1px solid #eef2f6;
    border-bottom: 1px solid #eef2f6;
    background-color: inherit;
}

body.excel-page .fi-ta-cell > div {
    padding: 0 !important;
}

body.excel-page .fi-ta-cell .fi-ta-text,
body.excel-page .fi-ta-cell .fi-ta-select,
body.excel-page .fi-ta-cell .fi-ta-icon,
body.excel-page .fi-ta-cell .fi-ta-color,
body.excel-page .fi-ta-cell .fi-ta-image,
body.excel-page .fi-ta-cell .fi-ta-toggle {
    padding: var(--xl-pad-y) var(--xl-pad-x) !important;
}

body.excel-page .fi-ta-cell .fi-ta-select {
    min-width: 8rem;
}

body.excel-page .fi-ta-cell .fi-ta-text {
    gap: 0;
}

/* ---------- Dondurulmuş kolonlar: seçim + ilk veri kolonu solda, aksiyonlar sağda ---------- */
body.excel-page .fi-ta-table th:first-child,
body.excel-page .fi-ta-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 6;
    width: 45px;
    min-width: 45px;
    max-width: 45px;
}

body.excel-page .fi-ta-table th:nth-child(2),
body.excel-page .fi-ta-table td:nth-child(2) {
    position: sticky;
    left: 45px;
    z-index: 6;
    border-inline-end: 2px solid #cbd5e1;
}

body.excel-page .fi-ta-table th:last-child,
body.excel-page .fi-ta-table td:last-child {
    position: sticky;
    right: 0;
    z-index: 6;
    border-inline-start: 2px solid #cbd5e1;
    border-inline-end: none;
}

body.excel-page .fi-ta-table thead th:first-child,
body.excel-page .fi-ta-table thead th:nth-child(2),
body.excel-page .fi-ta-table thead th:last-child {
    z-index: 21;
}

/* Modal içindeki tablolar (ör. Finansal İşlemler) sayfanın sıkışık yoğunluğunu
   kullanmasın; seçilen yoğunluktan bağımsız olarak rahat okunur kalsın. */
body.excel-page .fi-modal {
    --xl-font: 13px;
    --xl-line: 1.45;
    --xl-pad-y: 0.45rem;
    --xl-pad-x: 0.65rem;
    --xl-head-font: 11.5px;
    --xl-head-pad-y: 0.55rem;
    --xl-badge-font: 11px;
    --xl-select-font: 13px;
    --xl-action-font: 12px;
}

/* Modal içindeki tablolarda kolon dondurma devre dışı.
   Ana listelerde ilk kolon 45px'lik seçim kutusudur; modal tablolarında
   (ör. Finansal İşlemler) seçim kolonu yok, bu yüzden ilk veri kolonu
   (tarih) 45px'e kırpılıyordu. */
body.excel-page .fi-modal .fi-ta-table th:first-child,
body.excel-page .fi-modal .fi-ta-table td:first-child,
body.excel-page .fi-modal .fi-ta-table th:nth-child(2),
body.excel-page .fi-modal .fi-ta-table td:nth-child(2),
body.excel-page .fi-modal .fi-ta-table th:last-child,
body.excel-page .fi-modal .fi-ta-table td:last-child {
    position: static;
    width: auto;
    min-width: 0;
    max-width: none;
}

body.excel-page .fi-modal .fi-ta-content {
    max-height: none;
}

/* ---------- Hover: excel seçim hissi (opak; dondurulmuş kolonlarda da düzgün) ---------- */
body.excel-page .fi-ta-row:hover td {
    background-color: #e8f1fd;
}

/* ---------- Checkbox hücresi ---------- */
body.excel-page .fi-ta-cell > input.fi-ta-record-checkbox,
body.excel-page th > input.fi-ta-page-checkbox {
    margin: 0.25rem 0.5rem;
}

/* ---------- Rozetler kompakt ---------- */
body.excel-page .fi-ta-table .fi-badge {
    font-size: var(--xl-badge-font);
    padding: 0 0.375rem;
    line-height: 1.4;
    white-space: nowrap;
}

/* ---------- Satır içi durum select'i kompakt ---------- */
body.excel-page .fi-ta-table select {
    font-size: var(--xl-select-font);
    padding-top: 0.125rem;
    padding-bottom: 0.125rem;
}

body.excel-page .fi-ta-cell .fi-input-wrp {
    min-height: 0;
}

/* ---------- Satır aksiyonları kompakt ---------- */
body.excel-page .fi-ta-table .fi-ta-actions {
    gap: 0.25rem;
    padding: 0.125rem 0.375rem !important;
    flex-wrap: nowrap;
}

body.excel-page .fi-ta-table .fi-ta-actions .fi-link,
body.excel-page .fi-ta-table .fi-ta-actions .fi-btn {
    font-size: var(--xl-action-font);
    white-space: nowrap;
}

/* İkon-buton aksiyonlar: yoğunluğa göre küçülen ikonlar + dar tıklama alanı */
body.excel-page .fi-ta-table .fi-ta-actions .fi-icon-btn {
    padding: 0.125rem;
}

body.excel-page .fi-ta-table .fi-ta-actions .fi-icon-btn .fi-icon-btn-icon {
    height: 1.1rem;
    width: 1.1rem;
}

body.excel-page[data-excel-density='mini'] .fi-ta-table .fi-ta-actions .fi-icon-btn .fi-icon-btn-icon,
body.excel-page[data-excel-density='nano'] .fi-ta-table .fi-ta-actions .fi-icon-btn .fi-icon-btn-icon {
    height: 0.95rem;
    width: 0.95rem;
}

body.excel-page[data-excel-density='mini'] .fi-ta-table .fi-ta-actions .fi-icon-btn,
body.excel-page[data-excel-density='nano'] .fi-ta-table .fi-ta-actions .fi-icon-btn {
    padding: 0.05rem;
}

/* ---------- Ödeme durumu rozetleri (inline HTML) ---------- */
body.excel-page .fi-ta-table td span[style*='border-radius: 9999px'] {
    font-size: 10px !important;
    padding: 0 6px !important;
    white-space: nowrap;
}

/* ---------- Araç çubuğu ve sayfalama kompakt ---------- */
body.excel-page .fi-ta-header-toolbar {
    padding-top: 0.375rem !important;
    padding-bottom: 0.375rem !important;
}

body.excel-page .fi-ta-pagination {
    padding-top: 0.375rem !important;
    padding-bottom: 0.375rem !important;
}

/* =========================================================
   Karanlık tema
   ========================================================= */
:is(.dark) body.excel-page .fi-ta-content {
    scrollbar-color: #3f3f46 transparent;
}

:is(.dark) body.excel-page .fi-ta-content::-webkit-scrollbar-thumb {
    background: #3f3f46;
}

:is(.dark) body.excel-page .fi-ta-table thead th {
    background-color: rgb(24, 24, 27);
    border-bottom-color: rgba(255, 255, 255, 0.2);
    border-inline-end-color: rgba(255, 255, 255, 0.08);
}

:is(.dark) body.excel-page .fi-ta-header-cell-label {
    color: #cbd5e1;
}

:is(.dark) body.excel-page .fi-ta-row {
    background-color: rgb(24, 24, 27);
}

:is(.dark)
    body.excel-page
    .fi-ta-row:nth-child(even):not(.bg-planned):not(.bg-completed):not(.bg-paid):not(.bg-all-paid) {
    background-color: rgb(30, 30, 34);
}

:is(.dark) body.excel-page .fi-ta-table td {
    border-inline-end-color: rgba(255, 255, 255, 0.06);
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

:is(.dark) body.excel-page .fi-ta-table th:nth-child(2),
:is(.dark) body.excel-page .fi-ta-table td:nth-child(2) {
    border-inline-end-color: rgba(255, 255, 255, 0.2);
}

:is(.dark) body.excel-page .fi-ta-table th:last-child,
:is(.dark) body.excel-page .fi-ta-table td:last-child {
    border-inline-start-color: rgba(255, 255, 255, 0.2);
}

:is(.dark) body.excel-page .fi-ta-row:hover td {
    background-color: rgb(30, 41, 59);
}

/* =========================================================
   Görünüm yoğunluğu seçici (sağ alt sabit pill)
   ========================================================= */
#excel-density-control {
    position: fixed;
    bottom: 1rem;
    right: 1.25rem;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 6px;
    border-radius: 9999px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
    font-size: 11px;
    color: #64748b;
    user-select: none;
}

#excel-density-control .xl-label {
    padding: 0 6px 0 4px;
    font-weight: 600;
}

#excel-density-control button {
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

#excel-density-control button:hover {
    background: #f1f5f9;
}

#excel-density-control button.active {
    background: #f59e0b;
    color: #ffffff;
}

:is(.dark) #excel-density-control {
    background: rgb(24, 24, 27);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    color: #94a3b8;
}

:is(.dark) #excel-density-control button {
    color: #94a3b8;
}

:is(.dark) #excel-density-control button:hover {
    background: rgba(255, 255, 255, 0.06);
}

:is(.dark) #excel-density-control button.active {
    background: #f59e0b;
    color: #1c1917;
}
