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

:root {
  --c1: #ffe0e9;
  --c2: #ffc2d4;
  --c3: #ff9ebb;
  --c4: #ff7aa2;
  --c5: #e05780;
  --c6: #b9375e;
  --c7: #8a2846;
  --c8: #602437;
  --c9: #522e38;
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --content-pad: 28px;
}

body {
  font-family: 'Poppins', sans-serif;
  background: #f9f4f5;
  color: var(--c9);
  min-height: 100vh;
  display: flex;
}

/* ── Sidebar ────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  background: #fff;
  border-right: 1px solid var(--c2);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 200;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--c9);
  border-bottom: 1px solid var(--c2);
  flex-shrink: 0;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.sidebar-section-label {
  padding: 12px 20px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--c6);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: default;
  user-select: none;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 38px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c8);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.nav-item:hover { background: #fff0f3; }
.nav-item.active {
  background: var(--c1);
  color: var(--c6);
  border-left: 3px solid var(--c6);
  padding-left: 17px;
}

.nav-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--c3);
  flex-shrink: 0;
  transition: transform 0.2s;
}
.nav-item.open .nav-chevron { transform: rotate(90deg); }

.sub-list {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.sub-item {
  display: flex;
  align-items: center;
  padding: 0 20px 0 32px;
  height: 34px;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--c7);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.sub-item::before { content: '\00B7'; margin-right: 8px; color: var(--c3); }
.sub-item:hover { background: #fff0f3; }
.sub-item.active { color: var(--c6); font-weight: 500; }

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(82,46,56,0.35);
  z-index: 150;
}

/* ── Topbar ─────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--c2);
  display: flex;
  align-items: center;
  padding: 0 var(--content-pad);
  z-index: 100;
  gap: 12px;
}

#hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--c7);
  padding: 4px;
  line-height: 1;
  flex-shrink: 0;
}

#breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  flex-wrap: wrap;
}

#last-synced {
  padding: 12px 20px;
  font-size: 0.72rem;
  color: var(--c7);
  border-top: 1px solid var(--c1);
  flex-shrink: 0;
}

#global-search-wrap {
  position: relative;
  margin-left: auto;
  width: 280px;
  flex-shrink: 1;
  min-width: 0;
}

#global-search {
  width: 100%;
  font-family: 'Poppins', sans-serif;
  font-size: 0.8rem;
  color: var(--c9);
  background: #f9f4f5;
  border: 1px solid var(--c2);
  border-radius: 999px;
  padding: 7px 14px;
  outline: none;
}
#global-search:focus { border-color: var(--c6); background: #fff; }

#global-search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  max-width: calc(100vw - 32px);
  max-height: 360px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--c2);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(82,46,56,0.15);
  z-index: 300;
}
#global-search-results.open { display: block; }

.gsr-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--c1);
}
.gsr-item:last-child { border-bottom: none; }
.gsr-item:hover { background: #f9f4f5; }
.gsr-title { font-size: 0.85rem; font-weight: 500; color: var(--c9); }
.gsr-sub   { font-size: 0.72rem; color: var(--c7); }
.gsr-empty { padding: 14px; font-size: 0.8rem; color: var(--c7); text-align: center; }
.bc-sep { color: var(--c3); }
.bc-parent { color: var(--c7); cursor: pointer; }
.bc-parent:hover { color: var(--c6); text-decoration: underline; }
.bc-current { color: var(--c9); font-weight: 600; }

/* ── Main ───────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  flex: 1;
  padding: var(--content-pad);
  min-width: 0;
}
#d-chart-grid { margin-bottom: 20px; }
#r-chart-grid, #m-chart-grid { grid-template-columns: repeat(2, 1fr); }

/* Dimoo table: Type column only in misc dimoos view, Series column hidden there */
#section-dimoo .col-type { display: none; }
#section-dimoo .col-series { display: table-cell; }
#section-dimoo.misc-view .col-type { display: table-cell; }
#section-dimoo.misc-view .col-series { display: none; }

/* Hide Status column and filter in misc dimoos + pop beans views */
#section-dimoo.grouped-view .col-status { display: none; }
#section-dimoo.grouped-view #d-filter-owned { display: none; }

.section { display: none; }
.section.active { display: block; }

/* ── Today callout ──────────────────────────────────── */
#today-callout {
  display: none;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(82,46,56,0.08);
  border-left: 4px solid var(--c6);
  padding: 14px 20px;
  margin-bottom: 20px;
  position: relative;
  font-size: 0.85rem;
  color: var(--c9);
}
#today-callout.show { display: block; }
#today-callout .tc-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--c6);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
#today-callout .tc-line { margin-top: 4px; }
#today-callout .tc-line:first-of-type { margin-top: 0; }
#today-callout .tc-dismiss {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--c7);
  line-height: 1;
  padding: 4px;
}
#today-callout .tc-dismiss:hover { color: var(--c6); }

/* ── Stat grid ──────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(82,46,56,0.08);
  padding: 20px 24px;
  border-left: 4px solid var(--c6);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card.sp1 { border-left-color: var(--c6); }
.stat-card.sp2 { border-left-color: var(--c5); }
.stat-card.sp3 { border-left-color: var(--c4); }
.stat-card.sp4 { border-left-color: var(--c3); }

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--c7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--c6); line-height: 1.1; }
.stat-sub   { font-size: 0.78rem; font-weight: 400; color: var(--c7); }

/* ── Chart grid ─────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.chart-grid .wide { grid-column: 1 / -1; }

.chart-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(82,46,56,0.08);
}
.chart-header {
  padding: 16px 24px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--c7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--c2);
}
.chart-body { padding: 16px 24px 24px; }
.chart-body.tall   { height: 520px; }
.chart-body.medium { height: 280px; }
.chart-body canvas { max-width: 100%; }

/* ── Table card ─────────────────────────────────────── */
.table-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(82,46,56,0.08);
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--c2);
}
.table-title-row { display: flex; align-items: center; gap: 10px; }
.table-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--c7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.count-pill {
  background: rgba(185,55,94,0.10);
  color: var(--c6);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}
.table-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-filters select,
.table-filters input {
  font-family: 'Poppins', sans-serif;
  font-size: 0.8rem;
  color: var(--c9);
  background: #fff;
  border: 1px solid var(--c2);
  border-radius: 6px;
  padding: 5px 10px;
  outline: none;
}
.table-filters select:focus,
.table-filters input:focus { border-color: var(--c6); }

.table-scroll { overflow-y: auto; max-height: 520px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; }
thead { position: sticky; top: 0; z-index: 2; }
th {
  background: #fff0f3;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--c7);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 16px;
  text-align: left;
  white-space: nowrap;
}
th.sortable {
  cursor: pointer;
  user-select: none;
  padding-right: 26px;
  position: relative;
}
th.sortable:hover { color: var(--c6); }

/* Default unsorted: stacked up + down triangles */
th.sortable::before,
th.sortable::after {
  content: '';
  position: absolute;
  right: 9px;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0.35;
}
th.sortable::before {
  top: calc(50% - 6px);
  border-bottom: 5px solid var(--c7);
}
th.sortable::after {
  top: calc(50% + 1px);
  border-top: 5px solid var(--c7);
}

/* Ascending: only the up triangle, highlighted */
th[data-sort-dir="asc"]::before {
  border-bottom-color: var(--c6);
  opacity: 1;
}
th[data-sort-dir="asc"]::after  { border-top-color: transparent; opacity: 0; }

/* Descending: only the down triangle, highlighted */
th[data-sort-dir="desc"]::before { border-bottom-color: transparent; opacity: 0; }
th[data-sort-dir="desc"]::after {
  border-top-color: var(--c6);
  opacity: 1;
}
td {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--c9);
  padding: 10px 16px;
  border-bottom: 1px solid var(--c1);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fff0f3; }
.no-data-row td { text-align: center; color: var(--c7); padding: 32px; }

/* ── Badges ─────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-owned   { background: var(--c1); color: var(--c6); }
.badge-missing { background: var(--c7); color: var(--c2); }
.badge-yes     { background: var(--c1); color: var(--c6); }
.badge-no      { background: var(--c7); color: var(--c2); }
.badge-maybe   { background: var(--c5); color: #fff; }
.badge-rate-hi  { background: var(--c6); color: var(--c1); }
.badge-rate-mid { background: var(--c5); color: #fff; }
.badge-rate-lo  { background: var(--c2); color: var(--c7); }
.badge-S { background: var(--c7); color: var(--c1); }
.badge-A { background: var(--c6); color: var(--c1); }
.badge-B { background: var(--c5); color: #fff; }
.badge-C { background: var(--c3); color: var(--c8); }
.badge-D { background: var(--c2); color: var(--c8); }

/* ── OP TCG column visibility ───────────────────────────── */
/* Standard columns (number, rarity, color, alt, sp): shown by default, hidden in DON!! view */
#section-optcg .col-std { display: table-cell; }
#section-optcg .col-don { display: none; }
#section-optcg.don-view .col-std { display: none; }
#section-optcg.don-view .col-don { display: table-cell; }

/* Playing Cards: brand column hidden when filtered to one brand */
#section-playing .col-brand { display: table-cell; }
#section-playing.brand-filter .col-brand { display: none; }

/* ── OP TCG owner / rarity / special badges ─────────────── */
.badge-owner-alexis { background: var(--c1); color: var(--c6); }
.badge-owner-jordan { background: #e8e0f5; color: #4a3a8a; }
.badge-rarity-r     { background: var(--c2); color: var(--c8); }
.badge-rarity-sr    { background: var(--c6); color: #fff; }
.badge-rarity-sec   { background: var(--c8); color: #fff; }
.badge-sp           { background: var(--c7); color: var(--c1); }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 1023px) {
  #sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  #sidebar.open { transform: translateX(0); }
  #sidebar-backdrop.open { display: block; }
  #topbar { left: 0; }
  #main { margin-left: 0; }
  #hamburger { display: block; }
}
@media (max-width: 599px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  #global-search-wrap { width: 140px; }
}
