/* ============================================================
   Island Chests tab styles — scoped to #island_chests
   ============================================================ */

#island_chests {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: calc(100vh - 30px);
  height: calc(100dvh - 30px);
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 980px) {
  #island_chests {
    height: auto;
    min-height: calc(100vh - 80px);
    min-height: calc(100dvh - 80px);
    overflow: visible;
  }
}

/* ---- Layout: sidebar + main ---- */
.ic-layout {
  display: flex;
  gap: 0;
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* ---- Island sidebar ---- */
.ic-sidebar {
  width: 220px;
  height: 100%;
  min-height: 0;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background: var(--bg-surface-1);
  border-right: 1px solid var(--border-accent);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  gap: 2px;
}

.ic-sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px 8px;
}

.ic-sidebar-action-btn {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  color: var(--text-panel);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.ic-sidebar-action-btn:hover {
  background: var(--bg-panel);
}

.ic-island-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
}

.ic-island-btn .ic-island-banner {
  filter: saturate(0.28) brightness(0.72);
  opacity: 0.82;
  transition: filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.ic-island-btn:hover {
  background: var(--bg-panel);
}

.ic-island-btn:hover .ic-island-banner {
  filter: saturate(0.55) brightness(0.9);
  opacity: 0.95;
}

.ic-island-btn.active {
  background: var(--bg-tab-active);
  border-left-color: var(--border-accent);
  outline: none;
}

.ic-island-btn.active .ic-island-banner {
  filter: saturate(1.1) brightness(1);
  opacity: 1;
  transform: scale(1.01);
}

.ic-island-banner {
  width: 100%;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  display: block;
}

/* ---- Main content ---- */
.ic-main {
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.ic-multi-island-scroll {
  overflow-x: scroll;
  overflow-y: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  padding-bottom: 12px;
}

.ic-scroll-top-wrap {
  width: 100%;
  margin-bottom: 8px;
}

.ic-scroll-top {
  overflow-x: scroll;
  overflow-y: hidden;
  height: 14px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  touch-action: pan-x;
  border: 1px solid var(--border-accent);
  border-radius: 999px;
  background: var(--bg-surface-1);
}

.ic-scroll-top-inner {
  height: 1px;
  min-width: 100%;
}

.ic-scroll-top::-webkit-scrollbar {
  height: 12px;
}

.ic-scroll-top::-webkit-scrollbar-thumb {
  background: var(--text-title);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.ic-scroll-top::-webkit-scrollbar-track {
  background: var(--bg-surface-1);
  border-radius: 999px;
}

.ic-multi-island-scroll::-webkit-scrollbar {
  height: 12px;
}

.ic-multi-island-scroll::-webkit-scrollbar-thumb {
  background: var(--text-title);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.ic-multi-island-scroll::-webkit-scrollbar-track {
  background: var(--bg-surface-1);
  border-radius: 999px;
}

.ic-multi-island-grid {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  min-width: min-content;
}

.ic-island-panel {
  width: min(980px, calc(100vw - 320px));
  min-width: 620px;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ic-island-panel-banner-wrap {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border-accent);
}

.ic-island-panel-banner {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 64px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* ---- Header (controls + stats) ---- */
#ic-header {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ic-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
}

.ic-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.ic-char-search {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  color: var(--text-panel);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  min-width: 150px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ic-char-search:focus {
  border-color: var(--text-title);
  box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.1);
}

.ic-char-search::placeholder {
  color: var(--text-panel-secondary, rgba(255, 193, 7, 0.5));
}

.ic-filter-toggle-btn {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  color: var(--text-panel);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.ic-filter-toggle-btn.active {
  background: var(--bg-tab-active);
  color: var(--text-tab-active);
  border-color: var(--text-title);
}

.ic-filter-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ic-filter-btn {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  color: var(--text-panel);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.ic-filter-btn.active {
  background: var(--bg-tab-active);
  color: var(--text-tab-active);
}

.ic-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ic-action-btn {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-accent);
  color: var(--text-panel);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.ic-action-btn:hover {
  background: var(--bg-panel);
}

.ic-action-btn-danger {
  border-color: #c0392b;
  color: #e74c3c;
}

.ic-action-btn-danger:hover {
  background: rgba(231, 76, 60, 0.12);
}

/* ---- Stats row ---- */
.ic-stats-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.ic-stat-block {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ic-stat-label {
  font-size: 0.82rem;
  color: var(--text-muted, var(--text-panel));
  opacity: 0.75;
}

.ic-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-title);
}

.ic-progress-block {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ic-progress-bar-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ic-progress-bar {
  width: 120px;
  height: 10px;
  background: var(--bg-panel);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-accent);
}

.ic-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #27ae60, #2ecc71);
  transition: width 0.3s ease;
}

.ic-eb-bar .ic-progress-fill {
  background: linear-gradient(90deg, #2980b9, #3498db);
}

.ic-gl-bar .ic-progress-fill {
  background: linear-gradient(90deg, #8e44ad, #9b59b6);
}

.ic-progress-label {
  font-size: 0.78rem;
  color: var(--text-panel);
  white-space: nowrap;
}

/* ---- Section headings ---- */
.ic-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ic-section-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-title);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-accent);
}

/* ---- Stamina all-islands view ---- */
.ic-stamina-all-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ic-stamina-global-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.ic-stamina-global-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ic-stamina-global-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-panel);
}

.ic-stamina-banner-sm {
  width: 56px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border-accent);
  flex-shrink: 0;
}

/* Island header row inside the wide stamina table */
.ic-stamina-island-row th {
  background: var(--bg-surface-1);
}

.ic-stamina-island-th {
  text-align: center;
  padding: 6px 4px;
  white-space: nowrap;
}

.ic-stamina-island-th .ic-stamina-banner-sm {
  display: block;
  margin: 0 auto 4px;
  width: 100%;
  max-width: 72px;
  height: 40px;
}

.ic-stamina-island-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-title);
  white-space: normal;
  max-width: 76px;
  margin: 0 auto;
  text-align: center;
  line-height: 1.2;
}

/* Visual divider between island groups */
.ic-group-start {
  border-left: 2px solid var(--border-accent) !important;
}

/* ---- Global chests row ---- */
.ic-global-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---- Chest cards (global / standalone) ---- */
.ic-chest-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface-1);
  border: 2px solid var(--border-accent);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  min-width: 80px;
  user-select: none;
}

.ic-chest-card:hover {
  border-color: var(--text-title);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.ic-chest-card.ic-chest-card-checked {
  border-color: #27ae60;
  background: #27ae60;
}

.ic-chest-top {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.ic-chest-sprite {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.ic-chest-checked {
  filter: brightness(0.7) sepia(1) hue-rotate(85deg) saturate(2);
}

.ic-loot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}

.ic-loot-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 58px;
  flex-shrink: 0;
}

.ic-loot-item img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.ic-loot-qty {
  position: absolute;
  bottom: 0;
  right: 0;
  background: rgba(0,0,0,0.72);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0 2px;
  border-radius: 2px;
  line-height: 1.3;
  pointer-events: none;
}

.ic-chest-berries {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-title);
  text-align: center;
}

/* ---- Per-character table ---- */
.ic-char-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  padding-bottom: 14px;
}

.ic-char-table {
  border-collapse: collapse;
  min-width: 300px;
  table-layout: auto;
}

.ic-char-table th,
.ic-char-table td {
  border: 1px solid var(--border-accent);
  padding: 4px 6px;
  vertical-align: middle;
}

.ic-char-col-header {
  min-width: 130px;
  background: var(--bg-surface-1);
  position: sticky;
  left: 0;
  z-index: 1;
}

.ic-chest-col-header {
  min-width: 70px;
  background: var(--bg-surface-1);
  vertical-align: bottom;
  padding-bottom: 6px;
}

.ic-header-chest-items {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  margin-bottom: 2px;
}

.ic-loot-item-sm {
  width: 34px;
  height: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.ic-loot-item-sm img {
  width: 30px;
  height: 30px;
}

.ic-item-header-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: 0.55rem;
  line-height: 1.1;
  width: 100%;
}

.ic-header-berries {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-title);
  margin-top: 2px;
}

.ic-char-name-cell {
  position: sticky;
  left: 0;
  background: var(--bg-panel);
  z-index: 1;
  min-width: 130px;
}

.ic-char-avatar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ic-char-avatar img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--bg-surface-1);
}

.ic-char-label {
  font-size: 0.78rem;
  color: var(--text-panel);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.ic-chest-cell {
  text-align: center;
  background: var(--bg-panel);
}

.ic-char-table tr:nth-child(even) .ic-chest-cell,
.ic-char-table tr:nth-child(even) .ic-char-name-cell {
  background: var(--bg-surface-1);
}

/* ---- Small chest cards (table cells) ---- */
.ic-chest-card-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.ic-chest-card-sm:hover {
  border-color: var(--border-accent);
}

.ic-chest-card-sm.ic-chest-card-checked {
  border-color: #27ae60;
  background: #27ae60;
}

.ic-chest-sprite-sm {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

/* ---- Empty / info messages ---- */
.ic-empty-msg {
  color: var(--text-panel);
  opacity: 0.6;
  font-style: italic;
  padding: 16px 0;
}

/* ---- Island-specific stats row ---- */
.ic-island-stats-row {
  border-top: 1px dashed var(--border-accent);
  padding-top: 8px;
  margin-top: 0;
}

.ic-island-label-prefix {
  font-style: italic;
}

/* ---- Stamina mode: fixed table viewport with horizontal scrollbar ---- */
.ic-stamina-mode .ic-main {
  overflow: hidden;
}

.ic-stamina-mode #ic-chests-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ic-stamina-mode .ic-stamina-all-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ic-stamina-mode .ic-stamina-all-wrap > .ic-section:last-child {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ic-stamina-mode .ic-top-scrollbar-wrap {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-panel);
  padding-bottom: 2px;
}

.ic-stamina-mode .ic-top-scrollbar {
  overflow-x: auto;
  overflow-y: hidden;
  height: 14px;
  scrollbar-gutter: stable;
  border: 1px solid var(--border-accent);
  border-radius: 999px;
  background: var(--bg-surface-1);
}

.ic-stamina-mode .ic-top-scrollbar-spacer {
  height: 1px;
  min-width: 100%;
}

.ic-stamina-mode .ic-char-table-wrap {
  flex: 1;
  min-height: 0;
  max-width: none;
  overflow-x: scroll;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding-bottom: 0;
  cursor: grab;
}

.ic-stamina-mode .ic-char-table-wrap.ic-dragging {
  cursor: grabbing;
}

.ic-stamina-mode .ic-char-table-wrap.ic-dragging * {
  user-select: none;
  pointer-events: none;
}

.ic-stamina-mode .ic-char-table,
.ic-stamina-mode .ic-stamina-table {
  width: max-content;
  min-width: 100%;
}

/* Force always-visible track (defeats macOS overlay/hidden scrollbars) */
.ic-stamina-mode .ic-char-table-wrap::-webkit-scrollbar {
  height: 12px;
  width: 12px;
}

.ic-stamina-mode .ic-char-table-wrap::-webkit-scrollbar-thumb {
  background: var(--text-title);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.ic-stamina-mode .ic-char-table-wrap::-webkit-scrollbar-track {
  background: var(--bg-surface-1);
  border-radius: 999px;
}

.ic-stamina-mode .ic-top-scrollbar::-webkit-scrollbar {
  height: 12px;
}

.ic-stamina-mode .ic-top-scrollbar::-webkit-scrollbar-thumb {
  background: var(--text-title);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.ic-stamina-mode .ic-top-scrollbar::-webkit-scrollbar-track {
  background: var(--bg-surface-1);
  border-radius: 999px;
}

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .ic-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .ic-main {
    height: auto;
    overflow-y: visible;
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .ic-sidebar {
    width: 100%;
    height: 170px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-accent);
    flex-wrap: nowrap;
    padding: 4px;
  }

  .ic-sidebar-actions {
    flex-direction: column;
    min-width: 120px;
    padding: 0 6px 0 2px;
  }

  .ic-sidebar-action-btn {
    white-space: nowrap;
  }

  .ic-island-btn {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    padding: 4px 4px;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .ic-island-btn.active {
    border-left-color: transparent;
    border-bottom-color: var(--border-accent);
  }

  .ic-island-panel {
    width: calc(100vw - 28px);
    min-width: calc(100vw - 28px);
  }
}
