:root {
  color-scheme: light;
  --sidebar-width: 340px;
  --bg: #f6f7fb;
  --panel: #fffefa;
  --panel-soft: #f2f3f8;
  --panel-muted: #eceef4;
  --line: #dde0ea;
  --text: #1f2432;
  --muted: #6a7284;
  --accent: #0f172a;
  --accent-strong: #0b1222;
  --accent-ink: #0f172a;
  --accent-tint: #edf1fb;
  --support: #0f172a;
  --support-strong: #0b1222;
  --support-tint: #eff6ff;
  --danger: #b91c1c;
  --warn: #b45309;
  --page-gutter-top: 18px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 10px 30px rgb(15 23 42 / 0.05);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
}

.app-shell::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.48;
  content: "";
  background:
    radial-gradient(80% 55% at 50% -10%, rgb(127 150 220 / 0.16), transparent 70%),
    radial-gradient(100% 70% at 50% 120%, rgb(121 134 178 / 0.08), transparent 76%),
    repeating-linear-gradient(73deg, transparent 0 14px, rgb(141 154 200 / 0.16) 14px 15px),
    repeating-linear-gradient(-73deg, transparent 0 14px, rgb(141 154 200 / 0.16) 14px 15px);
  mask-image: radial-gradient(120% 86% at 50% 0%, #000 45%, transparent 92%);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 2;
  width: var(--sidebar-width);
  border-right: 1px solid #d7dbe6;
  background: rgb(248 249 253 / 0.96);
  backdrop-filter: blur(3px);
}

.sidebar-inner {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  gap: 20px;
  padding: max(var(--page-gutter-top), env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
}

.sidebar-resizer {
  display: none;
}

.sidebar-resizer::after {
  position: absolute;
  top: 0;
  right: 4px;
  bottom: 0;
  width: 2px;
  background: transparent;
  content: "";
}

.sidebar-resizer::before {
  position: absolute;
  top: 50%;
  right: 2px;
  width: 6px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  content: "";
  transform: translateY(-50%);
}

.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after {
  background: var(--accent);
}

.sidebar-resizer:hover::before,
.sidebar-resizer:focus-visible::before {
  border-color: #9fabc8;
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

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

.brand-logo {
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #cfd5e7;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgb(15 23 42 / 0.08), 0 14px 34px rgb(15 23 42 / 0.08);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.brand-name {
  font-size: 32px;
  font-weight: 860;
  line-height: 0.98;
  color: #111525;
  text-wrap: balance;
}

.control-section {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 15px;
  font-weight: 760;
  text-wrap: pretty;
}

.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-wrap: pretty;
}

.select-wrap,
.input-suffix,
.currency-wrap,
.pair-input {
  position: relative;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  padding: 10px 12px;
  box-shadow: 0 1px 1px rgb(15 23 42 / 0.03);
  font-size: 16px;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent-strong);
  outline: 2px solid rgb(37 99 235 / 0.18);
  outline-offset: 1px;
}

select {
  appearance: none;
  padding-right: 32px;
  font-weight: 650;
}

.select-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  width: 15px;
  height: 15px;
  pointer-events: none;
  stroke: var(--muted);
  transform: translateY(-50%);
}

.instrument-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.05;
}

.instrument-meta span {
  white-space: nowrap;
}

.instrument-meta b {
  display: inline;
  margin-left: 4px;
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
}

.input-suffix input,
.pair-input input {
  padding-right: 56px;
}

.input-suffix span,
.pair-input span {
  position: absolute;
  right: 10px;
  top: 50%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  pointer-events: none;
  transform: translateY(-50%);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-row button {
  min-width: 34px;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 10px;
}

.preset-row button.is-active {
  border-color: #aeb9d8;
  background: var(--accent-tint);
  color: var(--accent-ink);
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 750;
  line-height: 1;
  padding: 10px 16px;
  white-space: nowrap;
}

.button-primary {
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-dark {
  width: 100%;
  background: var(--accent);
  color: #ffffff;
}

.button-dark:hover {
  background: var(--accent-strong);
}

.button-tight {
  min-height: 36px;
  padding-inline: 12px;
}

.text-button {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 6px;
}

.text-button:hover {
  color: var(--text);
}

.support-panel {
  display: grid;
  gap: 8px;
}

.support-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.support-link {
  min-height: 44px;
  padding: 8px 10px;
}

.support-link b,
.support-link small {
  display: block;
}

.support-link b {
  font-size: 13px;
  line-height: 1.1;
}

.support-link small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1;
}

.support-link-primary {
  border-color: #1f2738;
  background: var(--support);
  color: #ffffff;
}

.support-link-primary:hover {
  background: var(--support-strong);
}

.support-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
}

.support-link-primary .support-icon {
  background: rgb(255 255 255 / 0.18);
  color: #ffffff;
}

.support-link-primary small {
  color: rgb(255 255 255 / 0.78);
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}

.icon-button.sidebar-close {
  display: none;
}

.icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sidebar-spacer {
  flex: 1;
}

.mobile-bar {
  display: none;
}

.main {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding-left: var(--sidebar-width);
}

.main-inner {
  width: min(calc(100vw - var(--sidebar-width)), 1320px);
  margin: 0 auto;
  padding: max(var(--page-gutter-top), env(safe-area-inset-top)) clamp(28px, 4vw, 64px) 64px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 14px;
}

.workspace-head {
  display: grid;
  gap: 4px;
  margin-right: auto;
}

.workspace-head h1 {
  margin: 0;
  color: #161b29;
  font-size: clamp(22px, 2.2vw, 28px);
  font-weight: 800;
  line-height: 1.05;
  text-wrap: balance;
}

.workspace-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
  text-wrap: pretty;
}

.toolbar .button {
  margin-top: 0;
}

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
  align-items: start;
  gap: 16px;
  padding-top: 0;
}

.account-card {
  border: 1px solid #d9dce8;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.82);
  backdrop-filter: blur(2px);
  box-shadow: var(--shadow);
}

.account-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

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

.account-name {
  width: 100%;
  min-height: 36px;
  border: 0;
  box-shadow: none;
  padding: 0 4px;
  font-size: 17px;
  font-weight: 750;
}

.account-name:focus {
  outline-offset: 0;
}

.remove-account {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.remove-account:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.account-row > *,
.field-grid > *,
.stats-grid > * {
  min-width: 0;
}

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: 10px;
  background: var(--panel-muted);
  padding: 2px;
}

.segment button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.segment button.is-active {
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 700;
}

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

.field-block {
  display: grid;
  gap: 6px;
}

.pair-input.is-derived input {
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 750;
}

.risk-card {
  display: grid;
  gap: 8px;
  border: 1px solid #d8ddea;
  border-radius: 10px;
  background: var(--accent-tint);
  padding: 14px 14px 12px;
}

.risk-title {
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
  text-wrap: pretty;
}

.risk-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--accent-ink);
}

.risk-value strong {
  font-family:
    "SF Mono", SFMono-Regular, ui-monospace, Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
  font-size: 28px;
  line-height: 1;
}

.risk-value span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.risk-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.15;
}

.risk-meta b {
  display: inline;
}

.risk-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

.risk-bar {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe2f3;
}

.risk-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #4b638f;
}

.risk-bar span.is-warn {
  background: var(--warn);
}

.risk-bar span.is-danger {
  background: var(--danger);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

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

.stat-key {
  color: var(--muted);
  font-size: 12px;
}

.stat-value {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.1;
}

.stat-value small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.add-card,
.empty-state {
  display: grid;
  min-height: 84px;
  place-items: center;
  border: 1px dashed #cfd4e3;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.58);
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
}

.add-card {
  display: none;
  gap: 7px;
}

.empty-state {
  gap: 8px;
  padding: 20px;
  text-align: center;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  text-wrap: pretty;
}

.empty-state .button {
  width: fit-content;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1024px) {
  body {
    background: var(--bg);
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 15;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  }

  .brand-compact {
    align-items: center;
  }

  .brand-compact .brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 6px;
  }

  .brand-compact .brand-logo img {
    padding: 2px;
  }

  .mobile-params {
    display: flex;
    min-width: 0;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    cursor: pointer;
    padding: 6px 9px;
    font-weight: 800;
  }

  .mobile-params span {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .mobile-dot {
    width: 3px;
    height: 3px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--muted);
  }

  .mobile-params .icon {
    margin-left: auto;
    flex: 0 0 auto;
    color: var(--muted);
  }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgb(0 0 0 / 0.32);
  }

  .sidebar {
    z-index: 30;
    width: 100vw;
    min-width: 0;
    max-width: none;
    border-right: 0;
    transform: translateX(-100%);
  }

  .sidebar-resizer {
    display: none;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .icon-button.sidebar-close {
    display: grid;
  }

  .main {
    padding-left: 0;
  }

  .main-inner {
    width: 100%;
    padding: 14px 14px 28px;
  }

  .toolbar {
    display: none;
  }

  .accounts-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .add-card {
    display: grid;
  }

  .account-body {
    gap: 10px;
    padding: 14px 12px;
  }

  .button-tight {
    width: 42px;
    padding-inline: 0;
  }

  .button-tight span {
    display: none;
  }
}

@media (max-width: 430px) {
  .field-grid,
  .stats-grid {
    gap: 8px;
  }
}
