/* ============================================================
   Smart Crypto Portfolio — shared design system
   Premium / modern · warm charcoal · gold accent · Helvetica
   ============================================================ */

:root {
  /* --- surface tone (parametrized for Tweaks) --- */
  --surf-hue: 72;        /* warm charcoal default */
  --surf-chroma: 0.006;

  /* --- charcoal surface tiers --- */
  --bg-0: oklch(0.165 var(--surf-chroma) var(--surf-hue));   /* app background (deepest) */
  --bg-1: oklch(0.205 var(--surf-chroma) var(--surf-hue));   /* panels / sidebar */
  --bg-2: oklch(0.235 calc(var(--surf-chroma) + 0.001) var(--surf-hue));   /* raised cards */
  --bg-3: oklch(0.275 calc(var(--surf-chroma) + 0.002) var(--surf-hue));   /* hover / inset */
  --line: oklch(0.32 var(--surf-chroma) var(--surf-hue));    /* hairline border */
  --line-soft: oklch(0.27 var(--surf-chroma) var(--surf-hue));

  /* --- whites (tinted to tone) --- */
  --fg:        oklch(0.955 var(--surf-chroma) var(--surf-hue));
  --fg-muted:  oklch(0.74 0.008 var(--surf-hue));
  --fg-faint:  oklch(0.56 0.008 var(--surf-hue));
  --fg-ghost:  oklch(0.44 0.007 var(--surf-hue));

  /* --- accent: restrained gold (overridable) --- */
  --accent:      oklch(0.80 0.105 82);
  --accent-dim:  color-mix(in oklab, var(--accent) 14%, transparent);
  --accent-line: color-mix(in oklab, var(--accent) 40%, transparent);

  /* --- meaning: calm gain / loss --- */
  --gain:     oklch(0.78 0.135 158);
  --gain-dim: oklch(0.78 0.135 158 / 0.13);
  --loss:     oklch(0.69 0.150 27);
  --loss-dim: oklch(0.69 0.150 27 / 0.13);

  /* --- coin family hues (muted, harmonious) --- */
  --c-btc:  oklch(0.76 0.115 72);
  --c-eth:  oklch(0.70 0.095 280);
  --c-sol:  oklch(0.75 0.115 180);
  --c-link: oklch(0.70 0.105 248);
  --c-dot:  oklch(0.71 0.115 350);

  /* --- geometry --- */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
}

[data-round="sharp"] { --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 10px; }
[data-round="round"] { --r-sm: 12px; --r-md: 16px; --r-lg: 22px; --r-xl: 30px; }

:root {

  /* --- density (overridden by [data-density]) --- */
  /* Fluid by default: scales smoothly with viewport instead of hard breakpoints.
     Caps at the original 22/18 on wide screens, eases down on tablet/phone. */
  --pad: clamp(16px, 1.2vw + 6px, 22px);
  --gap: clamp(12px, 1vw + 5px, 18px);
  --row-h: 56px;

  --sidebar-w: clamp(208px, 18vw, 248px);

  --shadow-card: 0 1px 0 oklch(1 0 0 / 0.025) inset,
                 0 8px 24px -16px oklch(0 0 0 / 0.7);
  --font: "Helvetica Neue", Helvetica, "Inter", system-ui, sans-serif;
}

[data-density="dense"]   { --pad: 16px; --gap: 12px; --row-h: 46px; }
[data-density="spacious"]{ --pad: 30px; --gap: 26px; --row-h: 66px; }

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* every figure aligns + uses tabular numerals */
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

::selection { background: var(--accent-dim); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 99px; border: 3px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--line); }

/* ============================================================
   App shell
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---- sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 14px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), color-mix(in oklab, var(--accent) 70%, oklch(0.5 0.08 30)));
  color: oklch(0.2 0.02 70);
  flex: none;
  box-shadow: 0 2px 10px -4px var(--accent-line);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-name {
  font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.1;
}
.brand-sub {
  font-size: 11px; color: var(--fg-faint); letter-spacing: 0.02em; margin-top: 2px;
}

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }

/* ---- workspace switcher ---- */
.ws { position: relative; margin: 0 0 12px; }
.ws-current { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 9px;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  cursor: pointer; font-family: var(--font); text-align: left; transition: border-color .15s ease; }
.ws-current:hover { border-color: var(--line); }
.ws-swatch { width: 26px; height: 26px; border-radius: 8px; flex: none;
  box-shadow: 0 0 0 1px oklch(1 0 0 / 0.06) inset, 0 2px 8px -3px var(--accent-line); }
.ws-swatch.sm { width: 18px; height: 18px; border-radius: 6px; }
.ws-meta { min-width: 0; flex: 1; }
.ws-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-label { display: block; font-size: 10px; color: var(--fg-faint); text-transform: capitalize; }
.ws-caret { color: var(--fg-faint); display: grid; place-items: center; transition: transform .18s ease; }
.ws-caret svg { transform: rotate(90deg); }
.ws-caret.open { transform: rotate(180deg); }

.ws-pop { position: absolute; z-index: 70; top: calc(100% + 6px); left: 0; min-width: 268px; width: max-content; max-width: 320px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: 0 18px 44px -18px oklch(0 0 0 / 0.8); padding: 6px; }
.ws-list { display: flex; flex-direction: column; gap: 2px; }
.ws-item { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: var(--r-sm);
  cursor: pointer; transition: background .12s ease; }
.ws-item:hover { background: var(--bg-3); }
.ws-item.on { background: var(--bg-3); }
.ws-item-name { font-size: 12.5px; font-weight: 500; color: var(--fg); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-active-dot { color: var(--accent); display: grid; place-items: center; }
.ws-edit { background: transparent; border: 0; color: var(--fg-ghost); cursor: pointer; padding: 4px;
  border-radius: 6px; display: grid; place-items: center; opacity: 0; transition: .12s ease; }
.ws-edit svg { width: 14px; height: 14px; }
.ws-item:hover .ws-edit { opacity: 1; }
.ws-edit:hover { color: var(--fg); background: var(--bg-1); }
.ws-add { display: flex; align-items: center; justify-content: center; gap: 7px; width: 100%; margin-top: 4px;
  padding: 9px; background: transparent; border: 1px dashed var(--line); border-radius: var(--r-sm);
  color: var(--fg-muted); font-family: var(--font); font-size: 12.5px; font-weight: 500; cursor: pointer; transition: .12s ease; }
.ws-add:hover { border-color: var(--accent-line); color: var(--fg); background: var(--accent-dim); }

.ws-form { padding: 4px; display: flex; flex-direction: column; gap: 10px; }
.ws-form-title { font-size: 12px; font-weight: 600; padding: 2px 2px 0; }
.ws-input { height: 38px; }
.ws-form-label { font-size: 11px; color: var(--fg-muted); font-weight: 500; }
.ws-colors { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.ws-cdot { aspect-ratio: 1; border-radius: 7px; border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: 0 0 0 1px var(--line) inset; transition: transform .1s ease; }
.ws-cdot:hover { transform: scale(1.12); }
.ws-cdot.on { border-color: var(--bg-2); box-shadow: 0 0 0 2px var(--fg); }
.ws-preview { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--fg-faint);
  padding: 8px 10px; border-radius: var(--r-sm); background: var(--bg-0); border: 1px solid var(--line-soft); }
.ws-preview-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pc); flex: none;
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--pc) 18%, transparent); }
.ws-form-actions { display: flex; align-items: center; gap: 7px; }
.ws-del { height: 32px; font-size: 12px; color: var(--loss); padding: 0 10px; }
.ws-del:hover { background: var(--loss-dim); }
.ws-form-actions .btn { white-space: nowrap; }
.nav-label {
  font-size: 10.5px; letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--fg-ghost); padding: 8px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 11px; border-radius: var(--r-sm);
  color: var(--fg-muted); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  position: relative;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--bg-2); color: var(--fg); }
.nav-item.active { background: var(--bg-2); color: var(--fg); }
.nav-item.active::before {
  content: ""; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item.active svg { opacity: 1; color: var(--accent); }

.sidebar-spacer { flex: 1; }

/* reserved profile slot (bottom) */
.profile {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color .15s ease;
}
.profile:hover { border-color: var(--line); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 30% 28%, var(--bg-3), oklch(0.32 0.02 70));
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--fg-muted);
  border: 1px solid var(--line);
}
.profile-meta { min-width: 0; flex: 1; }
.profile-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-role { font-size: 10.5px; color: var(--fg-faint); }
.profile .chev { color: var(--fg-faint); }

/* ---- main column ---- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 16px var(--pad);
  background: color-mix(in oklab, var(--bg-0) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line-soft);
}
.topbar > div:first-child { min-width: 0; }   /* let the title/crumb shrink */
.topbar h1 {
  font-size: clamp(17px, 1.4vw + 8px, 19px); font-weight: 600; letter-spacing: -0.02em;
}
.topbar .crumb { font-size: 12.5px; color: var(--fg-faint); margin-top: 1px; }
.topbar-spacer { flex: 1; }

.updated {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--fg-faint);
}
.dot-live {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gain);
  box-shadow: 0 0 0 0 var(--gain);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 oklch(0.78 0.135 158 / 0.5); }
  70% { box-shadow: 0 0 0 6px oklch(0.78 0.135 158 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.78 0.135 158 / 0); }
}

.content {
  padding: var(--pad);
  display: flex; flex-direction: column; gap: var(--gap);
  max-width: 1320px; width: 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .content { animation: viewIn .3s cubic-bezier(.2,.7,.2,1) both; }
}
@keyframes viewIn { from { transform: translateY(9px); } to { transform: none; } }

/* ============================================================
   Buttons / controls
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: var(--line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--accent); color: oklch(0.2 0.02 70); border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { background: oklch(0.84 0.105 82); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--bg-2); color: var(--fg); }
.btn .spin { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* segmented control */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-1); border: 1px solid var(--line-soft);
  border-radius: 9px;
}
.seg button {
  appearance: none; border: 0; background: transparent;
  color: var(--fg-faint); font-family: var(--font);
  font-size: 12px; font-weight: 500; cursor: pointer;
  padding: 6px 11px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s ease, background .15s ease;
}
.seg button svg { width: 14px; height: 14px; }
.seg button:hover { color: var(--fg-muted); }
.seg button.on { background: var(--bg-3); color: var(--fg); }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}
.card-h {
  display: flex; align-items: center; gap: 12px;
  padding: 16px var(--pad) 0;
}
.card-h h2 { font-size: 13.5px; font-weight: 600; letter-spacing: -0.005em; }
.card-h .sub { font-size: 11.5px; color: var(--fg-faint); }
.card-h .spacer { flex: 1; }

/* chips / badges */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
}
.chip.up   { color: var(--gain); background: var(--gain-dim); border-color: oklch(0.78 0.135 158 / 0.25); }
.chip.down { color: var(--loss); background: var(--loss-dim); border-color: oklch(0.69 0.150 27 / 0.25); }
.chip.neutral { color: var(--fg-muted); background: var(--bg-2); border-color: var(--line-soft); }

.up-fg { color: var(--gain); }
.down-fg { color: var(--loss); }

/* coin monogram */
.coin {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: -0.02em;
  color: oklch(0.16 0.01 70);
}
.coin.lg { width: 38px; height: 38px; font-size: 13px; }

/* Grid/flex items default to min-width:auto, which lets wide content (inputs,
   tables, long numbers) push a track past the viewport. Allow them to shrink so
   inner scroll/ellipsis/wrapping kicks in instead of overflowing the page. */
.kpis > *, .dash-grid > *, .analysis-grid > *, .work-grid > *, .detail-grid > *,
.asset-charts-grid > *, .alloc-split > *, .form-row > *, .cl-grid > *,
.metric-grid > *, .side-toggle > *, .im-range > * { min-width: 0; }

/* ============================================================
   Responsive
   ============================================================ */
/* popovers never wider than the viewport (so they don't cause horizontal scroll) */
.ws-pop { max-width: calc(100vw - 24px); }

@media (max-width: 980px) {
  /* sidebar becomes a horizontal top bar; nav scrolls horizontally */
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; height: auto; flex-direction: row; align-items: center;
    padding: 8px 12px; gap: 8px; z-index: 30;
    border-right: 0; border-bottom: 1px solid var(--line-soft);
  }
  .brand { padding: 4px 6px; flex: none; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; flex: 1 1 auto; min-width: 0; margin: 0; overflow-x: auto; gap: 2px; }
  .nav-label { display: none; }
  .nav-item { padding: 8px 12px; }
  .nav-item span { display: none; }
  .nav-item.active::before { left: 0; right: 0; top: auto; bottom: -8px;
    width: auto; height: 2px; transform: none; border-radius: 2px 2px 0 0; }
  .sidebar-spacer { display: none; }
  .profile .profile-meta, .profile .chev { display: none; }
  .profile { padding: 4px; border: 0; background: transparent; flex: none; }

  /* workspace switcher: compact, doesn't stretch the row */
  .ws { margin: 0; flex: none; }
  .ws-current { width: auto; padding: 6px 8px; }
  .ws-label { display: none; }
  .ws-name { max-width: 96px; }

  /* avoid two stacked sticky bars fighting for the top — let the title bar scroll */
  .topbar { position: static; }
}

@media (max-width: 560px) {
  .content { padding: var(--pad); }
  /* reclaim space in the crowded top bar: logo + swatch only */
  .brand-name { display: none; }
  .ws-meta { display: none; }
  .ws-current { gap: 6px; }
}
