:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #11151d;
  --panel-2: #151a24;
  --panel-3: #1a202c;
  --border: #242b39;
  --border-soft: #1c2330;
  --text: #f2f4f8;
  --muted: #8f99aa;
  --faint: #626c7c;
  --accent: #7181ff;
  --accent-strong: #8996ff;
  --accent-soft: rgba(113, 129, 255, 0.14);
  --green: #33c48d;
  --red: #f16f7a;
  --orange: #ff7043;
  --blue: #4f7cff;
  --sidebar-width: 294px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.is-hidden { display: none !important; }

.app-loader {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
  color: var(--muted);
}

.loader-mark { display: flex; align-items: end; justify-content: center; gap: 5px; height: 34px; }
.loader-mark span { width: 7px; border-radius: 5px; background: var(--accent); animation: loader 1s ease-in-out infinite; }
.loader-mark span:nth-child(1) { height: 18px; }
.loader-mark span:nth-child(2) { height: 30px; animation-delay: .14s; }
.loader-mark span:nth-child(3) { height: 23px; animation-delay: .28s; }
@keyframes loader { 0%, 100% { opacity: .35; transform: scaleY(.75); } 50% { opacity: 1; transform: scaleY(1); } }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.app-shell, .sidebar { transition: grid-template-columns .2s ease, transform .2s ease; }
.app-shell.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app-shell.sidebar-collapsed .sidebar { transform: translateX(-102%); }
.app-shell.sidebar-collapsed #open-sidebar { display: grid; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: #0e1219;
  border-right: 1px solid var(--border-soft);
}

.brand-row { height: 78px; padding: 0 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border-soft); }
.sidebar-collapse-button { margin-left: auto; font-size: 26px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; font-weight: 800; font-size: 18px; background: linear-gradient(145deg, #7786ff, #5366ef); box-shadow: 0 10px 30px rgba(91, 108, 245, .25); }
.brand-name { font-size: 15px; font-weight: 760; letter-spacing: .12em; }
.brand-subtitle { margin-top: 2px; font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .12em; }

.search-wrap { margin: 18px 16px 12px; height: 40px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.search-wrap:focus-within { border-color: #4654a8; box-shadow: 0 0 0 3px rgba(113, 129, 255, .08); }
.search-wrap svg { width: 17px; fill: none; stroke: var(--faint); stroke-width: 1.8; stroke-linecap: round; }
.search-wrap input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.search-wrap input::placeholder { color: #606a79; }

.sidebar-section-label { padding: 8px 19px 10px; display: flex; justify-content: space-between; align-items: center; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.count-badge { min-width: 24px; padding: 2px 7px; border-radius: 99px; text-align: center; background: #171c26; color: #737e8f; letter-spacing: 0; }

.groups-list { flex: 1; min-height: 0; padding: 0 9px 18px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2c3443 transparent; }
.group-block { margin-bottom: 5px; }
.group-header { width: 100%; height: 39px; padding: 0 8px 0 10px; display: flex; align-items: center; gap: 8px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; color: #aab2bf; }
.group-header:hover { background: #141923; color: var(--text); }
.group-chevron { color: #5c6676; font-size: 12px; transform: rotate(90deg); transition: transform .16s ease; }
.group-block.collapsed .group-chevron { transform: rotate(0deg); }
.group-color { width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 0 3px color-mix(in srgb, var(--group-color), transparent 82%); background: var(--group-color); }
.group-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-size: 12px; font-weight: 650; }
.group-count { color: #596373; font-size: 11px; }
.group-action { width: 25px; height: 25px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: #687283; cursor: pointer; opacity: 0; }
.group-header:hover .group-action { opacity: 1; }
.group-action:hover { background: #232a37; color: var(--text); }

.group-items { padding: 2px 0 6px; }
.group-block.collapsed .group-items { display: none; }
.series-row { display: flex; align-items: center; border-radius: 9px; }
.series-row:hover { background: #141923; }
.series-link { flex: 1; min-width: 0; padding: 9px 8px 9px 28px; display: block; border: 0; background: transparent; text-align: left; cursor: pointer; }
.series-row.active { background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); }
.series-row.active .series-name { color: #f5f6ff; }
.series-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #aeb6c2; font-size: 12px; font-weight: 590; }
.series-expression { margin-top: 3px; color: #586274; font-size: 10px; letter-spacing: .035em; }
.series-row.active .series-expression { color: #8f9aff; }
.series-edit { margin-right: 6px; opacity: 0; }
.series-row:hover .series-edit { opacity: 1; }
.empty-search { padding: 28px 15px; color: var(--faint); font-size: 12px; text-align: center; line-height: 1.6; }

.sidebar-footer { padding: 14px 16px 18px; border-top: 1px solid var(--border-soft); }
.full-width { width: 100%; }
.button-plus { font-size: 18px; line-height: 0; }

.main-content { grid-column: 2; min-width: 0; }
.topbar { height: 64px; padding: 0 28px; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; border-bottom: 1px solid var(--border-soft); background: rgba(11, 14, 20, .88); backdrop-filter: blur(16px); }
.topbar-spacer, .toolbar-spacer { flex: 1; }
.connection-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(51, 196, 141, .1); }
.connection-dot.loading { background: #f7b84b; box-shadow: 0 0 0 4px rgba(247, 184, 75, .1); animation: pulse 1.1s ease-in-out infinite; }
.connection-dot.error { background: var(--red); box-shadow: 0 0 0 4px rgba(241, 111, 122, .1); }
@keyframes pulse { 50% { opacity: .4; } }

.workspace { max-width: 1620px; margin: 0 auto; padding: 31px 34px 60px; }
.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; }
.breadcrumb { margin-bottom: 9px; color: var(--accent-strong); font-size: 10px; font-weight: 720; letter-spacing: .11em; text-transform: uppercase; }
.title-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-line h1 { margin: 0; font-size: clamp(22px, 2.2vw, 32px); line-height: 1.15; letter-spacing: -.035em; }
.expression-pill { padding: 5px 9px; border: 1px solid #2a3240; border-radius: 7px; background: #121720; color: #9aa4b4; font: 600 11px ui-monospace, SFMono-Regular, Consolas, monospace; }
.last-date { margin-top: 9px; color: var(--faint); font-size: 11px; }
.headline-value { min-width: 150px; text-align: right; }
.current-value { font-size: clamp(24px, 2.7vw, 36px); font-weight: 720; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.daily-change { margin-top: 7px; font-size: 12px; font-weight: 650; }
.daily-change.positive, .positive { color: var(--green) !important; }
.daily-change.negative, .negative { color: var(--red) !important; }
.daily-change.neutral { color: var(--muted); }

.chart-toolbar { min-height: 58px; margin-top: 26px; display: flex; align-items: center; gap: 10px; }
.segmented-control { padding: 3px; display: flex; gap: 2px; border: 1px solid var(--border); border-radius: 10px; background: #10141c; }
.segmented-control button { padding: 7px 11px; border: 0; border-radius: 7px; background: transparent; color: #788294; font-size: 11px; font-weight: 650; cursor: pointer; }
.segmented-control button:hover { color: var(--text); }
.segmented-control button.active { background: #202637; color: #f3f5ff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }

.topbar-button, .toolbar-button, .secondary-button, .primary-button, .danger-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 9px; cursor: pointer; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.topbar-button, .toolbar-button { height: 36px; padding: 0 12px; border: 1px solid var(--border); background: #11161f; color: #a5aebb; font-size: 11px; font-weight: 650; }
.topbar-button:hover, .toolbar-button:hover { border-color: #343d4e; background: #171d28; color: var(--text); }
.toolbar-button:disabled { cursor: not-allowed; opacity: .42; }
.toolbar-button:disabled:hover { border-color: var(--border); background: #11161f; color: #a5aebb; }
.toolbar-button.active { border-color: #6878f6; background: var(--accent-soft); color: #b7beff; box-shadow: 0 0 0 2px rgba(113, 129, 255, .08); }
.topbar-button svg, .toolbar-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.topbar-button.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.secondary-button, .primary-button, .danger-button { min-height: 38px; padding: 0 14px; font-size: 12px; font-weight: 680; }
.secondary-button { border: 1px solid var(--border); background: #151a23; color: #aab3c0; }
.secondary-button:hover { background: #1b222e; color: var(--text); }
.primary-button { border: 1px solid #6f7eff; background: #6979f8; color: white; box-shadow: 0 8px 22px rgba(94, 111, 242, .18); }
.primary-button:hover { background: #7887ff; transform: translateY(-1px); }
.danger-button { border: 1px solid rgba(241, 111, 122, .28); background: rgba(241, 111, 122, .08); color: #f58a94; }
.danger-button:hover { background: rgba(241, 111, 122, .14); }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; }
.icon-button:hover { background: #1a202a; color: var(--text); }
.small-count { min-width: 19px; height: 18px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 99px; background: var(--accent-soft); color: #9ca5ff; font-size: 10px; }
.drawing-actions { display: flex; gap: 7px; }

.indicator-control { position: relative; }
.indicator-popover { width: 370px; max-height: min(620px, calc(100vh - 120px)); position: absolute; z-index: 45; top: calc(100% + 8px); right: 0; padding: 12px; overflow-y: auto; border: 1px solid #2a3241; border-radius: 12px; background: #141923; box-shadow: 0 22px 60px rgba(0, 0, 0, .45); }
.comparison-control { position: relative; }
.comparison-popover { width: 330px; max-height: min(560px, calc(100vh - 130px)); position: absolute; z-index: 46; top: calc(100% + 8px); right: 0; padding: 12px; overflow: hidden; border: 1px solid #2a3241; border-radius: 12px; background: #141923; box-shadow: 0 22px 60px rgba(0, 0, 0, .45); }
.comparison-search { width: 100%; height: 36px; margin: 10px 0; padding: 0 10px; border: 1px solid #2a3240; border-radius: 8px; outline: 0; background: #0e131b; color: var(--text); }
.comparison-options { max-height: 410px; overflow-y: auto; }
.comparison-option { width: 100%; padding: 9px 10px; display: flex; justify-content: space-between; gap: 12px; border: 0; border-radius: 8px; background: transparent; color: #b8c0cc; text-align: left; cursor: pointer; }
.comparison-option:hover { background: #1b2130; }
.comparison-option:disabled { opacity: .35; cursor: default; }
.comparison-option small, .muted-copy { color: var(--faint); font-size: 10px; }
.popover-header { padding: 3px 7px 9px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.popover-title { color: #7f8999; font-size: 10px; font-weight: 720; letter-spacing: .1em; text-transform: uppercase; }
.popover-reset { padding: 3px 0; border: 0; background: transparent; color: #737e91; font-size: 10px; cursor: pointer; }
.popover-reset:hover { color: #b7beff; }
.indicator-option { padding: 9px 8px; border-radius: 8px; }
.indicator-option:hover { background: #1b212d; }
.indicator-option-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.indicator-option input { width: 16px; height: 16px; accent-color: var(--accent); }
.indicator-option-text { flex: 1; }
.indicator-option-name { color: #c3cad4; font-size: 12px; font-weight: 620; }
.indicator-option-kind { margin-top: 2px; color: #626c7c; font-size: 10px; }
.indicator-params { margin: 9px 0 0 26px; display: flex; flex-wrap: wrap; gap: 7px; }
.indicator-param { display: flex; align-items: center; gap: 6px; color: #697385; font-size: 9px; }
.indicator-param input { width: 58px; height: 28px; padding: 0 7px; border: 1px solid #2a3240; border-radius: 7px; outline: 0; background: #0e131b; color: #d8dde5; font-size: 11px; font-variant-numeric: tabular-nums; }
.indicator-param input:focus { border-color: #5363cb; box-shadow: 0 0 0 2px rgba(113, 129, 255, .09); }

.charts-region { position: relative; min-height: 590px; }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); gap: 14px; align-items: start; }
.chart-card { position: relative; min-width: 0; min-height: 590px; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 15px; background: var(--panel); box-shadow: 0 20px 70px rgba(0, 0, 0, .16); }
.chart-card.active { border-color: #5366ef; box-shadow: 0 0 0 1px rgba(101,119,255,.3), 0 20px 70px rgba(0,0,0,.16); }
.chart-card-header { min-height: 48px; padding: 9px 12px 7px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border-soft); }
.chart-card-title { min-width: 0; flex: 1; }
.chart-card-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #d9dee7; font-size: 12px; }
.chart-card-title span { color: var(--faint); font-size: 10px; }
.chart-card-actions { display: flex; align-items: center; gap: 5px; }
.mini-button { height: 29px; padding: 0 9px; border: 1px solid #2a3240; border-radius: 7px; background: #111720; color: #828d9e; font-size: 10px; cursor: pointer; }
.mini-button:hover { color: #d9dee7; border-color: #3a4558; }
.chart-card .chart { min-height: 520px; }
.chart-card .chart-hint { min-height: 34px; }
.panel-popouts { padding: 0 12px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.panel-popout-button { height: 27px; padding: 0 8px; display: inline-flex; align-items: center; border: 1px solid #252d3a; border-radius: 7px; background: #0f141c; color: #758093; font-size: 9px; text-decoration: none; cursor: pointer; }
.panel-popout-button:hover { color: #cbd2dc; }
.external-card-body { min-height: 540px; padding: 38px; display: grid; place-items: center; text-align: center; }
.external-card-body > div { max-width: 420px; }
.external-card-body h3 { margin: 12px 0 8px; color: #dfe4ec; }
.external-card-body p { color: var(--muted); line-height: 1.6; font-size: 12px; }
.external-badge { display: inline-flex; padding: 5px 8px; border-radius: 99px; background: #1d2636; color: #7fa9ff; font-size: 10px; }
.chart { min-height: 550px; width: 100%; }
.chart .modebar { top: 8px !important; right: 10px !important; }
.chart .modebar-btn path { fill: #8490a2 !important; }
.chart-hint { min-height: 38px; padding: 10px 18px; border-top: 1px solid var(--border-soft); color: #576172; font-size: 10px; text-align: center; }
.chart-loading, .chart-error { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 13px; background: rgba(17, 21, 29, .94); text-align: center; }
.chart-loading { flex-direction: row; }
.chart-loading div:last-child { display: flex; align-items: flex-start; flex-direction: column; gap: 4px; }
.chart-loading strong, .chart-error strong { font-size: 13px; }
.chart-loading span, .chart-error span { max-width: 430px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.spinner { width: 25px; height: 25px; border: 2px solid #2b3240; border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }

.stats-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-card { min-height: 108px; padding: 17px 18px; border: 1px solid var(--border-soft); border-radius: 13px; background: #10141c; }
.stat-label { display: flex; align-items: center; gap: 7px; color: #6f798a; font-size: 10px; font-weight: 680; letter-spacing: .045em; text-transform: uppercase; }
.stat-value { margin-top: 12px; color: #eef1f5; font-size: 21px; font-weight: 690; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.stat-note { margin-top: 5px; color: #626c7c; font-size: 10px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.blue { background: var(--blue); }
.legend-dot.orange { background: var(--orange); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 22px; display: grid; place-items: center; background: rgba(3, 5, 9, .72); backdrop-filter: blur(6px); }
.modal { width: min(500px, 100%); padding: 22px; border: 1px solid #2b3341; border-radius: 16px; background: #121721; box-shadow: 0 30px 90px rgba(0, 0, 0, .55); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 21px; }
.modal-eyebrow { margin-bottom: 6px; color: var(--accent-strong); font-size: 9px; font-weight: 730; letter-spacing: .13em; text-transform: uppercase; }
.modal h2 { margin: 0; font-size: 22px; letter-spacing: -.025em; }
.field { margin-bottom: 16px; display: block; }
.field > span { margin-bottom: 7px; display: block; color: #8e98a8; font-size: 11px; font-weight: 650; }
.field input, .field select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #2a3240; border-radius: 9px; outline: 0; background: #0e131b; color: var(--text); font-size: 13px; }
.field input:focus, .field select:focus { border-color: #5363cb; box-shadow: 0 0 0 3px rgba(113, 129, 255, .09); }
.field small { margin-top: 7px; display: block; color: #5f6979; font-size: 10px; }
.form-error { margin: 0 0 14px; padding: 10px 12px; border: 1px solid rgba(241, 111, 122, .22); border-radius: 8px; background: rgba(241, 111, 122, .07); color: #f18a93; font-size: 11px; }
.modal-actions { margin-top: 24px; display: flex; gap: 9px; }

.toast { position: fixed; z-index: 150; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 15px; border: 1px solid #30394a; border-radius: 10px; background: #1a202b; color: #d8dde5; box-shadow: 0 16px 50px rgba(0, 0, 0, .4); font-size: 11px; line-height: 1.45; animation: toast-in .2s ease-out; }
.login-screen { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 50% 0, rgba(101,119,255,.14), transparent 38%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 30px; border: 1px solid #293142; border-radius: 18px; background: #111620; box-shadow: 0 30px 90px rgba(0,0,0,.45); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand span { margin-top: 2px; color: var(--faint); font-size: 10px; }
.login-card h1 { margin: 30px 0 8px; }
.login-card > p, .modal-copy { color: var(--muted); font-size: 12px; line-height: 1.6; }
.login-card form, #password-form { margin-top: 22px; display: grid; gap: 14px; }
.user-state { display: flex; align-items: center; gap: 9px; color: #8f99a8; font-size: 11px; }
.compact-button { height: 31px; padding: 0 9px; }
.toast.error { border-color: rgba(241, 111, 122, .35); color: #f2929b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1000px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding-inline: 24px; }
}

@media (max-width: 760px) {
  .mobile-only { display: grid; }
  .app-shell { display: block; }
  .main-content { grid-column: auto; }
  .sidebar { transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 70px rgba(0, 0, 0, .35); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .55); }
  .sidebar-backdrop.open { display: block; }
  .brand-row .icon-button { margin-left: auto; }
  .topbar { padding-inline: 16px; }
  .topbar-button { width: 36px; padding: 0; font-size: 0; }
  .workspace { padding: 23px 15px 42px; }
  .chart-heading { flex-direction: column; gap: 13px; }
  .headline-value { min-width: 0; text-align: left; }
  .chart-toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbar-spacer { display: none; }
  .drawing-actions { order: 3; width: 100%; }
  .drawing-actions .toolbar-button { flex: 1; }
  .segmented-control { max-width: 100%; overflow-x: auto; }
  .indicator-control { margin-left: auto; }
  .stats-grid { grid-template-columns: 1fr; }
  .chart-card { border-radius: 12px; }
  .chart-hint { display: none; }
  .indicator-popover { position: fixed; top: auto; right: 14px; bottom: 14px; left: 14px; width: auto; }
  .comparison-popover { position: fixed; top: auto; right: 14px; bottom: 14px; left: 14px; width: auto; }
  .user-state span { display: none; }
  .sidebar-collapse-button { display: none; }
}
