/* ═══════════════════════════════════════════════════════════════════
   DATASETS CATALOG — histopath.ai
   Public-facing dataset browser. No auth required.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #0B0F1A;
  --bg-alt: #0F1322;
  --surface: #151A2B;
  --surface-alt: #1C2238;
  --surface-hover: #232B44;
  --border: rgba(255,255,255,.06);
  --border-strong: rgba(255,255,255,.12);
  --text: #F0F2F8;
  --text-secondary: #8B93A8;
  --text-muted: #7A85A0;
  --brand: #7C3AED;
  --brand-light: #A78BFA;
  --brand-dim: rgba(124,58,237,.12);
  --teal: #0D9488;
  --teal-dim: rgba(13,148,136,.12);
  --rose: #E11D48;
  --rose-dim: rgba(225,29,72,.12);
  --amber: #D97706;
  --amber-dim: rgba(217,119,6,.12);
  --green: #10B981;
  --green-dim: rgba(16,185,129,.12);
  --red: #EF4444;
  --blue: #3B82F6;
  --blue-dim: rgba(59,130,246,.12);
  --glass: rgba(255,255,255,.02);
  --glass-border: rgba(255,255,255,.06);
  --shadow: 0 4px 24px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
  --mono: 'JetBrains Mono','SF Mono','Cascadia Code','Fira Code',monospace;
  --sans: 'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --nav-width: 240px;
  --topbar-h: 52px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: var(--sans); cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: var(--sans); outline: none; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ── Utility ── */
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═══════════════════════════════════════════════════════════════════
   APP SHELL
   ═══════════════════════════════════════════════════════════════════ */
.ds-app {
  display: flex;
  height: 100vh;
}

.ds-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Top Bar ── */
.ds-topbar {
  height: var(--topbar-h);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.ds-topbar-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.ds-topbar-title span {
  color: var(--brand-light);
}

.ds-search-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.ds-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}

.ds-search {
  width: 100%;
  padding: 7px 14px 7px 36px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  transition: border-color .2s, box-shadow .2s;
}
.ds-search::placeholder { color: var(--text-muted); }
.ds-search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim); }

.ds-stats {
  display: flex;
  gap: 16px;
  margin-left: auto;
  flex-shrink: 0;
}

.ds-stat {
  text-align: center;
  line-height: 1.2;
}

.ds-stat-value {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-light);
}

.ds-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Filter Bar ── */
.ds-filterbar {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-filterbar::-webkit-scrollbar { display: none; }

.ds-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ds-filter-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.ds-chip:hover { background: var(--surface-hover); color: var(--text); }
.ds-chip.active { background: var(--brand-dim); color: var(--brand-light); border-color: rgba(124,58,237,.3); }

.ds-chip .ds-chip-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255,255,255,.05);
  padding: 0 5px;
  border-radius: 3px;
}
.ds-chip.active .ds-chip-count { background: rgba(124,58,237,.2); color: var(--brand-light); }

.ds-filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border-strong);
  flex-shrink: 0;
  margin: 0 4px;
}

/* ── Result count bar ── */
.ds-result-bar {
  padding: 6px 20px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ds-result-bar strong { color: var(--text-secondary); font-weight: 600; }

/* ── Content Area ── */
.ds-content-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.ds-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
}

/* ── Loading ── */
.ds-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.ds-spinner {
  width: 24px; height: 24px;
  border: 2px solid rgba(255,255,255,.1);
  border-top-color: var(--brand-light);
  border-radius: 50%;
  animation: ds-spin .8s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

/* ── Logo ── */
.ds-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ds-logo-mark {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.ds-logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.ds-logo-sub {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: .06em;
}

.ds-topbar-left { flex-shrink: 0; }
.ds-topbar-center { flex: 1; display: flex; justify-content: center; }
.ds-topbar-right { flex-shrink: 0; }

.ds-filter-sections {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-filter-sections::-webkit-scrollbar { display: none; }

.ds-chips {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   LIST VIEW
   ═══════════════════════════════════════════════════════════════════ */
.ds-table {
  width: 100%;
  border-collapse: collapse;
}

.ds-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  z-index: 1;
}

.ds-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.ds-table tbody tr:hover { background: var(--surface); }

.ds-table td {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  vertical-align: middle;
  white-space: nowrap;
}

.ds-table .ds-col-name {
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ds-table .ds-col-images {
  font-family: var(--mono);
  font-size: 12px;
}

.ds-table .ds-col-action {
  text-align: right;
}

.ds-table-dl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  background: var(--brand-dim);
  color: var(--brand-light);
  transition: all .15s;
}
.ds-table-dl:hover { background: var(--brand); color: white; }
.ds-table-dl svg { width: 12px; height: 12px; }

/* ═══════════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════════ */
.badge {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .03em;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-amber  { background: var(--amber-dim);  color: var(--amber); }
.badge-teal   { background: var(--teal-dim);   color: var(--teal); }
.badge-rose   { background: var(--rose-dim);   color: var(--rose); }
.badge-brand  { background: var(--brand-dim);  color: var(--brand-light); }
.badge-blue   { background: var(--blue-dim);   color: var(--blue); }
.badge-red    { background: rgba(239,68,68,.12); color: var(--red); }
.badge-muted  { background: rgba(255,255,255,.05); color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════
   CARD HEADER COLORS (by color token name, set by JS)
   ═══════════════════════════════════════════════════════════════════ */
.ds-card-header-rose   { background: var(--rose); }
.ds-card-header-teal   { background: var(--teal); }
.ds-card-header-amber  { background: var(--amber); }
.ds-card-header-blue   { background: var(--blue); }
.ds-card-header-brand  { background: var(--brand); }
.ds-card-header-green  { background: var(--green); }
.ds-card-header-muted  { background: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════
   DETAIL PANEL (inline slide-in)
   ═══════════════════════════════════════════════════════════════════ */
.ds-detail {
  width: 0;
  overflow: hidden;
  background: var(--bg-alt);
  border-left: 1px solid transparent;
  transition: width .3s cubic-bezier(.4,0,.2,1), border-color .3s;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.ds-detail.open {
  width: 420px;
  border-left-color: var(--border-strong);
}

.ds-detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: rgba(255,255,255,.7);
  transition: all .15s;
  z-index: 1;
}
.ds-detail-close:hover { background: rgba(255,255,255,.1); color: white; }

.ds-detail-header {
  position: relative;
  padding: 24px 20px 20px;
  flex-shrink: 0;
  min-width: 420px;
}

.ds-detail-organ-icon {
  width: 40px; height: 40px;
  margin-bottom: 12px;
  color: rgba(255,255,255,.9);
}
.ds-detail-organ-icon svg { width: 40px; height: 40px; }

.ds-detail-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  padding-right: 36px;
  color: white;
}

.ds-detail-organ {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  margin-top: 4px;
}

.ds-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 420px;
}

.ds-detail-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ds-detail-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.ds-detail-value {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.ds-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ds-detail-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}

.ds-detail-stat-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ds-detail-stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.ds-detail-dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: var(--brand);
  color: white;
  transition: all .15s;
}
.ds-detail-dl:hover { background: #6D28D9; box-shadow: 0 6px 20px rgba(124,58,237,.35); }
.ds-detail-dl svg { width: 16px; height: 16px; }

.ds-detail-src {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  transition: color .15s;
}
.ds-detail-src:hover { color: var(--brand-light); }
.ds-detail-src svg { width: 11px; height: 11px; vertical-align: -1px; margin-right: 4px; }

/* ── Card description ── */
.ds-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Card stats row ── */
.ds-card-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 6px;
}

.ds-card-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Card organ icon ── */
.ds-card-organ-icon {
  width: 16px; height: 16px;
  color: rgba(255,255,255,.8);
  flex-shrink: 0;
}
.ds-card-organ-icon svg { width: 16px; height: 16px; }

.ds-card-organ-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,.8);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── Table name cell ── */
.ds-cell-name { max-width: 320px; }

.ds-name-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ds-name-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ds-name-icon svg { width: 16px; height: 16px; }
.ds-name-icon-rose  { background: var(--rose-dim); color: var(--rose); }
.ds-name-icon-teal  { background: var(--teal-dim); color: var(--teal); }
.ds-name-icon-amber { background: var(--amber-dim); color: var(--amber); }
.ds-name-icon-blue  { background: var(--blue-dim); color: var(--blue); }
.ds-name-icon-brand { background: var(--brand-dim); color: var(--brand-light); }
.ds-name-icon-green { background: var(--green-dim); color: var(--green); }
.ds-name-icon-muted { background: rgba(255,255,255,.05); color: var(--text-muted); }

.ds-name-primary {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.ds-name-desc {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ds-cell-source { color: var(--text-muted); }

.ds-row-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all .15s;
}
.ds-row-link:hover { background: var(--brand-dim); color: var(--brand-light); }

.ds-patch-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 6px;
}

.ds-col-num { text-align: right; }

.ds-sort-arrow {
  font-size: 10px;
  margin-left: 2px;
}
.ds-sort-arrow.inactive { opacity: .3; }

.ds-th-sortable { cursor: pointer; user-select: none; }
.ds-th-sortable:hover { color: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════════════════ */
.ds-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.ds-empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  opacity: .4;
  margin-bottom: 16px;
}

.ds-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.ds-empty-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.ds-empty-clear {
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-light);
  background: var(--brand-dim);
  transition: all .15s;
}
.ds-empty-clear:hover { background: rgba(124,58,237,.2); }

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .ds-app > nav { display: none; }

  .ds-topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .ds-stats { display: none; }

  .ds-search-wrap { max-width: none; }

  .ds-filterbar { padding: 8px 12px; }

  .ds-content { padding: 12px; }

  .ds-detail.open { width: 100vw; position: fixed; top: 0; right: 0; height: 100vh; z-index: 100; }

  .ds-table td:nth-child(n+5) { display: none; }
  .ds-table thead th:nth-child(n+5) { display: none; }
  .ds-table td:nth-child(3) { display: none; }
  .ds-table thead th:nth-child(3) { display: none; }
}

@media (max-width: 480px) {
  .ds-topbar-title { font-size: 13px; }
}

/* ═══════════════════════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════════════════════ */
.ds-content::-webkit-scrollbar { width: 6px; }
.ds-content::-webkit-scrollbar-track { background: transparent; }
.ds-content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.ds-content::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.16); }

.ds-detail-body::-webkit-scrollbar { width: 5px; }
.ds-detail-body::-webkit-scrollbar-track { background: transparent; }
.ds-detail-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
