:root {
  color-scheme: light;
  --page: #f6f8fb;
  --panel: #ffffff;
  --panel-alt: #fbfcff;
  --panel-strong: #f3f6fb;
  --header: #fbfcff;
  --border: #d7deea;
  --border-soft: #e7ebf2;
  --text: #1a2230;
  --muted: #5e6878;
  --muted-2: #7b8596;
  --positive: #0b7f2a;
  --negative: #d62d2d;
  --warning: #a06a00;
  --accent: #2a61d8;
  --toolbar-height: 58px;
  --content-max: 1540px;
  --instrument-width: 14.8%;
  --last-width: 6.2%;
  --metric-width: 6.35%;
  --action-width: 3.65%;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: "DM Sans", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-tabs {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(246, 248, 251, .96);
  backdrop-filter: blur(10px);
}

.app-tab {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-weight: 650;
}

.app-tab.is-active {
  border-color: rgba(42, 97, 216, .5);
  color: #1e4ea6;
  background: rgba(42, 97, 216, .1);
}

.app-pane {
  min-height: calc(100vh - 58px);
}

.investments-frame {
  width: 100%;
  min-height: calc(100vh - 59px);
  border: 0;
  display: block;
  background: #fff;
}

.toolbar {
  position: sticky;
  top: 57px;
  z-index: 40;
  min-height: var(--toolbar-height);
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(250px, 430px) minmax(230px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(10px);
}
.brand-block { min-width: 0; }
.brand-block > strong { display: block; font-size: 17px; line-height: 1.1; }
.connection-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted-2); box-shadow: 0 0 0 4px rgba(123, 133, 150, .12); }
.status-dot.live { background: var(--positive); box-shadow: 0 0 0 4px rgba(11, 127, 42, .12); }
.status-dot.delayed { background: var(--warning); box-shadow: 0 0 0 4px rgba(160, 106, 0, .12); }
.status-dot.offline { background: var(--negative); box-shadow: 0 0 0 4px rgba(214, 45, 45, .1); }
.separator { color: var(--muted-2); }

.search-box {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid #d9e0eb;
  border-radius: 10px;
  background: var(--panel);
}
.search-box span { color: var(--muted); }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.search-box input::placeholder { color: var(--muted-2); }
.toolbar-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toolbar-btn, .group-control, .group-mini-btn, .icon-btn {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--text);
}
.toolbar-btn:hover, .group-mini-btn:hover, .icon-btn:hover { border-color: #b6c5de; background: #f3f6fb; }
.toolbar-btn.primary { border-color: rgba(42, 97, 216, .55); background: rgba(42, 97, 216, .08); color: #1e4ea6; }
.icon-btn { width: 32px; padding: 0; font-size: 21px; line-height: 1; }

.dashboard-main { width: min(100%, var(--content-max)); margin: 0 auto; padding: 18px; }
.groups-container { display: grid; gap: 18px; }
.group-section {
  min-width: 0;
  border: 1px solid #dbe2ee;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 8px 26px rgba(22, 38, 62, .06);
  overflow: hidden;
}
.group-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-strong);
}
.group-heading { min-width: 150px; }
.group-title-line { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.group-name { font-size: 15px; font-weight: 700; letter-spacing: 0; }
.group-count { color: var(--muted); font-size: 10px; }
.group-reference-line { margin-top: 3px; color: var(--muted); font-size: 10px; }
.group-reference-line strong { color: #c7d1ff; }
.group-reference-line strong { color: #315aa8; }
.group-header-controls { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.group-header-controls label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; }
.group-header-controls select { height: 30px; padding: 3px 24px 3px 8px; border: 1px solid var(--border); background: #0b1220; color: var(--text); font-size: 11px; }
.group-header-controls select { background: #fff; }
.group-mini-btn { min-height: 30px; padding: 4px 8px; font-size: 10px; }
.group-mini-btn.marker-pending { color: var(--warning); }
.group-mini-btn.marker-ready { color: var(--positive); }

.group-table-scroll { width: 100%; overflow-x: clip; overflow-y: visible; }
.market-table {
  width: 100%;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}
th, td { white-space: nowrap; border-bottom: 1px solid var(--border-soft); }
th {
  position: sticky;
  top: 0;
  z-index: 8;
  height: 38px;
  padding: 6px 7px;
  background: var(--header);
  color: #2b3340;
  font-size: 12px;
  line-height: 1.05;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
}
th span, th small { display: block; overflow: hidden; text-overflow: ellipsis; }
th small { margin-top: 4px; color: #7c8698; font-size: 10px; letter-spacing: 0; text-transform: none; }
th.number, td.number { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); background: #f4f7fc; }
th.sort-active { color: #1f4fa7; }
.sort-arrow { display: inline !important; margin-left: 3px; color: var(--accent); font-size: 9px; }

.instrument-col { width: var(--instrument-width); min-width: var(--instrument-width); max-width: var(--instrument-width); }
.last-col { width: var(--last-width); min-width: var(--last-width); max-width: var(--last-width); }
.metric-col { width: var(--metric-width); min-width: var(--metric-width); max-width: var(--metric-width); }
.actions-col { width: var(--action-width); min-width: var(--action-width); max-width: var(--action-width); text-align: center !important; }
.sticky-instrument { position: sticky; left: 0; z-index: 7; background: var(--panel); border-right: 1px solid var(--border); }
th.sticky-instrument { z-index: 12; background: var(--header); }
.sticky-actions { position: sticky; right: 0; z-index: 7; background: var(--panel); border-left: 1px solid var(--border); }
th.sticky-actions { z-index: 12; background: var(--header); }

.instrument-row td { height: 64px; padding: 10px 8px; background: var(--panel); }
.instrument-row:hover td { background: #f8fbff; }
.instrument-row:hover .sticky-instrument, .instrument-row:hover .sticky-actions { background: #f8fbff; }
.instrument-row.reference-row td { background: #f2f7ff; }
.instrument-row.reference-row .sticky-instrument, .instrument-row.reference-row .sticky-actions { background: #eef5ff; }
.instrument-cell { cursor: pointer; }
.instrument-cell:hover strong { color: #dce4ff; }
.instrument-cell strong { display: flex; align-items: center; gap: 7px; font-size: 40px; line-height: 1; font-weight: 700; letter-spacing: -.01em; }
.instrument-cell small { display: block; max-width: calc(var(--instrument-width) - 20px); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; color: #4f5968; font-size: 16px; line-height: 1.15; text-transform: none; }
.reference-tag { padding: 2px 5px; border: 1px solid rgba(42, 97, 216, .45); color: #315aa8; font-size: 8px; font-weight: 750; }
.price-cell { font-size: clamp(18px, 1.35vw, 28px); font-weight: 500; color: #525c6b; }

.metric-cell { position: relative; overflow: hidden; isolation: isolate; }
.metric-main { display: block; font-size: clamp(18px, 1.25vw, 36px); font-weight: 500; line-height: 1.02; }
.metric-delta { display: block; margin-top: 3px; color: #697383; font-size: clamp(14px, .95vw, 26px); font-weight: 500; line-height: 1.06; }
.metric-delta.reference-zero { color: #4f5968; }
.metric-track {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 3px;
  height: 5px;
  pointer-events: none;
}
.metric-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 2px;
  height: 1px;
  background: #d7e0ef;
}
.metric-track::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 5px;
  background: #9aa5b6;
}
.metric-dot {
  position: absolute;
  left: var(--delta-position, 50%);
  top: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
  box-shadow: 0 0 0 1px var(--panel);
}
.metric-cell.outlier .metric-main::after { content: " !"; color: var(--warning); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.neutral { color: var(--muted); }
.pending { color: var(--warning); }

th + th, td + td { border-left: 1px solid #edf1f7; }
.period-start { border-left: 2px solid #d5ddeb !important; }
.period-open { background-color: #fcfdff !important; }
.period-day { background-color: #fbfdff !important; }
.period-week { background-color: #fcfdff !important; }
.period-month { background-color: #fbfdff !important; }
.period-year { background-color: #fcfdff !important; }
.reference-column { background-color: #f7faff !important; }
.moment-column { background-color: #fcfdff !important; }
.row-menu-btn {
  width: 29px;
  height: 28px;
  padding: 0 0 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.row-menu-btn:hover { border-color: var(--border); background: var(--panel-strong); color: var(--text); }
.empty-group td { height: 46px; padding: 10px; color: var(--muted); font-size: 11px; background: var(--panel); }
.empty-state { padding: 24px; color: var(--muted); text-align: center; }
.bridge-offline .instrument-row td:not(.sticky-instrument):not(.sticky-actions) { opacity: .72; }

@media (max-width: 1250px) {
  :root {
    --instrument-width: 15.5%;
    --last-width: 6.2%;
    --metric-width: 6.75%;
    --action-width: 4.05%;
  }
  .dashboard-main { padding: 7px; }
  .group-header { padding: 6px 8px; }
  th { padding-inline: 4px; font-size: 9.5px; }
  th small { font-size: 7.5px; }
  .instrument-row td { padding-inline: 4px; }
  .instrument-cell small { font-size: 9px; }
  .metric-track { left: 4px; right: 4px; }
}

@media (max-width: 980px) {
  :root {
    --instrument-width: 16.5%;
    --last-width: 6.5%;
    --metric-width: 6.6%;
    --action-width: 4.4%;
  }
  .toolbar { grid-template-columns: 1fr minmax(190px, 320px) auto; gap: 8px; padding: 6px 8px; }
  .toolbar-btn { padding-inline: 7px; }
  .group-reference-line { display: none; }
  .group-header { align-items: flex-start; }
  .metric-track { display: none; }
  .instrument-cell small { display: none; }
  .instrument-row td { height: 39px; }
  .metric-delta { margin-top: 2px; }
}

@media (max-width: 760px) {
  .toolbar { position: static; grid-template-columns: 1fr auto; }
  .search-box { grid-column: 1 / -1; order: 3; }
  .dashboard-main { padding: 4px; }
  .group-header { display: grid; grid-template-columns: 1fr; }
  .group-header-controls { justify-content: flex-start; }
  .market-table { font-size: 11px; }
  .metric-main { font-size: 11px; }
  .metric-delta { font-size: 9px; }
  th { font-size: 8px; }
}

.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .68); backdrop-filter: blur(3px); }
.modal, .drawer {
  position: fixed;
  z-index: 61;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}
.modal { left: 50%; top: 50%; width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 32px); overflow: auto; transform: translate(-50%, -50%); }
.wide-modal { width: min(900px, calc(100vw - 28px)); }
.drawer { right: 0; top: 0; width: min(480px, 100vw); height: 100dvh; overflow: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px; border-bottom: 1px solid var(--border); background: var(--panel-alt); }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-header p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.modal-body { display: flex; flex-direction: column; gap: 13px; padding: 14px; }
.modal-body label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; }
.modal-body input, .modal-body select { width: 100%; min-height: 36px; padding: 7px 9px; border: 1px solid var(--border); background: var(--panel-alt); color: var(--text); font-size: 13px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two-columns { grid-template-columns: 1fr 1.4fr; }
fieldset { margin: 0; padding: 11px; border: 1px solid var(--border); }
legend { padding: 0 5px; color: var(--muted); font-size: 11px; }
.checkbox-list { display: grid; gap: 8px; }
.checkbox-item { display: flex !important; flex-direction: row !important; justify-content: space-between; align-items: center; gap: 10px; }
.checkbox-item input { width: 17px; min-height: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-note { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.moment-editor-row {
  display: grid;
  grid-template-columns: 52px minmax(160px, 1fr) minmax(190px, 1.2fr) 130px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
}
.moment-slot { align-self: center; color: #c0caff; font-size: 14px; font-weight: 800; }
.moment-status { grid-column: 2 / -1; color: var(--muted); font-size: 10px; }
.moment-status.resolved { color: var(--positive); }
.moment-status.pending { color: var(--warning); }
.error-box { padding: 10px; border: 1px solid rgba(255, 102, 123, .4); color: var(--negative); font-size: 10px; white-space: pre-wrap; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-card { padding: 10px; border: 1px solid var(--border); background: var(--panel-alt); }
.detail-card span { display: block; color: var(--muted); font-size: 10px; }
.detail-card strong { display: block; margin-top: 4px; font-size: 13px; }
.drawer-section { padding-top: 12px; border-top: 1px solid var(--border); }
.drawer-section h3 { margin: 0 0 8px; font-size: 13px; }
.drawer-note { margin: 0 0 9px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.action-list { display: grid; gap: 7px; }
.action-list button { text-align: left; }
.hidden-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px; border: 1px solid var(--border); background: var(--panel-alt); }
.hidden-row strong { font-size: 13px; }
.hidden-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 18px; max-width: calc(100vw - 30px); transform: translateX(-50%); padding: 9px 13px; border: 1px solid var(--border); background: #1a2740; font-size: 11px; }


@media (max-width: 760px) {
  .connection-line .separator, #lastUpdateLabel { display: none; }
  .modal, .wide-modal { left: 0; top: 0; width: 100vw; max-height: 100dvh; height: 100dvh; transform: none; border: 0; }
  .drawer { width: 100vw; }
  .form-grid.two-columns { grid-template-columns: 1fr; }
  .moment-editor-row { grid-template-columns: 42px 1fr; }
  .moment-editor-row label { grid-column: 2; }
  .moment-status { grid-column: 2; }
}
