:root {
  --bg: #0b0f14;
  --bg-2: #101720;
  --surface: #141c26;
  --surface-2: #192433;
  --surface-3: #213044;
  --border: #2a394d;
  --border-strong: #3a506b;
  --fg: #ecf4ff;
  --muted: #93a4ba;
  --subtle: #617289;
  --teal: #14b8a6;
  --teal-soft: #0b3d3a;
  --blue: #60a5fa;
  --blue-soft: #123253;
  --amber: #f59e0b;
  --amber-soft: #3b2b0a;
  --rose: #fb7185;
  --rose-soft: #3b121c;
  --green: #22c55e;
  --green-soft: #0d341f;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
  --font-sans: 'Instrument Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html:not(.dark) {
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --surface-3: #e1e8f0;
  --border: #d8e0ea;
  --border-strong: #b9c6d6;
  --fg: #132033;
  --muted: #596b82;
  --subtle: #8190a3;
  --teal-soft: #daf7f2;
  --blue-soft: #dbeafe;
  --amber-soft: #fef3c7;
  --rose-soft: #ffe4e8;
  --green-soft: #dcfce7;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.mono { font-family: var(--font-mono); }
.mt { margin-top: 16px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 8px 14px; border-bottom: 1px solid var(--border); }
.brand__mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: #031311; background: linear-gradient(135deg, var(--teal), #a3e635); }
.brand__mark svg { width: 17px; height: 17px; }
.brand__text { font-weight: 700; letter-spacing: 0; }
.brand--login { padding: 0; border: 0; margin-bottom: 22px; }

.nav { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; flex: 1; }
.nav__link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.nav__link svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav__link span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__link b { min-width: 22px; height: 20px; padding: 2px 6px; border-radius: 999px; background: var(--surface-3); color: var(--fg); font-size: 11px; text-align: center; }
.nav__link:hover { background: var(--surface-2); color: var(--fg); }
.nav__link.is-active { background: var(--teal-soft); color: var(--fg); border-color: color-mix(in oklab, var(--teal) 45%, transparent); }
.sidebar__foot { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar__foot form { margin: 0; }

.main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__left, .topbar__right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 2px 0 0; font-size: 20px; line-height: 1.2; letter-spacing: 0; }
.crumbs { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.crumbs a { color: var(--blue); }
.content { padding: 22px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--fg); font-weight: 700; border: 1px solid var(--border); }
.mobile-toggle { display: none; }

.flash { margin: 14px 22px 0; padding: 11px 13px; border-radius: var(--radius); border: 1px solid var(--border); }
.flash--ok { background: var(--green-soft); border-color: color-mix(in oklab, var(--green) 45%, transparent); }
.flash--err { background: var(--rose-soft); border-color: color-mix(in oklab, var(--rose) 45%, transparent); }
.notice { margin: 15px 15px 0; padding: 12px 13px; border-radius: var(--radius); border: 1px solid var(--border); color: var(--fg); }
.notice--warn { background: var(--amber-soft); border-color: color-mix(in oklab, var(--amber) 38%, transparent); }

.page-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi { padding: 15px; min-height: 118px; display: flex; flex-direction: column; justify-content: space-between; }
.kpi span, .kpi small { color: var(--muted); }
.kpi strong { font-size: 27px; letter-spacing: 0; }
.kpi--green { border-top: 3px solid var(--green); }
.kpi--blue { border-top: 3px solid var(--blue); }
.kpi--amber { border-top: 3px solid var(--amber); }
.kpi--rose { border-top: 3px solid var(--rose); }

.split { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.panel { min-width: 0; overflow: hidden; }
.panel__head {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
}
.panel__head h2 { margin: 0; font-size: 15px; letter-spacing: 0; }
.chart-box { height: 292px; padding: 12px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: color-mix(in oklab, var(--surface-2) 80%, transparent); }
td small { display: block; color: var(--muted); margin-top: 2px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.edit-row td { padding-top: 8px; padding-bottom: 14px; background: color-mix(in oklab, var(--surface-2) 55%, transparent); }
.actions { width: 1%; white-space: nowrap; }
.actions form { margin: 0; }

.btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  padding: 8px 12px;
}
.btn svg, .icon-btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--teal); border-color: var(--teal); color: #031311; font-weight: 700; }
.btn--secondary:hover, .icon-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.icon-btn { width: 36px; padding: 0; }
.link-sm { color: var(--blue); font-size: 12px; }
.toolbar-form { margin: 0; }
.link-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 150px;
  padding: 3px 8px;
  margin: 0 4px 4px 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--blue);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-muted { color: var(--muted); }

.chip, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.badge--ok { background: var(--green-soft); border-color: color-mix(in oklab, var(--green) 42%, transparent); }
.badge--warn { background: var(--amber-soft); border-color: color-mix(in oklab, var(--amber) 42%, transparent); }
.badge--info { background: var(--blue-soft); border-color: color-mix(in oklab, var(--blue) 42%, transparent); }
.badge--muted { color: var(--muted); }
.score { display: inline-grid; place-items: center; min-width: 34px; height: 28px; border-radius: 7px; background: var(--teal-soft); color: var(--fg); font-weight: 700; font-family: var(--font-mono); }
.pnl { font-weight: 700; font-family: var(--font-mono); }
.pnl.is-up { color: var(--green); }
.pnl.is-down { color: var(--rose); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: var(--subtle); }
.status-dot--ok { background: var(--green); box-shadow: 0 0 0 4px color-mix(in oklab, var(--green) 16%, transparent); }
.status-dot--warn { background: var(--amber); box-shadow: 0 0 0 4px color-mix(in oklab, var(--amber) 16%, transparent); }
.status-dot--err { background: var(--rose); box-shadow: 0 0 0 4px color-mix(in oklab, var(--rose) 16%, transparent); }
.status-dot--muted { background: var(--subtle); }

.wallet-stack, .activity, .list { display: flex; flex-direction: column; }
.wallet-mini, .activity__row, .list__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
}
.wallet-mini:last-child, .activity__row:last-child, .list__row:last-child { border-bottom: 0; }
.wallet-mini div, .activity__row div, .list__row div { min-width: 0; flex: 1; }
.wallet-mini small, .activity__row small, .list__row small { display: block; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px 15px; color: var(--muted); text-align: center; }

.form { padding: 15px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.form label span { font-size: 12px; }
input, select, textarea {
  width: 100%;
  min-height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--fg);
  background: var(--surface-2);
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px color-mix(in oklab, var(--teal) 18%, transparent); }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; }
.check input { width: 16px; min-height: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-form input, .inline-form select { width: auto; min-width: 110px; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.strategy-card { padding-bottom: 10px; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 15px; margin: 0; }
.kv div { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 3px 0 0; font-weight: 700; }
.steps { margin: 0; padding: 16px 18px 18px 38px; }
.steps li { margin: 0 0 10px; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at top left, color-mix(in oklab, var(--teal) 20%, transparent), transparent 32rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}
.login { width: min(440px, 100%); }
.login__panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 24px; box-shadow: var(--shadow); }
.login__panel h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: 0; }
.login__panel p { margin: 0 0 20px; color: var(--muted); }
.telegram-login { margin-top: 14px; min-height: 44px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; }

nav[role="navigation"] { padding: 12px 14px; }
nav[role="navigation"] .hidden { display: none; }

@media (max-width: 1100px) {
  .page-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; transform: translateX(-105%); transition: transform .18s ease; width: 248px; }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-toggle { display: inline-flex; }
  .topbar { align-items: flex-start; padding: 12px 14px; }
  .content { padding: 14px; }
  .page-grid, .card-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form .btn { width: 100%; }
}
