:root {
  --ss-bg: #15101c;
  --ss-panel: #1f1826;
  --ss-panel-sunken: #130f19;
  --ss-border: #362c45;
  --ss-text: #f4eefb;
  --ss-muted: #a394b8;
  --ss-gold: #ffd23f;
  --ss-live: #ff3b5c;
  --ss-ink-on-gold: #1a1206;
  --ss-font-hero: 'Bungee', system-ui, sans-serif;
  --ss-font-heading: 'Baloo 2', sans-serif;
  --ss-font-body: 'Inter', system-ui, sans-serif;
  --ss-rail-width: 88px;

  /* Back-compat aliases: profit.css/gifts.css (out of scope for the rail
     redesign, still using the old topbar shell) reference these pre-redesign
     token names directly — without these, their panels/text render with
     missing colors since --tool-* stopped being defined anywhere. */
  --tool-panel: var(--ss-panel);
  --tool-border: var(--ss-border);
  --tool-muted: var(--ss-muted);
  --tool-accent: var(--ss-gold);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ss-bg);
  color: var(--ss-text);
  font-family: var(--ss-font-body);
  -webkit-font-smoothing: antialiased;
}

/* ===== App shell: left icon rail + content column ===== */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.rail {
  flex: 0 0 var(--ss-rail-width);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--ss-panel);
  border-right: 1px solid var(--ss-border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail::before {
  content: '';
  height: 3px;
  background: linear-gradient(90deg, var(--ss-gold), var(--ss-live));
}

.rail-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
  font-family: var(--ss-font-hero);
  font-size: 18px;
  color: var(--ss-gold);
  text-decoration: none;
  border-bottom: 1px solid var(--ss-border);
  letter-spacing: 0.5px;
}

.rail-links {
  display: flex;
  flex-direction: column;
  padding: 10px 0;
}

.rail-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  border-top: 1px solid var(--ss-border);
}

.rail-link {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  color: var(--ss-muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  transition: color 0.15s ease, background 0.15s ease;
}

.rail-icon {
  width: 20px;
  height: 20px;
}

.rail-link:hover {
  color: var(--ss-text);
  background: rgba(255, 210, 63, 0.06);
}

.rail-link.is-current {
  color: var(--ss-gold);
  background: rgba(255, 210, 63, 0.1);
}

.rail-link.is-current::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--ss-gold);
}

/* ===== Page header (replaces the old full-width topbar) ===== */
.app-content {
  flex: 1;
  min-width: 0;
}

.page-header {
  padding: 28px 32px 0;
}

.page-header h1 {
  font-family: var(--ss-font-heading);
  font-size: 22px;
  margin: 0;
}

.page-header p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ss-muted);
}

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.panel h2 {
  font-family: var(--ss-font-heading);
  font-size: 17px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--ss-muted);
  line-height: 1.5;
  max-width: 640px;
}

.count {
  font-size: 12px;
  font-weight: 600;
  color: var(--ss-muted);
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  padding: 2px 9px;
  border-radius: 999px;
}

/* ===== Form ===== */
.entry-form {
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.form-row label {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  color: var(--ss-muted);
  gap: 6px;
}

/* Muted inline note within a label — a clarifying detail (not an "optional"
   flag; optional fields simply carry no marker at all, see .required-mark
   below for the mandatory case). */
.form-row label .label-note {
  font-weight: 400;
  font-style: italic;
  color: #6d5f82;
}

.form-row label .required-mark {
  color: #ff6b7a;
  font-weight: 700;
  font-style: normal;
}

/* Reserves the same header height for every label sharing a form-row —
   without this, a label whose note/hint wraps to a second line pushes its
   input down while its shorter siblings (e.g. "Price") stay on one line,
   throwing inputs out of alignment across the row. */
.form-row label:not(.full-width) .label-title {
  display: block;
  min-height: 32px;
}

.form-row label.full-width {
  flex-basis: 100%;
  min-width: 100%;
}

.form-hint {
  margin: 10px 2px 0;
  font-size: 12px;
  color: #e8a13a;
}

/* ===== Bundle item checklist ===== */
.checklist {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
}

.checklist-empty {
  grid-column: 1 / -1;
  color: var(--ss-muted);
  font-size: 13px;
  padding: 10px;
}

/* Specificity note: when a checklist sits inside a form label (the Bundle
   modal's item picker), the generic `.form-row label` rule below also
   matches these nested <label class="checklist-item"> elements and would
   otherwise flip them to a column layout — `.checklist .checklist-item`
   below wins on specificity and keeps them a row regardless of nesting. */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.checklist .checklist-item {
  flex-direction: row;
  min-width: 0;
  flex: none;
}

.checklist-item:has(input:checked) {
  border-color: var(--ss-gold);
  background: rgba(255, 210, 63, 0.12);
}

.checklist-item img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 5px;
  background: #251b30;
  flex-shrink: 0;
}

.checklist-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.checklist-qty {
  width: 52px;
  flex-shrink: 0;
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  border-radius: 6px;
  color: var(--ss-text, #fff);
  padding: 4px 6px;
  font-size: 12px;
}

.checklist-qty:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ===== Grouped checklist (Bundle item picker) — categories stack, each
   category's items lay out in their own wrapping grid ===== */
.checklist.checklist-grouped {
  display: block;
  max-height: 320px;
}
.checklist-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

/* ===== Deals checklist — mini rendered cards instead of icon+text rows, so
   an item is recognizable by its actual rarity color/badge while picking
   deals, same spirit as the Bundle checklist already using real icons. ===== */
.checklist.deals-checklist {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  max-height: 340px;
}
.deal-checklist-item {
  flex-direction: column !important;
  align-items: stretch !important;
  position: relative;
  padding: 8px !important;
}
.deal-checklist-item input[type="checkbox"] {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.55);
}
.deal-preview-wrap {
  pointer-events: none;
  margin: 0 auto;
  width: calc(var(--item-card-width) * 0.6);
  height: calc(var(--card-height) * 0.6);
  transform: scale(0.6);
  transform-origin: top center;
}

.checklist-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.form-hint-static {
  display: block;
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 400;
  font-style: normal;
  color: var(--ss-muted);
}

/* ===== Out-of-stock toggle button (semantic red/green — not the brand accent) ===== */
.oos-btn {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--ss-border);
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.oos-btn.oos-inactive {
  color: #4ade80;
  border-color: #166534;
}
.oos-btn.oos-inactive:hover {
  color: #f87171;
  border-color: #991b1b;
}

.oos-btn.oos-active {
  color: #f87171;
  border-color: #991b1b;
  background: rgba(239, 68, 68, 0.08);
}
.oos-btn.oos-active:hover {
  color: #4ade80;
  border-color: #166534;
  background: transparent;
}

/* ===== Category tag on listing rows ===== */
.cat-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  padding: 3px 9px;
  border-radius: 20px;
  margin-right: auto; /* pushes entry-actions to the right */
}

/* In the editor preview context, cards need fixed widths
   (the display banner uses flex:1 via styles.css instead) */
.preview-wrap .item-card   { flex: none; width: var(--item-card-width); }
.preview-wrap .bundle-card { flex: none; width: var(--bundle-card-width); }

/* ===== Rarity list row ===== */
.rarity-row-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
}

.rarity-swatch {
  width: 52px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}

/* ===== Gradient preview bar ===== */
.gradient-preview {
  height: 32px;
  border-radius: 8px;
  flex: 1;
  border: 1px solid var(--ss-border);
  background: linear-gradient(135deg, var(--ss-gold), var(--ss-live));
  transition: background 0.2s;
}

.add-stop-btn { flex-shrink: 0; align-self: center; }

/* ===== Colour stop rows ===== */
.color-stops-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.color-stop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  padding: 8px 12px;
}

.stop-label {
  font-size: 12px;
  color: var(--ss-muted);
  width: 42px;
  flex-shrink: 0;
}

.stop-color-input {
  width: 44px !important;
  height: 32px !important;
  padding: 2px !important;
  border-radius: 6px !important;
  cursor: pointer;
  flex-shrink: 0;
}

.stop-remove {
  margin-left: auto;
  background: transparent;
  border: 1px solid #4a3d5c;
  color: #948a9f;
  border-radius: 6px;
  width: 26px; height: 26px;
  font-size: 16px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s;
}
.stop-remove:hover { color: #ef233c; border-color: #ef233c; }

/* ===== Rarity tag on library/listing rows ===== */
.rarity-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #fff;
  padding: 3px 9px;
  border-radius: 20px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Shown on a library row when its icon size has been manually adjusted */
.scale-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  color: var(--ss-muted);
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  padding: 3px 8px;
  border-radius: 20px;
}

/* ===== Library list ===== */
.library-list .entry-row {
  gap: 10px;
}

/* Left group: icon + name + category + rarity */
.lib-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.lib-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  background: #251b30;
  padding: 4px;
  flex-shrink: 0;
}

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

/* Right group: add to shop + edit + delete + oos — pushed to far right */
.lib-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.no-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #251b30;
  flex-shrink: 0;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row select {
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  color: var(--ss-text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
}

.form-row input[type="text"]:focus,
.form-row input[type="number"]:focus,
.form-row input[type="password"]:focus,
.form-row select:focus,
.form-row input[type="file"]:focus {
  outline: 2px solid var(--ss-gold);
  outline-offset: 1px;
}

.form-row input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: var(--ss-panel-sunken);
  padding: 3px;
  cursor: pointer;
}

.file-label input[type="file"] {
  color: var(--ss-muted);
  font-size: 12px;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 13px;
  color: var(--ss-text) !important;
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

button {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  background: var(--ss-gold);
  color: var(--ss-ink-on-gold);
  transition: filter 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(0) scale(0.97); }
button:focus-visible { outline: 2px solid var(--ss-live); outline-offset: 2px; }

button.secondary {
  background: transparent;
  color: var(--ss-muted);
  border: 1px solid var(--ss-border);
}

/* ===== List ===== */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Listings grouped by category ===== */
.listing-cat-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.listing-cat-group + .listing-cat-group {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--ss-border);
}
.listing-cat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
  border-bottom: 2px solid;
}
.listing-cat-count {
  font-size: 12px;
  color: var(--ss-muted);
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color 0.15s ease;
}

.entry-row:hover {
  border-color: #4a3d5c;
}

.entry-row .preview-wrap {
  flex-shrink: 0;
  transform: scale(0.82);
  transform-origin: left center;
  width: calc(var(--item-card-width) * 0.82);
}

.entry-row.bundle-row .preview-wrap {
  width: calc(var(--bundle-card-width) * 0.82);
}

.entry-row .entry-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.entry-row .entry-actions button {
  padding: 7px 11px;
  font-size: 12px;
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  color: var(--ss-muted);
}

.entry-row .entry-actions button:hover {
  color: var(--ss-text);
  border-color: var(--ss-gold);
}

.entry-row .entry-actions button.danger:hover {
  color: #ff6b7a;
  border-color: #ff6b7a;
}

.empty-state {
  color: var(--ss-muted);
  font-size: 13px;
  padding: 18px;
  text-align: center;
  border: 1px dashed var(--ss-border);
  border-radius: 12px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: calc(50% + 44px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  color: var(--ss-text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: #ff6b7a;
  color: #ff8a96;
}

/* ===== Add-trigger button (opens the add/edit modal) ===== */
.add-trigger-btn {
  margin: 4px 0 18px;
}
.add-trigger-btn:hover,
.form-actions button[type="submit"]:hover {
  box-shadow: 0 4px 14px rgba(255, 210, 63, 0.3);
}

/* ===== Edit/Add modal =====
   Hidden via opacity+visibility (not display:none) so opening/closing can
   animate into a "pop" — the [hidden] override below cancels the browser's
   default `[hidden]{display:none}` so our own transition can run. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}
.modal-overlay[hidden] {
  display: flex;
}
.modal-overlay:not([hidden]) {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.18s ease, visibility 0s linear 0s;
}

.modal-box {
  position: relative;
  background: var(--ss-panel);
  border: 1px solid var(--ss-border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.18s ease;
}
.modal-overlay:not([hidden]) .modal-box {
  transform: scale(1) translateY(0);
}

/* ===== Large rarity preview swatch (shown at the top of the rarity modal) ===== */
.rarity-swatch-lg {
  width: 100%;
  height: 90px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ss-font-heading);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 6px rgba(0,0,0,0.45);
  transition: background 0.2s;
}

.modal-box h3 {
  margin: 0 0 14px;
  font-family: var(--ss-font-heading);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  color: var(--ss-muted);
  border: 1px solid var(--ss-border);
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
}

.modal-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--ss-panel-sunken);
  border: 1px solid var(--ss-border);
  border-radius: 10px;
}

/* ===== General Settings panel ===== */
.settings-grid {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.settings-grid .modal-preview {
  flex: 0 0 260px;
  margin-bottom: 0;
}
.settings-form {
  flex: 1;
  min-width: 260px;
  margin-bottom: 0;
}
.style-options {
  display: flex;
  gap: 10px;
}
.style-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ss-muted);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.style-option input[type="radio"] { accent-color: var(--ss-gold); margin: 0; }
.style-option.is-active {
  border-color: var(--ss-gold);
  color: var(--ss-text);
  background: rgba(255, 210, 63, 0.1);
}
input[type="color"] {
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: var(--ss-bg);
  cursor: pointer;
}

.fonts-subsection {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--ss-border);
}
.fonts-subsection h3 {
  font-family: var(--ss-font-heading);
  font-size: 15px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.font-active-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--ss-gold);
  background: rgba(255, 210, 63, 0.15);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ===== Responsive: collapse rail to icon-only below tablet width ===== */
@media (max-width: 640px) {
  .rail-link span { display: none; }
  .rail-link { padding: 12px 2px; }
}
