/* ── Inventory page ──────────────────────────────────── */
.inv-wrap {
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Toolbar ─────────────────────────────────────────── */
.inv-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.toolbar-btn:hover { background: var(--border); }
.toolbar-btn.danger:hover {
  background: #3a1010; border-color: #7a2020; color: #ff9999;
}
.toolbar-btn.active-toggle {
  background: var(--border);
  border-color: var(--muted);
  font-weight: 600;
}

/* ── Tab bar ─────────────────────────────────────────── */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.tab-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.tab-btn:hover { background: var(--border); color: var(--text); }
.tab-btn.active {
  background: var(--border);
  color: var(--text);
  font-weight: 600;
  border-color: var(--muted);
}
/* Separator between alpha tab and section tabs */
.tab-btn.tab-alpha {
  border-style: solid;
}
.tab-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 0 0.1rem;
}

/* ── Stats panel ─────────────────────────────────────── */
.stats-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  cursor: pointer;
  user-select: none;
}
.stats-header:hover { background: var(--border); }
.stats-header strong { font-size: 0.9rem; }
.stats-arrow {
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.15s;
}
.stats-panel.open .stats-arrow { transform: rotate(180deg); }
.stats-body {
  display: none;
  padding: 0.75rem 1rem;
  gap: 2rem;
  border-top: 1px solid var(--border);
}
.stats-panel.open .stats-body { display: flex; flex-wrap: wrap; }
.stats-group { display: flex; flex-direction: column; gap: 0.3rem; min-width: 160px; }
.stats-group-title {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
}
.stats-row .s-label { color: var(--muted); }
.stats-row .s-value { font-weight: 600; }

/* ── Section panel ───────────────────────────────────── */
.section-panel { display: none; }
.section-panel.active { display: block; }
.section-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.section-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
}
.section-title-bar strong { font-size: 0.9rem; }
.section-subtitle { font-size: 0.8rem; color: var(--muted); }

/* ── Ore table ───────────────────────────────────────── */

/* Horizontal-only scroll wrapper. The panel is never height-constrained —
   it always takes up exactly the vertical space its rows need, exactly
   like it would without this wrapper. Only left/right scrolling happens
   here, so wide tables don't force the page itself to scroll sideways.
   The sticky rules below keep the ore-name column ("frozen" like a
   spreadsheet) and the header row visible while scrolling. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll::-webkit-scrollbar { height: 8px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.ore-table {
  width: 100%;
  min-width: 640px; /* forces horizontal scroll instead of squishing on narrow screens */
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.ore-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 0.4rem 0.6rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ore-table thead th.th-right { text-align: right; }
.ore-table tbody tr {
  transition: background 0.07s;
}
.ore-table tbody tr:hover { background: rgba(255,255,255,0.025); }
[data-theme="light"] .ore-table tbody tr:hover { background: rgba(0,0,0,0.03); }
/* Border lives on the cells, not the row — a <tr> border isn't reliably
   painted once a sticky-positioned cell (the frozen name column) is
   involved, since the sticky cell paints above the row's own border. */
.ore-table td {
  padding: 0.28rem 0.6rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.ore-table tbody tr:last-child td { border-bottom: none; }

/* Freeze the first (ore name) column while horizontally scrolling.
   width:1% + white-space:nowrap is the standard auto-table-layout trick
   to make this column shrink-wrap to its content instead of stretching —
   this is what keeps it from claiming more horizontal space than the
   name/icon actually needs (and the sticky-position artifact that comes
   from a column that's wider than its visible content). */
.ore-table td:first-child,
.ore-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
  width: 1%;
  white-space: nowrap;
}
/* Top-left corner cell sits above both sticky axes */
.ore-table thead th:first-child { z-index: 4; }

/* Ore name cell — styled like the trade page trigger buttons */
.ore-name-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: 'Source Sans 3', 'Source Sans Pro', system-ui, sans-serif;
  font-weight: bold;
  white-space: nowrap;
  width: 100%;
  /* color and background set inline from ore data */
}
/* ── Icons (ore images) ────────────────────────────────────── */
.ore-icon-box {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ore-icon {
  width: auto;
  height: auto;
  max-width: 30px;
  max-height: 30px;
  image-rendering: pixelated;
  border-radius: 2px;
}

/* Amount input */
.amount-inp {
  width: 100px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.28rem 0.45rem;
  font-size: 0.85rem;
  font-family: inherit;
}
.amount-inp:focus { outline: none; border-color: var(--muted); }

.td-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.td-muted { color: var(--muted); }
.td-av { font-weight: 600; }

/* Notes input */
.notes-inp {
  width: 100%;
  min-width: 100px;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.2rem 0;
  transition: border-color 0.1s, color 0.1s;
}
.notes-inp:focus { outline: none; border-bottom-color: var(--border); color: var(--text); }
.notes-inp::placeholder { color: var(--border); }

/* ── Section footer ──────────────────────────────────── */
.section-footer {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}
.footer-stat { display: flex; gap: 0.35rem; align-items: center; }
.footer-stat .f-label { color: var(--muted); }
.footer-stat .f-value { font-weight: 600; }

/* ── Generic modal overlay ───────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

/* Simple (non-layout) modals */
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  width: 100%;
  max-width: 380px;
}
.modal-box h3 { margin-bottom: 0.5rem; font-size: 1rem; }
.modal-box p { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
.modal-actions button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  font-family: inherit;
}
.modal-actions button:hover { background: var(--border); }
.modal-actions button.btn-primary {
  background: #1a3a1a; border-color: #2d6b2d; color: #8eff8e;
}
.modal-actions button.btn-primary:hover { background: #254825; }
.modal-actions button.btn-danger {
  background: #3a1010; border-color: #7a2020; color: #ff9999;
}
.modal-actions button.btn-danger:hover { background: #4a1818; }

/* ── Layout modal — fixed height, inner scroll ───────── */
.layout-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.layout-modal-overlay.open { display: flex; }

.layout-modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 680px;
  /* Fixed height layout: header + presets + sections (scrollable) + footer */
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.layout-modal-header {
  padding: 1.1rem 1.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.layout-modal-header h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.layout-modal-header p { font-size: 0.82rem; color: var(--muted); margin: 0; }

.layout-modal-presets {
  padding: 0.75rem 1.4rem 0;
  flex-shrink: 0;
}
.layout-modal-presets-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.preset-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.preset-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  font-family: inherit;
  transition: background 0.1s;
}
.preset-btn:hover { background: var(--border); }
.preset-btn.active { border-color: var(--muted); font-weight: 600; }

/* THE scrollable region — this is the only part that scrolls */
.layout-modal-sections {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  /* Thin scrollbar */
  scrollbar-width: thin;
}
.layout-modal-sections::-webkit-scrollbar { width: 5px; }
.layout-modal-sections::-webkit-scrollbar-track { background: transparent; }
.layout-modal-sections::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.layout-modal-footer {
  padding: 0.75rem 1.4rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ── Section editor cards ────────────────────────────── */
.le-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0; /* prevent squish */
}
.le-section.dragging { opacity: 0.4; }
.le-section.drag-over { border-color: var(--muted); }

.le-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.le-drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1rem;
  padding: 0 0.15rem;
  user-select: none;
  flex-shrink: 0;
}
.le-drag-handle:active { cursor: grabbing; }
.le-section-name {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 0;
}
.le-section-name:focus { outline: none; }
.le-section-name::placeholder { color: var(--muted); }
.le-remove-section {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  font-family: inherit;
  flex-shrink: 0;
}
.le-remove-section:hover { color: #ff9999; }

.le-ore-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.6rem;
  min-height: 38px;
}
.le-ore-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.45rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  user-select: none;
}
.le-ore-chip img {
  width: 15px; height: 15px;
  object-fit: contain;
  image-rendering: pixelated;
}
.le-chip-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  opacity: 0.55;
}
.le-chip-remove:hover { opacity: 1; }

.le-add-ore-btn {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 3px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.18rem 0.45rem;
  font-family: inherit;
  align-self: center;
}
.le-add-ore-btn:hover { background: var(--border); color: var(--text); }

.le-add-section-btn {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
}
.le-add-section-btn:hover { background: var(--border); color: var(--text); }

/* ── Ore picker popup ────────────────────────────────── */
.ore-picker-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 600;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.ore-picker-overlay.open { display: flex; }
.ore-picker-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  width: 440px;
  max-width: 95vw;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.ore-picker-box h4 { font-size: 0.95rem; margin: 0; flex-shrink: 0; }
.ore-picker-search {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  width: 100%;
  flex-shrink: 0;
}
.ore-picker-search:focus { outline: none; border-color: var(--muted); }
.ore-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  overflow-y: auto;
  flex: 1;
  align-content: flex-start;
}
.ore-pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.5rem;
  border-radius: 3px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.1s, filter 0.1s;
}
.ore-pick-chip:hover { filter: brightness(1.15); }
.ore-pick-chip.already-added {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}
.ore-pick-chip img {
  width: 16px; height: 16px;
  object-fit: contain;
  image-rendering: pixelated;
}
.ore-picker-actions { display: flex; justify-content: flex-end; flex-shrink: 0; }
.ore-picker-actions button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.35rem 0.9rem;
  font-family: inherit;
}
.ore-picker-actions button:hover { background: var(--border); }

/* ── Section checkboxes ──────────────────────────────── */
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.data-notice { font-size: 0.8rem; color: var(--muted); }

@media (max-width: 580px) {
  .amount-inp { width: 75px; }
}

/* ── Compact mode ─────────────────────────────────────
   Only difference from the normal view: ore buttons drop their name
   label, becoming a square icon-only button (icon stays the same size
   as normal). Nothing else shrinks — fonts, padding, row height, and
   columns stay exactly as they are outside compact mode. */
.inv-wrap.compact .ore-name-btn .ore-name-text {
  display: none;
}
.inv-wrap.compact .ore-name-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  gap: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Interactive Header Sorting ──────────────────────── */
.sortable-th {
  cursor: pointer;
  user-select: none;
  transition: color 0.1s ease;
}

.sortable-th:hover {
  color: var(--text);
}

.sort-icon {
  display: inline-block;
  margin-left: 0.25rem;
  font-size: 0.75rem;
  opacity: 0.4;
  transition: opacity 0.1s ease;
}

.sortable-th:hover .sort-icon {
  opacity: 0.8;
}

.sortable-th.active-sort {
  color: var(--text);
  font-weight: bold;
}

.sortable-th.active-sort .sort-icon {
  opacity: 1;
}

/* Center alignment helpers */
.ore-table thead th.th-center { text-align: center; }

.td-center {
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
