/*
 * Trader space: the frame (side navigation, top bar, tabs on a phone), the page heading and the overview strip.
 * Same family as the terminal and the brand site: bluish graphite, the brand accent, green and red only for direction,
 * amber at the limits. Colours, radii and motion are the tokens of ../style.css; nothing is hard-coded here.
 * Hover effects live under (hover: hover) so that a first tap on a phone is never swallowed.
 */
.page-space {
  background:
    radial-gradient(1100px 520px at 12% -12%, color-mix(in srgb, var(--acc) 11%, transparent), transparent 70%) no-repeat,
    radial-gradient(700px 360px at 100% 0%, color-mix(in srgb, var(--up) 5%, transparent), transparent 70%) no-repeat,
    linear-gradient(transparent 0 calc(100% - 1px), rgb(255 255 255 / 0.018) calc(100% - 1px)) 0 0 / 100% 56px,
    linear-gradient(90deg, transparent 0 calc(100% - 1px), rgb(255 255 255 / 0.018) calc(100% - 1px)) 0 0 / 56px 100%,
    var(--bg);
  background-attachment: fixed;
}
.sp-frame { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }

/* ---------- side navigation ---------- */
.sp-side {
  position: sticky; top: 0; z-index: 50; height: 100vh; display: flex; flex-direction: column; gap: 26px;
  padding: 22px 14px 18px; background: linear-gradient(180deg, var(--bg-2), color-mix(in srgb, var(--bg) 92%, transparent));
  border-right: 1px solid var(--line);
}
.sp-side::after {
  content: ""; position: absolute; top: 0; right: -1px; bottom: 0; width: 1px; pointer-events: none;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--acc) 60%, transparent) 28%, transparent 66%); opacity: 0.55;
}
.sp-brand { padding: 2px 10px; font-size: 15px; }
.sp-nav { display: grid; gap: 2px; }
.sp-link {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px;
  color: var(--mute); font-size: 13.5px; font-weight: 600; text-decoration: none; border-radius: var(--r-sm);
  transition: color var(--t-fast), background-color var(--t-fast);
}
.sp-link[aria-current="page"] { color: var(--text); background: var(--acc-soft); }
.sp-link[aria-current="page"] .sp-icon { color: var(--acc); }
.sp-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--acc); box-shadow: 0 0 14px var(--acc);
}
.sp-side-foot { margin-top: auto; }
.sp-terminal {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--text); text-decoration: none;
  background: linear-gradient(155deg, var(--surface-3), var(--surface)); border: 1px solid var(--line-2); border-radius: var(--r);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05); transition: border-color var(--t-fast), box-shadow var(--t);
}
.sp-terminal[data-enabled="true"] { border-color: color-mix(in srgb, var(--acc) 48%, var(--line-2)); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05), 0 14px 30px -22px var(--acc); }
.sp-terminal[data-enabled="true"] .sp-icon:first-child { color: var(--acc); }
.sp-terminal[aria-disabled="true"] { color: var(--mute); cursor: not-allowed; background: var(--surface); }
.sp-terminal-text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.sp-terminal-text b { font-size: 13.5px; font-weight: 650; }
.sp-terminal-text small { font-size: 11.5px; color: var(--mute); line-height: 1.35; }

/* ---------- top bar ---------- */
.sp-col { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.sp-top {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px; min-height: 58px;
  padding: 10px 32px; background: color-mix(in srgb, var(--bg) 76%, transparent);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.sp-brand-m { display: none; }
.sp-who { display: flex; align-items: center; gap: 9px; min-width: 0; color: var(--mute); font-size: 12px; }
.sp-who .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-who-dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--up); box-shadow: 0 0 10px var(--up); }
.sp-who-tag { flex: 0 0 auto; padding: 2px 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--warn); background: var(--warn-soft); border-radius: var(--r-pill); }
.sp-top-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#spTermTop { display: none; }

/* ---------- content ---------- */
.sp-main { flex: 1; width: 100%; max-width: 1220px; margin: 0 auto; padding: 32px 32px 44px; display: grid; gap: 30px; align-content: start; }
.sp-main:focus { outline: none; }
.sp-main > * { animation: sp-rise 420ms var(--ease) both; }
.sp-main > :nth-child(2) { animation-delay: 60ms; }
.sp-main > :nth-child(3) { animation-delay: 110ms; }
.sp-main > :nth-child(n+4) { animation-delay: 150ms; }
@keyframes sp-rise { from { opacity: 0; transform: translateY(10px); } }
.sp-foot { max-width: 1220px; width: 100%; margin: 0 auto; padding: 0 32px 24px; }

.sp-pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 28px; }
.sp-pagehead .eyebrow { color: var(--acc); margin-bottom: 8px; }
.sp-pagehead h1 { font-size: clamp(27px, 1.35rem + 1.1vw, 36px); font-weight: 700; line-height: 1.08; letter-spacing: -0.028em; color: var(--text); }
.sp-lead { max-width: 64ch; margin-top: 10px; font-size: 14px; line-height: 1.55; color: var(--mute); }
.sp-pagehead-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sp-h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.005em; color: var(--text); }
.sp-h3 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.012em; color: var(--text); }
.sp-section { display: grid; gap: 14px; }
.sp-sec-head { display: flex; align-items: baseline; gap: 10px; }
.sp-count { padding: 1px 8px; font-size: 11px; font-weight: 650; color: var(--mute); background: var(--surface-3); border-radius: var(--r-pill); }
.sp-none { padding: 18px 20px; color: var(--mute); border: 1px dashed var(--line-2); border-radius: var(--r-lg); font-size: 13px; }

.sp-back {
  display: inline-flex; align-items: center; gap: 8px; justify-self: start; min-height: 32px; padding: 0 4px;
  color: var(--mute); font-size: 12.5px; font-weight: 600; text-decoration: none; border-radius: var(--r-sm);
  transition: color var(--t-fast);
}

/* ---------- overview strip ---------- */
.sp-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; overflow: hidden;
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.045), 0 24px 48px -36px rgb(0 0 0 / 0.9);
}
.sp-stat { min-width: 0; padding: 17px 20px 16px; border-left: 1px solid var(--line); }
.sp-stat:first-child { border-left: 0; }
.sp-stat-label { font-size: 10.5px; font-weight: 650; letter-spacing: 0.09em; text-transform: uppercase; color: var(--dim); }
.sp-stat-value { margin: 7px 0 0; font-size: 23px; font-weight: 650; line-height: 1.15; overflow-wrap: anywhere; }
.sp-stat-value[data-tone="up"] { color: var(--up); }
.sp-stat-value[data-tone="down"] { color: var(--down); }
.sp-stat-value[data-status="tight"] { color: var(--warn); }
.sp-stat-value[data-status="critical"], .sp-stat-value[data-status="touched"] { color: var(--down); }
.sp-stat-sub { margin: 5px 0 0; font-size: 11.5px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- empty state ---------- */
.sp-empty {
  display: grid; justify-items: start; gap: 12px; padding: 34px clamp(20px, 5vw, 48px);
  background:
    radial-gradient(520px 220px at 100% 0%, color-mix(in srgb, var(--acc) 14%, transparent), transparent 70%),
    linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
}
.sp-empty .sp-h2 { font-size: 22px; letter-spacing: -0.02em; }

@media (hover: hover) {
  .sp-link:hover { color: var(--text); background: var(--surface-2); }
  .sp-back:hover { color: var(--text); }
  .sp-terminal[data-enabled="true"]:hover { border-color: var(--acc); }
}
.sp-link:active, .sp-terminal:active { transform: translateY(1px); }

/* ---------- phones and tablets: tabs at the bottom, terminal link in the top bar ---------- */
.sp-tabs { display: none; }
@media (max-width: 899px) {
  .sp-frame { grid-template-columns: minmax(0, 1fr); }
  .sp-side, .sp-who, .sp-logout { display: none; }
  .sp-brand-m { display: inline-flex; }
  #spTermTop { display: block; }
  .sp-top { padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
  .sp-main { padding: 22px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); gap: 24px; }
  .sp-foot { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
  .sp-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg-2) 94%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line-2);
  }
  .sp-tab {
    position: relative; display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 54px; padding: 6px 2px;
    color: var(--mute); font-size: 10.5px; font-weight: 600; text-decoration: none; border-radius: var(--r-sm); min-width: 0;
  }
  .sp-tab[aria-current="page"] { color: var(--text); }
  .sp-tab[aria-current="page"] .sp-icon { color: var(--acc); }
  .sp-tab[aria-current="page"]::before { content: ""; position: absolute; top: -7px; left: 26%; right: 26%; height: 2px; border-radius: 2px; background: var(--acc); box-shadow: 0 0 12px var(--acc); }
  .sp-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sp-stat:nth-child(odd) { border-left: 0; }
  .sp-stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 420px) {
  .sp-top { gap: 8px; }
  .sp-top .lang button { padding: 0 8px; }
  .sp-stat { padding: 14px 14px 13px; }
  .sp-stat-value { font-size: 19px; }
}
