:root {
  --bg: #0b0e14;
  --card: #131720;
  --card-alt: #181d29;
  --border: #232a3b;
  --text: #e2e8f0;
  --muted: #8b95a5;
  --accent: #3b82f6;
  --accent-bg: rgba(59, 130, 246, 0.16);
  --rare: #ffff77;
  --unique: #af6025;
  --magic: #8888ff;
  --gem: #1ba29b;
  --currency: #aa9e82;
  --fire: #f87171;
  --cold: #38bdf8;
  --light: #facc15;
  --chaos: #d946ef;
  --life: #ef4444;
  --es: #38bdf8;
  --mana: #60a5fa;
  --pos: #22c55e;
  --neg: #ef4444;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* HEADER */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 14, 20, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-badge {
  font-size: 10px;
  background: var(--accent-bg);
  color: #60a5fa;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.league-select,
.btn-refresh {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
}

.btn-refresh {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-refresh:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* CONTAINER & CARDS */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 14px;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

/* INPUTS & BUTTONS */
.input-box {
  width: 100%;
  background: #0c1017;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}

.input-box:focus {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

/* CHECK STATUS BOX */
.check-status-box {
  display: none;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.check-status-box.ok {
  display: block;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
}

.check-status-box.err {
  display: block;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
}

/* STASH TABS BAR */
.stash-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.stash-tab-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.stash-tab-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: #60a5fa;
}

/* FILTERS & ACCOUNT */
.account-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.account-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

/* LISTINGS & ITEMS */
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.item-row:last-child {
  border-bottom: none;
}

.item-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  background: #0b0e14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rarity-1 { color: var(--magic); }
.rarity-2 { color: var(--rare); }
.rarity-3,
.rarity-9 { color: var(--unique); }
.rarity-4 { color: var(--gem); }
.rarity-5 { color: var(--currency); }

.price-div {
  color: #facc15;
  font-weight: 800;
  font-size: 13px;
}

.price-chaos {
  color: #f8fafc;
  font-weight: 700;
  font-size: 13px;
}

.price-other {
  color: #93c5fd;
  font-weight: 700;
  font-size: 13px;
}

.stash-tag {
  background: #1f2738;
  color: #a5b4fc;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 11px;
  margin-left: 6px;
}

/* HISTORY STATUS BADGES */
.status-pill {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
}

.status-sold {
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.status-repriced {
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.4);
}

.diff-banner {
  display: none;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

/* ECONOMY PILLS */
.pill-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 8px;
  scrollbar-width: none;
}

.pill-scroll::-webkit-scrollbar {
  display: none;
}

.pill {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.pill.active {
  background: var(--accent-bg);
  color: #60a5fa;
  border-color: var(--accent);
}

.star-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #475569;
  cursor: pointer;
  padding: 4px;
}

.star-btn.fav {
  color: #fbbf24;
}

/* TRACKED STASH TABS GRID */
.tracked-tabs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.tracked-tab-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1017;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
}

.tracked-tab-chip.checked {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.14);
}

/* MODAL POPUP */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.85);
  backdrop-filter: blur(6px);
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 680px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
}

.modal-box.modal-fullscreen {
  max-height: 94vh;
  height: 94vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.modal-sticky-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.modal-scroll-body {
  padding: 12px 14px calc(28px + env(safe-area-inset-bottom));
  overflow-y: auto;
  flex: 1;
}

/* CHART TREND CARDS */
.trend-card {
  background: #0d1119;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
}

.trend-card.highlight {
  border-color: var(--accent);
}

/* ITEM DETAIL MODS */
.mod-check-card {
  background: #141a26;
  border: 1px solid #263147;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.mod-check-card.enchant {
  background: rgba(180, 130, 50, 0.14);
  border-color: rgba(217, 160, 60, 0.4);
}

.mod-check-card.crafted {
  background: rgba(27, 162, 155, 0.14);
  border-color: rgba(27, 162, 155, 0.4);
}

.mod-min-input {
  width: 72px;
  background: #0a0d14;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

/* POB PLANNER & HERO CARDS */
.sub-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.sub-tab {
  background: var(--card-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.sub-tab.active {
  background: var(--accent-bg);
  color: #60a5fa;
  border-color: var(--accent);
}

.hero-dps-card {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.14) 0%, rgba(19, 23, 32, 0.98) 100%);
  border: 1px solid rgba(234, 179, 8, 0.45);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.hero-minion-card {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12) 0%, rgba(19, 23, 32, 0.98) 100%);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.hero-def-card {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(19, 23, 32, 0.98) 100%);
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.pool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.pool-card,
.res-card {
  background: #0d1119;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.pool-val {
  font-size: 16px;
  font-weight: 800;
}

.res-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.res-title {
  font-size: 10px;
  font-weight: 700;
}

.res-val {
  font-size: 15px;
  font-weight: 800;
  margin: 2px 0;
}

.res-sub {
  font-size: 10px;
  color: var(--muted);
}

.stat-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.stat-line:last-child {
  border-bottom: none;
}

/* GEAR PAPER-DOLL GRID */
.gear-doll-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.gear-slot-box {
  background: #0c1017;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}

.gear-slot-box.empty {
  opacity: 0.4;
  cursor: default;
}

.gear-slot-box.rarity-UNIQUE {
  border-color: rgba(175, 96, 37, 0.7);
  background: rgba(175, 96, 37, 0.1);
}

.gear-slot-box.rarity-RARE {
  border-color: rgba(255, 255, 119, 0.55);
  background: rgba(255, 255, 119, 0.06);
}

.gear-slot-box.rarity-MAGIC {
  border-color: rgba(136, 136, 255, 0.55);
  background: rgba(136, 136, 255, 0.08);
}

.gear-slot-lbl {
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.gear-slot-name {
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.flask-row-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 6px;
}

.jewel-row-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: 8px;
}

/* FLOATING BOTTOM NAV */
.bottom-nav {
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  max-width: 656px;
  margin: 0 auto;
  z-index: 40;
  background: rgba(19, 23, 32, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px;
  gap: 4px;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 11px;
  cursor: pointer;
}

.nav-btn.active {
  color: #60a5fa;
  background: var(--accent-bg);
}

.nav-icon {
  font-size: 18px;
  line-height: 1;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 12px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
}

.badge-pos {
  color: var(--pos);
  font-size: 11.5px;
  font-weight: 600;
}

.badge-neg {
  color: var(--neg);
  font-size: 11.5px;
  font-weight: 600;
}

.empty-prompt {
  text-align: center;
  padding: 22px 12px;
}