:root {
  --bg-base: #0d0e10;
  --bg-surface: #16181b;
  --bg-filter-panel: #1f2227;
  --bg-filter-header: #2a2e35;
  --bg-elevated: #23272c;
  --bg-hover: #2d3238;
  --border-subtle: #282c31;
  --border-filter: #555d68;
  --border-strong: #68707c;
  --border-active: #ffffff;
  --text-primary: #f4f5f7;
  --text-secondary: #b5bcc4;
  --text-muted: #7e8690;
  --accent-white: #ffffff;
  --accent-dark: #0d0e10;
  --radius-sm: 6px;
  --radius-md: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(13, 14, 16, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-primary);
}

.brand-title {
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 13.5px;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  padding: 2px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
}

.subserver-group {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.pill-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.pill-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.pill-btn.active {
  background: var(--text-primary);
  color: var(--accent-dark);
}

/* Main Two-Column Layout */
.workspace {
  max-width: 1520px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 22px;
  align-items: start;
}

/* Distinct Zone Banners (Filter vs Accounts) */
.zone-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
}

.zone-filter-banner {
  background: var(--bg-filter-header);
  border-bottom: 1px solid var(--border-filter);
}

.zone-results-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.zone-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.zone-title-wrap h2 {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-badge {
  background: var(--text-primary);
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.step-badge-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.zone-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.collapse-btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.mobile-only {
  display: none;
}

/* ZONE 1: Left Filter Panel (Visually Distinct from Account Cards!) */
.picker-sidebar {
  position: sticky;
  top: 62px;
  max-height: calc(100vh - 78px);
  display: flex;
  flex-direction: column;
  background: var(--bg-filter-panel);
  border: 2px solid var(--border-filter);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.picker-body {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  overflow: hidden;
  flex: 1;
}

.picker-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--text-primary);
  padding: 6px 9px;
  border-radius: 3px;
}

.picker-controls-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.search-box input,
.code-search-input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-filter);
  color: var(--text-primary);
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.search-box input:focus,
.code-search-input:focus {
  border-color: var(--text-primary);
}

.rarity-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-base);
  border: 1px solid var(--border-filter);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.rarity-tab {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background 0.14s, color 0.14s;
}

.rarity-tab.active {
  background: var(--text-primary);
  color: var(--accent-dark);
}

.card-picker-grid {
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-right: 2px;
}

.card-picker-grid::-webkit-scrollbar {
  width: 5px;
}

.card-picker-grid::-webkit-scrollbar-thumb {
  background: var(--border-filter);
  border-radius: 3px;
}

/* Filter Tile has an explicit "+ Filter" / "✓ Selected" button look */
.picker-tile {
  background: #141619;
  border: 1px dashed var(--border-filter);
  border-radius: var(--radius-sm);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  min-width: 0;
  transition: border-color 0.14s, background 0.14s;
}

.picker-tile:hover {
  border-style: solid;
  border-color: var(--text-primary);
  background: var(--bg-hover);
}

.picker-tile.selected {
  border-style: solid;
  border-color: var(--accent-white);
  box-shadow: 0 0 0 1.5px var(--accent-white);
  background: #2b3037;
}

.tile-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.tile-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-tier {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(13, 14, 16, 0.9);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  font-size: 9.5px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 3px;
}

.tile-check {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(13, 14, 16, 0.88);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
}

.picker-tile.selected .tile-check {
  background: var(--accent-white);
  color: var(--accent-dark);
  border-color: var(--accent-white);
  font-weight: 800;
}

.tile-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-sub {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ZONE 2: Right Account Results Section */
.results-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.results-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.code-filter-bar {
  display: flex;
}

.action-btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, border-color 0.14s;
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Selected Filter Chips */
.selected-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg-filter-panel);
  border: 1px solid var(--border-filter);
  border-radius: var(--radius-md);
  padding: 9px 12px;
}

.chips-label {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-base);
  border: 1px solid var(--text-primary);
  border-radius: 6px;
  padding: 3px 8px 3px 4px;
  font-size: 12px;
  font-weight: 600;
}

.chip img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--text-primary);
}

/* Account Result Cards (Clearly Structured as Account Boxes with Header Bar) */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--text-primary);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.account-top {
  background: #1c1f24;
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.account-id-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.account-code {
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.badge-subserver {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: 4px;
}

.badge-ssr-total {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-dark);
  background: var(--text-primary);
  padding: 2px 9px;
  border-radius: 4px;
  letter-spacing: 0.03em;
}

.copy-btn {
  background: var(--text-primary);
  color: var(--accent-dark);
  border: 1px solid var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.copy-btn:hover {
  opacity: 0.9;
}

.account-cards-strip {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}

.acc-card-item {
  position: relative;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  color: var(--text-primary);
  min-width: 0;
}

.acc-card-item:hover {
  border-color: var(--border-strong);
}

.acc-card-item.matched {
  border-color: var(--accent-white);
  box-shadow: 0 0 0 1.5px var(--accent-white);
}

.acc-card-pic {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.acc-card-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.acc-card-count {
  position: absolute;
  bottom: 3px;
  right: 3px;
  background: rgba(13, 14, 16, 0.92);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 3px;
}

.acc-card-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.pager-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 8px;
}

.page-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 700;
}

/* Lightbox */
.lightbox[hidden],
.toast[hidden],
.selected-chips[hidden],
.pager-bar[hidden],
.text-btn[hidden],
.picker-body[hidden] {
  display: none !important;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.84);
}

.lightbox-dialog {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px;
  max-width: 720px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lightbox-dialog img {
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 6px;
  background: var(--bg-base);
}

.lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: rgba(13, 14, 16, 0.88);
  color: var(--text-primary);
  cursor: pointer;
}

.lightbox-caption {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lightbox-caption span {
  font-size: 12px;
  color: var(--text-secondary);
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 90;
  background: var(--text-primary);
  color: var(--accent-dark);
  font-weight: 800;
  font-size: 12.5px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Mobile Layout: Clear visual separation between Filter Drawer and Accounts List */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 12px 12px 40px;
    gap: 16px;
  }
  .mobile-only {
    display: inline-flex;
  }
  .picker-sidebar {
    position: static;
    max-height: none;
  }
  /* Horizontal or compact 4-column scrollable tray on mobile so it never looks like an account card */
  .card-picker-grid {
    max-height: 270px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .account-cards-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 10px;
  }
}

@media (max-width: 420px) {
  .card-picker-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
