:root {
  --bg: #f8f8fa;
  --card: #ffffff;
  --border: #e5e5ea;
  --text: #000000;
  --text-muted: #3a3a3c;
  --text-soft: #8e8e93;
  --gain: #30d158;
  --gain-text: #1f9d45;
  --loss: #ff3b30;
  --warn: #ff9f0a;
  --info: #0a84ff;
  --hover: #f2f2f7;
  --sidebar-w: 232px;
  --radius: 14px;
  --radius-login: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
input {
  font-family: inherit;
}

.logo {
  position: relative;
  display: inline-block;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text);
}

.logo .tm {
  position: absolute;
  top: -0.35em;
  right: -0.95em;
  font-size: 0.42em;
  letter-spacing: 0;
  font-weight: 600;
  color: var(--text-soft);
}

.signin-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-login);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  padding: 36px 32px 28px;
}

.login-card .logo {
  font-size: 28px;
}

.login-kicker {
  margin: 18px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
}

.login-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.login-copy {
  margin: 0 0 24px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-muted);
}

.primary-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
}

.primary-btn:hover {
  opacity: 0.92;
}

.primary-btn[hidden] {
  display: none;
}

.google-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-top: 12px;
}

.login-error {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--loss);
}

.login-error[hidden] {
  display: none;
}

.login-origin {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-soft);
}

.login-origin code {
  font-size: 12px;
  color: var(--text);
}

.text-btn {
  display: block;
  margin: 12px auto 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.text-btn[hidden] {
  display: none;
}

/* ---------- App shell ---------- */

.app-body {
  font-size: 14px;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 0 8px 20px;
}

.brand .logo {
  font-size: 18px;
}

.product {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-group {
  margin: 14px 8px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.nav-group:first-child {
  margin-top: 0;
}

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.nav a:hover {
  background: var(--hover);
}

.nav a.active {
  background: var(--text);
  color: #fff;
}

.nav-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--hover);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-badge.bad {
  background: var(--loss);
  color: #fff;
}

.nav-badge[hidden] {
  display: none;
}

.nav a.active .nav-badge:not(.bad) {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.user-meta {
  min-width: 0;
}

.user-email {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.foot-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.demo-note {
  margin: 8px 4px 0;
  font-size: 11px;
  color: var(--text-soft);
}

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

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-soft);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.as-of {
  font-size: 12px;
  color: var(--text-soft);
}

.view {
  padding: 0 28px 40px;
}

/* ---------- Building blocks ---------- */

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.grid > .card {
  margin-bottom: 0;
}

.grid-main {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-orders {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--info);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.kpi-value {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.kpi-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.seg {
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--hover);
}

.seg button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.seg button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.btn-primary:hover {
  background: #2c2c2e;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
  padding: 10px 12px;
}

.input {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
}

.input:focus {
  outline: 2px solid rgba(10, 132, 255, 0.35);
  border-color: var(--info);
}

.input:disabled {
  background: var(--hover);
  color: var(--text-soft);
}

.input-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.pill-good {
  background: rgba(48, 209, 88, 0.14);
  color: var(--gain-text);
}

.pill-bad {
  background: rgba(255, 59, 48, 0.12);
  color: #d70015;
}

.pill-warn {
  background: rgba(255, 159, 10, 0.16);
  color: #b25000;
}

.pill-info {
  background: rgba(10, 132, 255, 0.12);
  color: #0060c7;
}

.pill-neutral {
  background: var(--hover);
  color: var(--text-muted);
}

.pill-muted {
  background: var(--hover);
  color: var(--text-soft);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.swatch.dashed {
  height: 2px;
  width: 14px;
  border-radius: 0;
}

.pos {
  color: var(--gain-text);
}

.neg {
  color: #d70015;
}

.muted {
  color: var(--text-soft);
}

.small {
  font-size: 12px;
}

.sub {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 400;
}

.empty {
  margin: 8px 0;
  font-size: 13px;
  color: var(--text-soft);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--hover);
  font-size: 12px;
  color: var(--text-muted);
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
}

.chip-btn:hover {
  background: var(--hover);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 9px 8px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-soft);
  white-space: nowrap;
}

.table th.sortable {
  cursor: pointer;
  user-select: none;
}

.table th.sortable:hover {
  color: var(--text);
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tfoot td {
  border-top: 1px solid var(--border);
  border-bottom: 0;
  background: #fbfbfd;
}

.row-link {
  cursor: pointer;
}

.row-link:hover td {
  background: var(--hover);
}

.cell-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.row-actions {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.detail-row td {
  background: #fbfbfd;
  white-space: normal;
}

.detail-row p {
  margin: 0 0 6px;
  line-height: 1.5;
  color: var(--text-muted);
}

.check-inline {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.6;
}

.wbar-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wbar {
  position: relative;
  width: 72px;
  height: 6px;
  border-radius: 3px;
  background: var(--hover);
}

.wbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 3px;
  background: var(--text);
}

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

.wbar-fill.bad {
  background: var(--loss);
}

.wbar-limit,
.bar-limit {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 1.5px;
  background: var(--loss);
  opacity: 0.6;
}

.conv {
  display: inline-block;
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: var(--hover);
  vertical-align: middle;
  overflow: hidden;
}

.conv-fill {
  height: 100%;
  background: var(--info);
}

.conv-label {
  margin-left: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.limit-cell {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.limit-ok {
  background: rgba(48, 209, 88, 0.1);
  color: var(--gain-text);
}

.limit-warn {
  background: rgba(255, 159, 10, 0.14);
  color: #b25000;
}

.limit-bad {
  background: rgba(255, 59, 48, 0.12);
  color: #d70015;
  font-weight: 600;
}

/* ---------- Charts ---------- */

.chart {
  position: relative;
}

.chart svg {
  display: block;
  width: 100%;
  height: 260px;
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-zero {
  stroke: #c7c7cc;
  stroke-width: 1;
}

.chart-axis {
  font-size: 11px;
  fill: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.chart-hover {
  stroke: #c7c7cc;
  stroke-width: 1;
}

.chart-tip {
  position: absolute;
  pointer-events: none;
  min-width: 150px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.chart-tip[hidden] {
  display: none;
}

.tip-date {
  margin-bottom: 4px;
  color: #aeaeb2;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.tip-row strong {
  margin-left: auto;
  padding-left: 12px;
}

.tip-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.alloc {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.donut {
  width: 170px;
  height: 170px;
}

.donut-value {
  font-size: 17px;
  font-weight: 700;
  fill: var(--text);
}

.donut-label {
  font-size: 11px;
  fill: var(--text-soft);
}

.alloc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
}

.alloc-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}

.alloc-list li:hover {
  background: var(--hover);
}

.alloc-name {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-weight: 600;
  font-size: 13px;
}

.alloc-val {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-weight: 600;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.spark {
  display: block;
}

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
}

.bars li {
  display: grid;
  grid-template-columns: minmax(90px, 160px) 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--hover);
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px;
  background: var(--text);
}

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

.bar-fill.bad {
  background: var(--loss);
}

.bar-track.dual {
  height: 12px;
}

.bar-track.dual .bar-fill.before {
  top: 0;
  bottom: 50%;
  background: #c7c7cc;
}

.bar-track.dual .bar-fill.after {
  top: 50%;
  bottom: 0;
  background: var(--info);
}

.bar-track.dual .bar-fill.after.bad {
  background: var(--loss);
}

.bar-val {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}

.mini-row:first-child {
  border-top: 0;
  padding-top: 0;
}

/* ---------- Funds ---------- */

.fund-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.fund-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.fund-card:hover {
  border-color: #c7c7cc;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.fund-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fund-card-head .pill {
  margin-left: auto;
}

.fund-code {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}

.fund-card-name {
  font-size: 16px;
  font-weight: 700;
}

.fund-card-nav {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.fund-card-stats,
.fund-card-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fund-card-foot {
  color: var(--text-soft);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.fund-card .spark {
  width: 100%;
  height: 48px;
  margin: 4px 0;
}

.fund-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.fund-switch a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.fund-switch a.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

/* ---------- Positions ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.toolbar #pos-q {
  width: 220px;
}

.toolbar-spacer {
  flex: 1;
}

/* ---------- AI ---------- */

.ai-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.ai-side {
  position: sticky;
  top: 16px;
}

.preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 13px;
}

.preview-head .btn {
  margin-left: auto;
}

.copilot {
  display: flex;
  flex-direction: column;
}

.chat-log {
  height: 380px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px;
}

.chat-msg {
  max-width: 92%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--hover);
  border-bottom-left-radius: 4px;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--text);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form .input {
  flex: 1;
}

/* ---------- Orders ---------- */

.ticket {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ticket label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}

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

.ticket-info {
  padding: 10px;
  border-radius: 10px;
  background: var(--hover);
  font-size: 13px;
}

.ticket-est {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  font-size: 13px;
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.check-list li {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

.check-dot {
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--gain);
}

.check-warn .check-dot {
  background: var(--warn);
}

.check-fail .check-dot {
  background: var(--loss);
}

/* ---------- Alerts ---------- */

.alert-list-x {
  list-style: none;
  margin: 0;
  padding: 0;
}

.alert-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.alert-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.alert-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #c7c7cc;
}

.sev-warning .alert-dot {
  background: var(--warn);
}

.sev-critical .alert-dot {
  background: var(--loss);
}

.alert-row:not(.unread) .cell-title {
  font-weight: 500;
  color: var(--text-muted);
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  background: rgba(28, 28, 30, 0.95);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 50;
}

.toast-error {
  background: #d70015;
}

.toast[hidden] {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .ai-layout {
    grid-template-columns: 1fr;
  }

  .ai-side {
    position: static;
  }

  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 980px) {
  .grid-main,
  .grid-2,
  .grid-3,
  .grid-orders {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    flex: none;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
  }

  .nav-group {
    display: none;
  }

  .nav a {
    white-space: nowrap;
    gap: 6px;
  }

  .sidebar-foot {
    display: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .view {
    padding: 0 12px 32px;
  }

  .hide-sm {
    display: none;
  }

  .chart svg {
    height: 210px;
  }
}

/* ---------- Live data ---------- */

.span-2 {
  min-width: 0;
}

.card-note {
  margin: 8px 0 0;
  line-height: 1.5;
}

.card-foot {
  display: flex;
  justify-content: center;
  padding-top: 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

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

.bar-fill.good {
  background: var(--gain);
}

.decision-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
}

.decision-text {
  margin: 10px 0 0;
  padding: 12px;
  max-height: 420px;
  overflow: auto;
  border-radius: 10px;
  background: var(--hover);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline-item {
  border-top: 1px solid var(--border);
  padding: 8px 0;
}

.timeline-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.timeline-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.timeline-sum {
  flex-basis: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.banner {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
}

.banner-warn {
  background: rgba(255, 159, 10, 0.14);
  color: #b25000;
}

.n8n-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  margin-top: 8px;
}

.n8n {
  position: relative;
  margin-top: 12px;
  border-radius: 14px;
  background-color: #f3f3f6;
  background-image: radial-gradient(#c7c7cc 1.1px, transparent 1.1px);
  background-size: 18px 18px;
  overflow: visible;
}

.n8n-wires {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.wire {
  fill: none;
  stroke: #8e8e93;
  stroke-width: 1.6;
}

.wire-hot {
  stroke: #000;
  stroke-width: 2.2;
}

.n8n-node {
  position: absolute;
  width: 176px;
  height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  text-align: left;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

.n8n-node.active {
  border-color: #000;
  box-shadow: 0 0 0 1px #000;
}

.n8n-node.flow-missing,
.n8n-node.flow-skipped {
  border-style: dashed;
  opacity: 0.72;
}

.n8n-port {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #8e8e93;
  top: 31px;
}

.n8n-port.in { left: -6px; }
.n8n-port.out { right: -6px; }

.flow {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  max-width: 640px;
  margin-top: 12px;
}

.flow-step {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.flow-step.active {
  border-color: var(--text);
}

.flow-step.flow-skipped,
.flow-step.flow-missing {
  opacity: 0.55;
}

.flow-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.flow-arrow {
  width: 2px;
  height: 14px;
  margin-left: 22px;
  background: var(--border);
}

.flow-label {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}
