/* "The Instrument" — Swiss-grid portfolio dashboard.
   Tokens, components, and layout ported from direction-3-instrument.jsx. */

:root {
  --paper: #f6f5f1;
  --paper-2: #edece6;
  --rule: #dcdbd3;
  --rule-2: #c9c7bc;
  --ink: #14140f;
  --ink-2: #5a584e;
  --ink-3: #8a887b;
  --accent: #c43d1f;
  --up: #2f6b3c;
  --down: #a8361e;
  --mono: "JetBrains Mono", "SF Mono", Menlo, ui-monospace, monospace;
  --sans: "Inter Tight", "Neue Haas Grotesk", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; background: var(--paper); }

.in-root {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  padding: 24px 32px 48px;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum", "ss01";
  font-size: 14px;
  line-height: 1.4;
}
.in-root .up { color: var(--up); }
.in-root .down { color: var(--down); }
.in-root .muted { color: var(--ink-3); }

/* Head */
.in-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 24px;
}
.in-head-l { display: flex; align-items: center; gap: 16px; }
.in-mark {
  width: 28px; height: 28px; border: 1.5px solid var(--ink);
  display: grid; place-items: center; border-radius: 2px;
}
.in-mark-dot { width: 10px; height: 10px; background: var(--accent); border-radius: 50%; }
.in-head-title {
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  letter-spacing: 0.02em;
}
.in-head-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 0.02em; margin-top: 2px; }
.in-head-r { display: flex; align-items: center; gap: 24px; }
.in-head-kpi { text-align: right; }
.in-head-kpi span {
  display: block; font-size: 10px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--ink-3);
}
.in-head-kpi strong { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }

.in-btn-primary {
  background: var(--ink); color: var(--paper);
  border: none; padding: 10px 18px; border-radius: 2px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer; transition: background 200ms;
}
.in-btn-primary:hover { background: #000; }
.in-btn-primary.sell { background: var(--down); }
.in-btn {
  background: var(--paper-2); color: var(--ink);
  border: 1px solid var(--rule-2); padding: 10px 18px; border-radius: 2px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
}
.in-btn:hover { background: var(--rule); }
.in-btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.in-btn.ghost:hover { background: var(--paper-2); }

/* Rail */
.in-rail {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: 0;
  border: 1px solid var(--rule);
  margin-bottom: 24px;
  background: var(--paper);
}
.in-metric {
  padding: 14px 16px;
  border-right: 1px solid var(--rule);
}
.in-metric:last-child { border-right: none; }
.in-metric-l {
  font-size: 10px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-3);
  margin-bottom: 8px;
}
.in-metric-v {
  font-size: 22px; font-weight: 500; letter-spacing: -0.015em;
  font-feature-settings: "tnum";
}
.in-metric-s { font-family: var(--mono); font-size: 11px; margin-top: 2px; }
.in-metric.muted .in-metric-s { color: var(--ink-3); }

/* Tabs */
.in-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 24px;
}
.in-tabs button {
  background: none; border: none; padding: 10px 20px 12px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.in-tabs button:hover { color: var(--ink-2); }
.in-tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* Body */
.in-body { display: flex; flex-direction: column; gap: 24px; }
.in-grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; }
.in-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.in-grid-order { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

.in-card {
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 20px 20px 18px;
}
.in-card.mini { padding: 16px 20px; }
.in-card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}
.in-card-title {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  font-weight: 600; color: var(--ink);
}
.in-card-sub {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
}
.in-mini-l {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 8px;
}
.in-mini-v { font-size: 26px; font-weight: 500; letter-spacing: -0.015em; }

/* Chart */
.in-chart-wrap { position: relative; }
.in-chart-wrap.big { padding: 8px 0; }
.in-chart { width: 100%; height: 160px; color: var(--ink); display: block; }
.in-chart-wrap.big .in-chart { height: 220px; }
.in-chart-ticks {
  position: absolute; top: 0; right: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  height: 100%; padding: 4px 0;
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  pointer-events: none;
}
.in-chart-legend {
  display: flex; gap: 20px; margin-top: 8px;
  font-size: 11px; color: var(--ink-2);
}
.in-chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.in-chart-legend i { width: 16px; height: 1.5px; display: inline-block; }

/* Alloc */
.in-alloc { display: flex; flex-direction: column; gap: 6px; }
.in-alloc-row {
  display: grid; grid-template-columns: 60px 1fr 50px;
  align-items: center; gap: 12px;
  cursor: pointer; padding: 4px 0;
}
.in-alloc-row:hover .in-alloc-sym { text-decoration: underline; }
.in-alloc-sym { font-family: var(--mono); font-size: 11px; font-weight: 600; }
.in-alloc-bar { height: 8px; background: var(--paper-2); position: relative; }
.in-alloc-bar > span {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--ink);
}
.in-alloc-pct {
  font-family: var(--mono); font-size: 11px; text-align: right; color: var(--ink-2);
}

/* Table */
.in-table { width: 100%; border-collapse: collapse; }
.in-table th, .in-table td {
  padding: 10px 8px; text-align: right;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
.in-table th {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-3); cursor: pointer;
  user-select: none;
}
.in-table th:hover { color: var(--ink); }
.in-table th.sorted { color: var(--ink); }
.in-table th .sort-ind { display: inline-block; width: 10px; color: var(--accent); margin-left: 2px; }
.in-table th.l, .in-table td.l { text-align: left; }
.in-table td.sym { font-family: var(--mono); font-weight: 600; font-size: 12px; }
.in-table td.name { color: var(--ink-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.in-table td { font-family: var(--mono); font-size: 12px; font-feature-settings: "tnum"; }
.in-table tr { cursor: pointer; transition: background 150ms; }
.in-table tbody tr:hover { background: var(--paper-2); }
.in-table tbody tr.sel { background: rgba(196, 61, 31, 0.06); }

.in-barcell {
  position: relative; display: flex; justify-content: flex-end; align-items: center;
  font-family: var(--mono); font-size: 11px; padding-right: 2px;
}
.in-barcell > span {
  position: absolute; right: 0; top: 50%;
  height: 4px; transform: translateY(-50%);
  background: var(--ink); opacity: 0.15;
}
.in-barcell em { font-style: normal; position: relative; z-index: 1; }

/* Expiry */
.in-expiry { display: flex; flex-direction: column; gap: 6px; }
.in-expiry-group {
  display: grid;
  grid-template-columns: 120px 80px 1fr 120px 100px;
  align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.in-expiry-group.urgent { background: rgba(255, 179, 35, 0.06); margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
.in-expiry-group.dangerous { background: rgba(196, 61, 31, 0.06); }
.in-expiry-date { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.in-expiry-dte { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.in-expiry-group.dangerous .in-expiry-dte { color: var(--down); font-weight: 600; }
.in-expiry-bar { height: 6px; background: var(--paper-2); position: relative; }
.in-expiry-bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ink); }
.in-expiry-group.dangerous .in-expiry-bar > span { background: var(--down); }
.in-expiry-notional { font-family: var(--mono); font-size: 12px; text-align: right; }
.in-expiry-contracts { font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-align: right; }
.in-expiry-list {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--rule);
  font-family: var(--mono); font-size: 11px;
}
.in-expiry-item {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 4px 8px; background: var(--paper-2); border-radius: 2px;
}
.in-expiry-item-sym { font-weight: 600; }
.in-expiry-item-pc { color: var(--ink-3); }
.in-expiry-item-strike { color: var(--ink-2); }
.in-expiry-item-qty { color: var(--down); font-weight: 500; }

/* Dialog */
.in-dialog-back {
  position: fixed; inset: 0;
  background: rgba(20, 20, 15, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: inFade 200ms;
}
@keyframes inFade { from { opacity: 0; } }
.in-dialog {
  background: var(--paper);
  width: min(640px, calc(100% - 48px));
  padding: 28px 32px;
  border: 1px solid var(--rule-2);
  position: relative;
  animation: inPop 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes inPop { from { transform: scale(0.98); opacity: 0; } }
.in-dialog-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; font-size: 20px; cursor: pointer;
  width: 28px; height: 28px; color: var(--ink-3);
}
.in-dialog-close:hover { color: var(--ink); }
.in-dialog-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding-bottom: 16px; margin-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}
.in-dialog-eye { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); }
.in-dialog-sym { font-family: var(--mono); font-size: 26px; font-weight: 600; margin: 4px 0; letter-spacing: -0.01em; }
.in-dialog-name { font-size: 13px; color: var(--ink-2); }
.in-dialog-price { text-align: right; }
.in-dialog-last { font-size: 28px; font-weight: 500; letter-spacing: -0.015em; font-feature-settings: "tnum"; }
.in-dialog-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px 20px; margin-bottom: 24px;
}
.in-dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.in-kv { display: flex; flex-direction: column; gap: 4px; }
.in-kv-l { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); }
.in-kv-v { font-family: var(--mono); font-size: 14px; font-weight: 500; }

/* Order ticket */
.in-field {
  display: flex; flex-direction: column; margin-bottom: 14px;
}
.in-field label {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 6px;
}
.in-field input {
  background: var(--paper-2); border: 1px solid var(--rule);
  padding: 10px 12px; border-radius: 2px;
  font-family: var(--mono); font-size: 14px; color: var(--ink);
  outline: none;
}
.in-field input:focus { border-color: var(--ink); background: var(--paper); }
.in-field .err { color: var(--down); font-size: 11px; margin-top: 4px; font-family: var(--mono); }
.in-seg {
  display: inline-flex; gap: 0; border: 1px solid var(--rule); width: fit-content;
}
.in-seg button {
  background: var(--paper); border: none;
  padding: 8px 16px; font-family: var(--sans); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; color: var(--ink-2);
  border-right: 1px solid var(--rule);
}
.in-seg button:last-child { border-right: none; }
.in-seg button:hover { background: var(--paper-2); }
.in-seg button.on { background: var(--ink); color: var(--paper); }
.in-seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.in-seg button:disabled:hover { background: var(--paper); }

.in-summary-row {
  display: flex; gap: 12px; align-items: baseline;
  padding: 12px; background: var(--paper-2);
  font-family: var(--mono); margin-bottom: 16px;
}
.in-summary-row.big { font-size: 16px; }
.in-summary-row strong { font-size: 20px; font-weight: 600; }
.in-summary-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px;
  padding-bottom: 18px; margin-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}

/* Capital flows list */
.in-flows { display: flex; flex-direction: column; }
.in-flow-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  align-items: baseline; gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.in-flow-row:last-child { border-bottom: none; }
.in-flow-row.total {
  border-top: 1px solid var(--rule-2);
  padding-top: 14px; margin-top: 4px;
  font-weight: 600;
}
.in-flow-row.total.emph {
  background: var(--paper-2); margin: 0 -12px; padding: 14px 12px;
}
.in-flow-label { font-size: 12px; color: var(--ink); }
.in-flow-note { font-size: 11px; }
.in-flow-count { font-family: var(--mono); font-size: 11px; text-align: right; }
.in-flow-amt { font-family: var(--mono); font-size: 13px; font-weight: 500; text-align: right; }

/* Head KPI cluster tweak: allow multiple kpi blocks with spacing */
.in-head-r .in-head-kpi { min-width: 110px; }

/* Alert chips (top of Book tab) */
.in-alerts {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 12px;
}
.in-alert {
  font-size: 12px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-left-width: 3px;
  background: var(--paper-2);
  font-family: var(--sans);
  display: flex; align-items: center; gap: 12px;
}
.in-alert > span:first-child { flex: 1; }
.in-alert.warn { border-left-color: var(--down, #c33); }
.in-alert.info { border-left-color: var(--ink-2, #888); color: var(--ink-2, #888); }
.in-alert-close {
  background: transparent; border: none; cursor: pointer;
  color: inherit; opacity: 0.5;
  font-size: 18px; line-height: 1; padding: 0 4px;
  font-family: inherit;
}
.in-alert-close:hover { opacity: 1; }

/* Toast */
.in-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 2px;
  font-family: var(--sans); font-size: 12px; letter-spacing: 0.06em;
  text-transform: uppercase;
  z-index: 200;
  animation: inFade 200ms;
}

@media (max-width: 900px) {
  .in-root { padding: 16px; }
  .in-rail { grid-template-columns: repeat(2, 1fr); }
  .in-metric { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
  .in-metric:nth-child(2n) { border-right: none; }
  .in-grid-2, .in-grid-3, .in-grid-order { grid-template-columns: 1fr; }
  .in-dialog-grid { grid-template-columns: repeat(2, 1fr); }
  .in-summary-list { grid-template-columns: 1fr; }
  .in-expiry-group { grid-template-columns: 1fr 1fr; }
  .in-table td.name { display: none; }
}
