/* Invaris Brokerage — foundation layer.
 *
 * ORIGIN: adapted from coherence/apps/coherence-ui/public/styles.css.
 * Token values, shell grid, rail geometry, and component metrics are carried
 * over verbatim so the brokerage inherits Coherence's actual visual language
 * rather than an approximation of it. Coherence itself is never modified.
 *
 * What was deliberately NOT copied: the chat product's surfaces (message
 * stream, composer, repair review, settings panels). That is ~100 KB of
 * selectors for workflows this app does not have. Copying them wholesale is
 * the "over-copying" failure the adaptation plan warns about.
 *
 * Naming: Coherence's class names are retained where the element plays the
 * same structural role (.top-rail, .workspace, .list-item), because matching
 * names is what lets a change in either app be read across both.
 */

/* ---- tokens (verbatim from Coherence's refined :root layer) ------------- */

:root {
  color-scheme: dark;

  --page: #000000;
  --rail: #030508;
  --panel: #0d1118;
  --panel-soft: #070a10;
  --line: rgba(224, 232, 242, 0.075);
  --line-strong: rgba(171, 186, 205, 0.30);
  --text: #f0f4fa;
  --muted: #aeb8c6;
  --dim: #667181;
  --accent: #d7dee8;

  --electric-blue: #74a9ff;
  --electric-blue-soft: rgba(116, 169, 255, 0.12);
  --electric-blue-line: rgba(116, 169, 255, 0.46);
  --electric-green: #8deaa5;
  --electric-green-soft: rgba(141, 234, 165, 0.10);
  --electric-green-line: rgba(141, 234, 165, 0.42);
  --danger: #f28799;
  --danger-soft: rgba(242, 135, 153, 0.12);
  --danger-line: rgba(242, 135, 153, 0.42);
  --amber: #f5c15d;
  --amber-soft: rgba(245, 193, 93, 0.12);

  --shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

/* Environment theming (FR-UI-06). The distinction is a token override rather
 * than a badge, so PAPER and LIVE differ everywhere at once — a live session
 * cannot end up looking like paper because one component forgot to check. */
:root[data-environment="paper"] {
  --env: var(--electric-blue);
  --env-soft: var(--electric-blue-soft);
  --env-line: var(--electric-blue-line);
  --env-label: "PAPER";
}

:root[data-environment="live"] {
  --env: var(--amber);
  --env-soft: var(--amber-soft);
  --env-line: rgba(245, 193, 93, 0.5);
  --env-label: "LIVE";
}

/* ---- reset + base ------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  background-clip: content-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* top rail, environment strip, workspace */
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

/* `display: grid` on a component beats the [hidden] attribute, which silently
 * leaves hidden surfaces occupying a grid column. Restore the attribute's
 * meaning globally rather than per-component. */
[hidden] {
  display: none !important;
}

.top-rail {
  position: relative;
  z-index: 200;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 9px 18px 9px 22px;
  background: rgba(0, 0, 0, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(18px);
}

.top-rail-left,
.top-rail-right {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-lockup img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  opacity: 0.92;
}

.brand-lockup strong {
  color: #eef4ff;
  font-size: 14px;
  font-weight: 780;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-lockup span {
  color: var(--dim);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.surface-pill {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
}

.surface-pill-button {
  min-height: 30px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  letter-spacing: 0.01em;
}

.surface-pill-button.active {
  background: #f3f6fb;
  color: #050608;
}

.workspace {
  --left-rail-width: 250px;
  --right-rail-width: 300px;
  display: grid;
  grid-template-columns: var(--left-rail-width) minmax(0, 1fr) var(--right-rail-width);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.workspace.left-collapsed {
  --left-rail-width: 36px;
}

.workspace.right-collapsed {
  --right-rail-width: 36px;
}

.nav-rail,
.side-rail,
.surface {
  min-width: 0;
  min-height: 0;
  background: rgba(0, 0, 0, 0.68);
}

.nav-rail {
  display: grid;
  align-content: start;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow: hidden;
}

/* Managed Strategies rail: three equal thirds, each scrolling independently
 * so a long conversation list never buries the executions or the strategy
 * library below it. */
.nav-rail.thirds {
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0;
}

.rail-third {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  padding-bottom: 10px;
  overflow: hidden;
}

.rail-third + .rail-third {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.top-rail-center {
  display: flex;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

/* Replaces the navigation menu: says where you are, does not offer tabs. */
.context-line {
  color: var(--dim);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-line strong {
  color: var(--muted);
  font-weight: 780;
}

.rail-hint {
  color: var(--dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.side-rail {
  display: grid;
  align-content: start;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  border-left: 1px solid var(--line);
  padding: 14px;
  overflow: hidden;
}

.surface {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.surface-body {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px 28px;
}

.rail-titlebar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.rail-scroll {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 16px;
}

/* ---- components -------------------------------------------------------- */

.rail-section {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.rail-section > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 22px;
  color: var(--electric-blue);
  cursor: pointer;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.04em;
  list-style: none;
}

.rail-section > summary::-webkit-details-marker {
  display: none;
}

.rail-section > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--electric-blue);
  transform: rotate(90deg);
  transition: transform 120ms ease;
}

.rail-section:not([open]) > summary::before {
  transform: rotate(0deg);
}

.item-list {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 2px;
  min-height: 0;
  padding: 2px 0;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 0 6px 0 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-align: left;
}

.list-item:hover,
.list-item.active {
  background: rgba(255, 255, 255, 0.075);
  color: var(--text);
}

.list-item .meta {
  color: var(--dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.text-action {
  min-height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
  line-height: 1.2;
}

.text-action:hover {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.card-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.stat {
  display: grid;
  gap: 4px;
}

.stat-label {
  color: var(--dim);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat-value {
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-value.small {
  font-size: 15px;
}

.pos {
  color: var(--electric-green);
}

.neg {
  color: var(--danger);
}

.btn {
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 780;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn.primary {
  border-color: transparent;
  background: #f3f6fb;
  color: #050608;
}

.btn.danger {
  border-color: var(--danger-line);
  color: var(--danger);
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badge.ok {
  border-color: var(--electric-green-line);
  background: var(--electric-green-soft);
  color: var(--electric-green);
}

.badge.warn {
  border-color: rgba(245, 193, 93, 0.5);
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.bad {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.info {
  border-color: var(--electric-blue-line);
  background: var(--electric-blue-soft);
  color: var(--electric-blue);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--page);
  color: var(--dim);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
}

table.data td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

table.data tr:hover td {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

table.data td.num {
  text-align: right;
}

table.data .sym {
  color: var(--text);
  font-weight: 760;
}

.mono {
  font-family: var(--mono);
  font-size: 11px;
}

.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
}

.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.surface-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 780;
  letter-spacing: 0;
}

.surface-header p {
  margin: 3px 0 0;
  color: var(--dim);
  font-size: 11px;
}

/* ---- responsive --------------------------------------------------------
 * Placed last on purpose: these override the base rail rules above, and an
 * equal-specificity media query declared earlier in the file loses the
 * cascade — which is exactly how the rails kept rendering at 529px.
 *
 * The conversation is the product, so it is what survives a narrow viewport.
 * Rails drop away rather than squeezing the centre to nothing.
 */

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: var(--left-rail-width) minmax(0, 1fr);
  }

  .side-rail {
    display: none;
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .nav-rail {
    display: none;
  }

  .top-rail-center {
    display: none;
  }
}
