/* =========================================================
   QUBE — design tokens & shared system
   Calm, instrument-panel aesthetic. Flat surfaces, hairline
   borders, amber signal colour reserved for confidence/alpha,
   cyan reserved for AI-origin data, green/red reserved for P&L.
   ========================================================= */

:root {
  /* colour */
  --bg: #0a0c10;
  --surface: #12151c;
  --surface-2: #181c25;
  --surface-3: #1d222c;
  --border: #232833;
  --border-strong: #2a3040;
  --text: #edeff3;
  --text-dim: #8b92a5;
  --text-faint: #565d6d;

  --amber: #ff9f0a;
  --amber-dim: rgba(255, 159, 10, 0.14);
  --amber-strong: #ffb74a;

  --cyan: #4fd1e8;
  --cyan-dim: rgba(79, 209, 232, 0.14);

  --positive: #1fcb8f;
  --positive-dim: rgba(31, 203, 143, 0.14);
  --negative: #ff5c5c;
  --negative-dim: rgba(255, 92, 92, 0.14);

  /* type */
  --font: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* geometry */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 14px;
  --nav-h: 64px;
  --topbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.02) inset;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: var(--font);
  color: inherit;
}

button {
  cursor: pointer;
}

::selection {
  background: var(--amber-dim);
  color: var(--amber-strong);
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* tabular numerals for anything financial */
.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* uppercase data / eyebrow label — one of the two type "roles"
   layered on DM Sans: wide tracking reads as instrument-panel text */
.label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--amber);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
  color: var(--text-dim);
}

/* =========================================================
   App shell
   ========================================================= */

.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 8px;
  background: rgba(10, 12, 16, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  flex: none;
}

.brand-word {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.brand-word small {
  display: block;
  font-weight: 500;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  margin-top: -2px;
}

.session-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
}

.session-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-dim);
}

.session-pill.paused .dot {
  background: var(--text-faint);
  box-shadow: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text-dim);
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 28px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.page-head {
  margin: 4px 0 18px;
}

.page-head h1 {
  font-size: 22px;
}

.page-head p {
  margin-top: 4px;
  font-size: 13.5px;
}

/* bottom tab bar */
.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(10, 12, 16, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  position: relative;
}

.bottomnav svg {
  width: 21px;
  height: 21px;
}

.bottomnav a.active {
  color: var(--amber);
}

.bottomnav a.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 2px;
  background: var(--amber);
  border-radius: 2px;
}

/* =========================================================
   Cards & layout primitives
   ========================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.card + .card {
  margin-top: 12px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 14.5px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: 14px 0;
}

/* stat block */
.stat .label {
  margin-bottom: 4px;
}

.stat .value {
  font-size: 20px;
  font-weight: 700;
}

.stat .value.positive {
  color: var(--positive);
}

.stat .value.negative {
  color: var(--negative);
}

/* delta chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.chip.positive {
  color: var(--positive);
  background: var(--positive-dim);
}

.chip.negative {
  color: var(--negative);
  background: var(--negative-dim);
}

.chip.neutral {
  color: var(--text-dim);
  background: var(--surface-2);
}

.chip.amber {
  color: var(--amber);
  background: var(--amber-dim);
}

.chip.cyan {
  color: var(--cyan);
  background: var(--cyan-dim);
}

/* status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.badge .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge.running {
  color: var(--positive);
  border-color: rgba(31, 203, 143, 0.3);
}

.badge.paused {
  color: var(--text-dim);
}

.badge.flat {
  color: var(--amber);
  border-color: rgba(255, 159, 10, 0.3);
}

/* =========================================================
   Buttons & forms
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  width: 100%;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--amber);
  color: #16110a;
}

.btn.primary:hover {
  background: var(--amber-strong);
}

.btn.secondary {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn.secondary:hover {
  background: var(--surface-3);
}

.btn.ghost {
  background: none;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn.danger {
  background: var(--negative-dim);
  color: var(--negative);
  border-color: rgba(255, 92, 92, 0.3);
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.btn.small {
  height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
  width: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 14px;
  color: var(--text);
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 84px;
  font-family: var(--font);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

/* toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex: none;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.switch .track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch input:checked + .track {
  background: var(--amber-dim);
  border-color: rgba(255, 159, 10, 0.4);
}

.switch input:checked + .track::before {
  transform: translateX(18px);
  background: var(--amber);
}

/* segmented control */
.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.segmented button {
  flex: 1;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 8px 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
}

.segmented button.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* =========================================================
   Execution stream / log rows
   ========================================================= */

.log-row {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.log-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.log-row .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 5px;
  flex: none;
  background: var(--text-faint);
}

.log-row.buy .dot {
  background: var(--positive);
}

.log-row.sell .dot {
  background: var(--negative);
}

.log-row.ai .dot {
  background: var(--cyan);
}

.log-row .msg {
  flex: 1;
  color: var(--text);
}

.log-row .ts {
  color: var(--text-faint);
  font-size: 11px;
  flex: none;
}

/* =========================================================
   Radial gauge (Alpha Confidence Meter)
   ========================================================= */

.gauge {
  position: relative;
  display: grid;
  place-items: center;
}

.gauge svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.gauge .track {
  fill: none;
  stroke: var(--surface-3);
}

.gauge .arc {
  fill: none;
  stroke: var(--amber);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.gauge .center {
  position: absolute;
  text-align: center;
}

.gauge .center .pct {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.gauge .center .lbl {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* horizontal risk meter */
.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  position: relative;
}

.meter .fill {
  height: 100%;
  border-radius: 999px;
  background: var(--positive);
  transition: width 0.5s ease;
}

.meter.warn .fill {
  background: var(--amber);
}

.meter.danger .fill {
  background: var(--negative);
}

/* =========================================================
   AI chat / forge
   ========================================================= */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}

.bubble.user {
  align-self: flex-end;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-right-radius: 3px;
}

.bubble.ai {
  align-self: flex-start;
  background: var(--cyan-dim);
  border: 1px solid rgba(79, 209, 232, 0.25);
  border-bottom-left-radius: 3px;
}

.bubble.ai .eyebrow {
  color: var(--cyan);
  display: block;
  margin-bottom: 5px;
}

.bubble pre {
  white-space: pre-wrap;
  margin: 0;
  font-family: var(--font);
}

.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}

.thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  animation: pulse 1.1s ease-in-out infinite;
}

.thinking span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* skeleton shimmer */
.skel {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* code block — the one deliberate departure from DM Sans, reserved for
   literal API payloads in the Developer API Studio */
.code {
  background: #0d1017;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #c3e88d;
  overflow-x: auto;
  white-space: pre;
}

.code .k {
  color: #82aaff;
}
.code .s {
  color: #c3e88d;
}
.code .c {
  color: var(--text-faint);
}

/* forge canvas blocks */
.fb-block {
  position: relative;
  padding-left: 22px;
}

.fb-block::before {
  content: "";
  position: absolute;
  left: 5px;
  top: -12px;
  width: 1px;
  height: 12px;
  background: var(--border-strong);
}

.fb-block:first-child::before {
  display: none;
}

.fb-node {
  position: absolute;
  left: 0;
  top: 14px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg);
}

.hint-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.hint-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11.5px;
}

.hint-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

/* =========================================================
   Toast
   ========================================================= */

.toast-wrap {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* install banner */
.install-sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 70;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-pop);
  transform: translateY(140%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.install-sheet.show {
  transform: translateY(0);
}

.install-sheet img {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex: none;
}

.install-sheet .copy {
  flex: 1;
}

.install-sheet .copy .t {
  font-weight: 700;
  font-size: 13px;
}

.install-sheet .copy .d {
  font-size: 11.5px;
  color: var(--text-dim);
}

/* =========================================================
   Empty state
   ========================================================= */

.empty {
  text-align: center;
  padding: 30px 16px;
  color: var(--text-dim);
}

.empty .eyebrow {
  display: block;
  margin-bottom: 6px;
}

/* =========================================================
   Utility
   ========================================================= */

.mt-4 {
  margin-top: 4px;
}
.mt-8 {
  margin-top: 8px;
}
.mt-12 {
  margin-top: 12px;
}
.text-dim {
  color: var(--text-dim);
}
.text-faint {
  color: var(--text-faint);
}
.center-x {
  display: flex;
  justify-content: center;
}
.hidden {
  display: none !important;
}

/* faint cube-lattice watermark used sparingly behind the topbar */
.lattice-bg {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  pointer-events: none;
  background-image: linear-gradient(30deg, var(--border-strong) 1px, transparent 1px),
    linear-gradient(150deg, var(--border-strong) 1px, transparent 1px);
  background-size: 22px 38px;
  mask-image: linear-gradient(to bottom, black, transparent);
}

/* =========================================================
   Breakpoints — progressive enhancement, bottom nav persists
   ========================================================= */

@media (min-width: 560px) {
  .grid-2-sm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}

@media (min-width: 720px) {
  main {
    max-width: 780px;
    padding-left: 24px;
    padding-right: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* =========================================================
   Auth guard (js/auth.js) — hides the page until
   php/session_check.php confirms a session, or redirects.
   ========================================================= */

.qube-auth-pending,
.qube-auth-pending body {
  visibility: hidden;
}

/* =========================================================
   Login screen
   ========================================================= */

.auth-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-b));
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand img {
  border-radius: var(--radius);
  flex: none;
}

.auth-demo-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.auth-demo-note code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  font-family: var(--font);
}

.auth-error {
  min-height: 16px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--negative);
}

/* =========================================================
   Account card (Settings page)
   ========================================================= */

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.account-identity .name {
  font-size: 14px;
  font-weight: 700;
}
