/**
 * Bolån – komplett CSS (med rutnät + smart layout)
 * - 1 period (mobil): tvåspaltsvy
 * - 2–3 perioder: fullbredd utan scroll
 * - 4+ perioder: scroll + sticky
 * - Desktop: alltid fullbredd
 */

/* ======== Grundlayout ======== */
.uj-bolan-table {
  width: 100%;
  background: var(--uj-white);
  border-radius: var(--uj-radius-lg);
  border: 1px solid var(--uj-border-light);
  overflow: hidden;
  margin-top: 20px;
  box-shadow: var(--uj-shadow-sm);
}

.uj-bolan-table-scroll {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  scroll-behavior: smooth; /* smidig scroll */
}

/* ======== Tabell-struktur ======== */
.uj-bolan-table table {
  border-collapse: collapse;
  width: 100%;
  border: 1px solid var(--uj-border-light);
}

.uj-bolan-table th,
.uj-bolan-table td {
  text-align: center;
  border: 1px solid var(--uj-border-light);
  padding: 14px 12px;
  font-size: 14px;
  background: var(--uj-white);
}

.uj-bolan-table thead th {
  background: linear-gradient(to bottom, #fafbfc, #f7f8f9);
  border-bottom: 2px solid var(--uj-border-light);
  font-weight: 600;
  color: var(--uj-text-muted);
  text-transform: uppercase;
  font-size: 12px;
}

.uj-bolan-table tbody tr:hover td {
  background: var(--uj-background);
  border-color: var(--uj-border-light);
}

/* Kolumner: Bolag */
.uj-bolan-table th.uj-bank-col,
.uj-bolan-table td.uj-bank-col {
  min-width: 110px;
  width: 110px;
  text-transform: none;
  font-size: 13px;
  border-right: 1px solid var(--uj-border-light);
}

/* Logotyp och fallback */
.uj-bank-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.uj-bank-logo {
  height: 28px;
  width: auto;
  max-width: 80px;
  object-fit: contain;
}

.uj-bank-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--uj-primary-pale);
  color: var(--uj-primary-medium);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}

/* ======== Räntenivå-färger ======== */
.uj-rate-low { color: var(--uj-success-color); }
.uj-rate-high { color: var(--uj-error-color); }
.uj-rate-normal { color: var(--uj-text-primary); }
.uj-rate-empty { color: var(--uj-text-muted); font-weight: 400; }

/* ======== Desktop ======== */
@media (min-width: 769px) {
  .uj-bolan-table-scroll {
    overflow-x: visible;
  }
  .uj-bolan-table table {
    width: 100%;
    min-width: 0;
  }
}

/* ======== 1–3 kolumner: fullbredd utan scroll ======== */
.uj-bolan-table.uj-no-scroll .uj-bolan-table-scroll {
  overflow-x: visible;
}
.uj-bolan-table.uj-no-scroll table {
  width: 100%;
  table-layout: fixed;
}

/* ======== 4+ kolumner: scroll + sticky kolumn ======== */
.uj-bolan-table.uj-scroll .uj-bolan-table-scroll {
  overflow-x: auto;
}
@media (max-width: 768px) {
  .uj-bolan-table.uj-scroll table {
    width: max-content;
    min-width: 700px;
  }

  .uj-bolan-table.uj-scroll th.uj-bank-col,
  .uj-bolan-table.uj-scroll td.uj-bank-col {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--uj-white);
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    background-clip: padding-box;
    border-right: 1px solid var(--uj-border-light);
  }

  .uj-bolan-table.uj-scroll thead th.uj-bank-col {
    background: linear-gradient(to bottom, #fafbfc, #f7f8f9);
    z-index: 3;
  }
}

/* ======== Single period i mobil: tvåspaltslista ======== */
@media (max-width: 768px) {
  .uj-bolan-table.uj-single-mobile .uj-bolan-table-scroll {
    overflow-x: visible;
  }

  .uj-bolan-table.uj-single-mobile table {
    width: 100%;
    table-layout: fixed;
  }

  .uj-bolan-table.uj-single-mobile th.uj-bank-col,
  .uj-bolan-table.uj-single-mobile td.uj-bank-col {
    position: static;
    width: 46%;
    box-shadow: none;
    background: var(--uj-white);
    text-align: left;
    border-right: none;
  }

  .uj-bolan-table.uj-single-mobile th.uj-rate-col,
  .uj-bolan-table.uj-single-mobile td.uj-rate-col {
    width: 54%;
    text-align: right;
  }

  .uj-bolan-table.uj-single-mobile th {
    padding: 10px;
    font-size: 12px;
  }

  .uj-bolan-table.uj-single-mobile td {
    padding: 14px 10px;
    font-size: 15px;
  }

  .uj-bolan-table.uj-single-mobile .uj-rate-cell span {
    font-weight: 700;
  }

  /* Enkel rutnätsram i single-läge */
  .uj-bolan-table.uj-single-mobile th,
  .uj-bolan-table.uj-single-mobile td {
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--uj-border-light);
    border-bottom: 1px solid var(--uj-border-light);
  }
}

/* ======== Alltid rutnät ======== */
.uj-bolan-table th + th,
.uj-bolan-table td + td {
  border-left: 1px solid var(--uj-border-light);
}

/* =========================================================
   KOLUMNSORTERING – dubbelpilar + grön aktiv pil
   ========================================================= */
.uj-bolan-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
}
.uj-bolan-table th[data-sort] .uj-sort-icon {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  line-height: 1;
  font-size: 10px;
  opacity: 0.9;
  color: #9aa0a6;
}

/* visa alltid båda pilarna */
.uj-bolan-table th[data-sort] .uj-sort-icon::before { content: "▲"; }
.uj-bolan-table th[data-sort] .uj-sort-icon::after  { content: "▼"; }

/* hover */
.uj-bolan-table th[data-sort]:hover { background-color: rgba(0,0,0,0.03); }
.uj-bolan-table th[data-sort]:hover .uj-sort-icon { color: #6b7280; }

/* aktiv riktning = grön, andra nedtonad */
.uj-bolan-table th.uj-sort-asc .uj-sort-icon::before { color: var(--uj-success-color); }
.uj-bolan-table th.uj-sort-asc .uj-sort-icon::after  { color: #c9cdd2; }
.uj-bolan-table th.uj-sort-desc .uj-sort-icon::after { color: var(--uj-success-color); }
.uj-bolan-table th.uj-sort-desc .uj-sort-icon::before{ color: #c9cdd2; }

/* lite extra padding så pilar får plats */
.uj-bolan-table thead th[data-sort] { padding-right: 10px; }

/* =========================================================
   FILTER-RAD (Räntetyp + Förhandlingsfritt)
   ========================================================= */
.uj-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
  align-items: flex-start;
}
@media (max-width: 768px) {
  .uj-filter-row { gap: 12px 16px; }
}

/* Hjälparklass att gömma ev. gamla sortboxar */
.uj-hide { display: none !important; }

.uj-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.uj-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--uj-success-color, #16a249);
  cursor: pointer;
}
