:root {
  color-scheme: light;
  --bg: #edf2f7; --nested:#f3f7fb; --inset:#e8eff7; --edge:#bdcbdb; --panel-shadow:0 5px 16px rgb(34 62 90 / 9%); --surface: #fff; --surface-alt: #f1f5f9; --ink: #0b1220;
  --muted: #526176; --line: #dce4ed; --brand: #2563eb; --active-bg: #edf4ff;
  --active-text: #194caf; --cyan: #22d3ee; --success-bg: #e5f5ef; --success: #116046;
  --warning-bg: #fff2d5; --warning: #785108; --error-bg: #ffedec; --error: #a5322c;
  --shadow: 0 3px 12px rgb(22 40 64 / 5%);
  font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
[data-theme=dark] {
  color-scheme: dark;
  --bg: #0b1220; --nested:#1c2a40; --inset:#253750; --edge:#4a607b; --panel-shadow:none; --surface: #141f30; --surface-alt: #1b293d; --ink: #eff6ff;
  --muted: #abb9cb; --line: #324157; --brand: #477ef1; --active-bg: #1e3559;
  --active-text: #adcaff; --success-bg: #163c36; --success: #96e4ca;
  --warning-bg: #422f13; --warning: #ffd68c; --error-bg: #4c2729; --error: #ffb0ab;
}
* {box-sizing: border-box}
body {margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh}
[hidden] {display: none !important}
a {color: var(--active-text); text-underline-offset: .2em}
button, input, select, textarea {font: inherit; color: inherit}
button, .button {display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 2.55rem; padding: .45rem .85rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 550; cursor: pointer}
button:hover, .button:hover {background: var(--surface-alt)}
button.primary, .button.primary, button[type=submit] {color: #fff; background: #215bd9; border-color: #215bd9}
button.primary:hover, .button.primary:hover, button[type=submit]:hover {background: #194ebc}
button.danger {color: var(--error); border-color: var(--error)}
button:disabled {opacity: .55; cursor: not-allowed}
:focus-visible {outline: 3px solid var(--brand); outline-offset: 2px}
input:not([type=checkbox]):not([type=radio]), textarea, select {width: 100%; min-width: 0; min-height: 2.7rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface)}
textarea {resize: vertical; min-height: 6rem}
input[type=checkbox], input[type=radio] {accent-color: var(--brand)}
label {display: grid; gap: .35rem; color: var(--muted); font-weight: 550}
form {display: grid; gap: 1rem} form button {justify-self: start}
fieldset {min-width: 0; border: 1px solid var(--line); border-radius: .55rem}
h1,h2,h3 {margin: 0; line-height: 1.18; letter-spacing: -.035em}
h1 {font-size: clamp(1.85rem, 3vw, 2.55rem)}
h2 {font-size: 1.3rem} h3 {font-size: 1.05rem}
p {margin: .55rem 0; overflow-wrap: anywhere}
small, .muted, #subtitle {color: var(--muted)}
.skip {position: fixed; z-index: 9; top: -6rem; left: .7rem; background: var(--surface); padding: .5rem}
.skip:focus {top: .5rem}
.shell {display:grid; grid-template-columns:clamp(13rem,16vw,17rem) minmax(0,1fr); min-height:100vh; width:100%; --workspace-gutter:clamp(1rem,2.4vw,2.5rem)}
.sidebar {position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height:0; align-self:start; padding: 1.55rem .8rem 1rem; background: #0b1220; color: #eef4ff; z-index: 4}
.brand {display: flex; align-items: center; gap: .6rem; font-size: 1.23rem; letter-spacing: -.055em; font-weight: 650; white-space: nowrap}
.brand strong {color: #22d3ee; font-weight: 650}
.sidebar .brand {padding: 0 .65rem 1.6rem}
.brand-mark {display: inline-block; position: relative; width: 2.05rem; height: 2.05rem; border-radius: .55rem; background: #2563eb}
.brand-mark::before,.brand-mark::after {content: ""; position: absolute; left: 23%; width: 54%; height: 17%; background: #fff; transform: skewY(-22deg); border-radius: .08rem}
.brand-mark::before {top: 30%}.brand-mark::after {top: 54%; background: #55e0f3}
#nav {display: flex; flex-direction: column; gap: .13rem; min-height:0; overflow-y: auto; padding: .2rem; scrollbar-width: thin}
#nav button, #nav a {position: relative; display: flex; width: 100%; justify-content: flex-start; align-items: center; min-height: 2.54rem; padding: .48rem .8rem; border: 0; border-radius: .45rem; color: #bbc7d8; background: transparent; text-decoration: none; font-weight: 480; text-align: left}
#nav :is(button,a):hover {background: #1b2a41; color: #fff}
#nav :is(.active,[aria-current=page],[aria-selected=true]) {background: #1e385d; color: #fff; box-shadow: inset 3px 0 #22d3ee; font-weight: 600}
.account {display: flex; align-items: center; gap: .5rem; justify-content: space-between; margin-top: auto; padding: 1.1rem .6rem 0; border-top: 1px solid #28384f}
#identity {overflow-wrap: anywhere; min-width: 0; color: #d5dfea; font-size: .82rem}
#logout {min-height: 2.1rem; font-size: .8rem; padding: .2rem .55rem; border-color: #40516a; background: transparent; color: #edf5ff}
.workspace {min-width:0; width:100%; min-height:0}
.topbar {min-height: 3.85rem; display: flex; align-items: center; gap: .7rem; padding: .55rem var(--workspace-gutter); width:100%; position:sticky; top:0; z-index:2; border-bottom: 1px solid var(--line); background: var(--surface)}
.workspace-label {color: var(--muted); font-size: .88rem}
.theme-toggle {margin-left: auto; min-height: 2.15rem; font-size: .83rem}
#menu-toggle {display: none}
.page {width:100%; min-width:0; margin:0; padding:var(--workspace-gutter,1rem)}
.page-header {display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.65rem}
#subtitle:empty,#actions:empty {display: none}
#content {min-width: 0; outline: 0; display: grid; gap: 1.1rem}
.actions,.toolbar,.pagination {display: flex; flex-wrap: wrap; align-items: center; gap: .55rem}
.toolbar input:not([type=checkbox]),.toolbar select,.actions select {width: auto; max-width: 100%}
.panel, .card, .metric, .column, details.help {min-width: 0; padding: 1.3rem; background: var(--surface); border: 1px solid var(--line); border-radius: .85rem; box-shadow: var(--shadow)}
.panel>*+*, .card>*+* {margin-top: .8rem}
.grid,.metrics,.board {display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit,minmax(min(100%,220px),1fr))}
.metrics {grid-template-columns: repeat(auto-fit,minmax(min(100%,165px),1fr))}
.metric {border-top: 3px solid var(--brand)}
.metric:nth-child(3n+2) {border-top-color: #13a6c2}
.metric :is(strong,b,.value) {display: block; font-size: clamp(1.45rem,2.5vw,2.15rem); font-weight: 650; letter-spacing: -.045em; font-variant-numeric: tabular-nums}
.metric :is(small,label,.label) {font-size: .84rem; color: var(--muted)}
.table-wrap {max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface)}
table {width: 100%; border-collapse: collapse; background: var(--surface); text-align: left; font-variant-numeric: tabular-nums}
td,th {padding: .7rem .8rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; vertical-align: top}
th {font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--surface-alt)}
tr:last-child td {border-bottom: 0} tr:hover td {background: var(--bg)}
.badge {display: inline-flex; align-items: center; padding: .15rem .55rem; border-radius: 1rem; background: var(--active-bg); color: var(--active-text); font-size: .8rem; font-weight: 600}
.success {background: var(--success-bg); color: var(--success)} .warning {background: var(--warning-bg); color: var(--warning)} .error {background: var(--error-bg); color: var(--error)}
.empty,.help {padding: 1.1rem; color: var(--muted)} .empty {border: 1px dashed var(--line); border-radius: .65rem}
details summary {cursor: pointer; font-weight: 600; color: var(--ink)}
.chart {width: 100%; min-width: 0; overflow: hidden}
.chart svg,canvas {display: block; max-width: 100%}
#notice:not(:empty) {position: fixed; z-index: 6; bottom: max(1rem,env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: min(90vw,38rem); padding: .8rem 1.15rem; border-radius: .7rem; background: #0b1220; color: #fff; border: 1px solid #425674; box-shadow: var(--shadow)}
#login {min-height: 100vh; display: grid; justify-content: center; align-content: center; padding: 1rem}
.login-panel {width: min(100%,28rem); padding: 2rem; border-radius: 1rem; border: 1px solid var(--line); box-shadow: var(--shadow); background: var(--surface)}
.login-panel .brand {margin-bottom: 1.5rem} .login-panel .brand strong {color: var(--active-text)}
dialog {width: min(92vw,37rem); max-height: 85vh; overflow: auto; color: var(--ink); background: var(--surface); padding: 1.4rem; border: 1px solid var(--line); border-radius: .9rem}
dialog::backdrop {background: rgb(11 18 32 / 60%)}
@media(max-width: 800px) {
  .shell {grid-template-columns:minmax(0,1fr); --workspace-gutter:1rem}
  .sidebar {display: none; position: fixed; inset: 0 auto 0 0; width: min(82vw,260px)}
  .nav-open .sidebar {display: flex}.nav-open #nav-backdrop {display: block !important; position: fixed; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; background: rgb(11 18 32 / 55%); z-index: 3}
  #menu-toggle {display: inline-flex; min-width: 44px; min-height: 44px; font-size: 1.25rem}
  .topbar {min-height: 3.5rem} .page {padding: 1rem}
  .page-header {align-items: flex-start; flex-direction: column; margin-bottom: 1.2rem}
  .metrics {grid-template-columns: repeat(2,minmax(0,1fr))} .metric {padding: .9rem}
  .panel,.card,.column {padding: 1rem} .toolbar :is(button,select),button {min-height: 44px}
  input,textarea,select {font-size: 16px}
  .table-wrap {overscroll-behavior-x: contain} .actions,.toolbar {max-width: 100%}
}
@media(max-width: 360px) {.metrics {grid-template-columns: 1fr}}
@media(prefers-reduced-motion: reduce) {* {scroll-behavior: auto !important}}
.insights,.insight-body {display:grid;gap:1rem;min-width:0}
.insights>button {justify-self:start}
.report-toolbar {justify-content:space-between;align-items:end}
.report-toolbar>label {font-size:.82rem}
.metric-note {display:block;color:var(--muted);font-size:.8rem}
.plot-grid {stroke:var(--line);stroke-dasharray:3 4}
.plot-label {fill:var(--muted);font-family:inherit;font-size:11px}
.plot-area {fill:var(--brand);opacity:.1}
.plot-line {fill:none;stroke:var(--brand);stroke-width:3;stroke-linejoin:round;stroke-linecap:round}
.plot-dot {fill:var(--brand);stroke:var(--surface);stroke-width:1.5}
.trend-card>.chart {width:100%}
.trend-card details>summary {font-size:.85rem;color:var(--muted)}
.schedule-grid {display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr));gap:.8rem}
.check-group {display:flex;flex-wrap:wrap;gap:.35rem 1rem}
.check-group legend {font-weight:600}
.check-group label,form label:has(input[type=checkbox]) {display:flex;align-items:center;gap:.4rem}
.check-group input,form label>input[type=checkbox] {order:-1}
.bar-now {fill:var(--brand)} .bar-before {fill:#0aa7be} .finance-chart {width:100%}
#content>div:not(:empty){display:grid;gap:1rem}
.panel label:has(input[type=checkbox]), fieldset label{display:flex;align-items:center;gap:.5rem}
input[type=checkbox]{width:1.1rem;height:1.1rem;min-height:0;accent-color:var(--brand)}
fieldset{min-width:0;border:1px solid var(--line);border-radius:.65rem;padding:1rem}
@media(max-width: 600px) {
  .plot-label {font-size: 18px}
  .report-toolbar {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:end}
  .report-toolbar>label:first-child,.report-toolbar>div {grid-column:1 / -1}
  .report-toolbar select {width:100%;max-width:100%}
}
.bar-negative {fill:var(--error)}
.saved-chart > .table-wrap {margin:.65rem 0}
.saved-chart svg {width:100%;min-width:3rem;height:1rem}
.saved-chart td:first-child {width:37%}
.saved-chart th:last-child,.saved-chart td:last-child {text-align:right}
@media (max-width:600px) {
 .saved-chart th,.saved-chart td {padding:.5rem .35rem}
 .saved-chart th:nth-child(2) {font-size:0}
}
.help dt{font-weight:650;margin-top:.8rem}
.help dd{margin:.15rem 0 .5rem;color:var(--muted)}
#nav button,.actions button {gap:.55rem}
.lf-icon {flex:none;vertical-align:middle}
progress {width:100%;height:.5rem;accent-color:var(--brand)}
.board {grid-template-columns:repeat(4,minmax(0,1fr))}
.board-item {padding:.7rem 0;border-top:1px solid var(--line);overflow-wrap:anywhere}
.board-item button,.board-item select {max-width:100%}
.status-in_progress {background:#ffdfa3;color:#43300a}
.status-done,.status-processed {background:#c7f3dd;color:#15442c}
.status-rejected {background:#ffdbd8;color:#722c27}
@media(max-width:950px){.board{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:520px){.board{grid-template-columns:1fr}}
button.metric {display:flex;align-items:flex-start;flex-direction:column;text-align:left;white-space:normal;color:var(--ink)}
button.metric:hover {border-color:var(--muted)}
.toolbar select[multiple] {min-width:9rem}
details > summary {cursor:pointer}
button.danger {font-weight:600}
/* A wide results table scrolls inside its frame even inside nested grid items. */
#content,#content>div:not(:empty){grid-template-columns:minmax(0,1fr)}
#content>div>div {min-width:0}
#content>div>button {justify-self:start}
.shell {min-height:100dvh}
td,th,.board-item,p {overflow-wrap:normal;word-break:normal}
.badge,time {white-space:nowrap}
.table-wrap {min-width:0}
.metrics:has(>:nth-child(6):last-child) {grid-template-columns:repeat(3,minmax(0,1fr))}
@media(min-width:1500px){.metrics:has(>:nth-child(6):last-child){grid-template-columns:repeat(6,minmax(0,1fr))}}
@media(max-width:700px){.metrics:has(>:nth-child(6):last-child){grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:360px){.metrics:has(>:nth-child(6):last-child){grid-template-columns:1fr}}
.picker-results {max-height:17rem;overflow:auto}
.picker-results label {display:flex;align-items:baseline;padding:.25rem;gap:.45rem}
fieldset>output {display:block;margin:.4rem 0}

.lead-grid .lead-text {min-width:clamp(16rem,27vw,31rem)}
.lead-grid td:not(.lead-text){padding-inline:.5rem}
.lead-grid th{white-space:nowrap}
.lead-grid .lead-text button{text-align:start}
.metrics + .metrics{margin-top:.55rem}
[hidden]{display:none !important}
.panel,.card {border:2px solid var(--edge);box-shadow:var(--panel-shadow);background:var(--surface)}
.panel :is(fieldset,.panel,.card),.card fieldset,details[open]{background:var(--nested);border:1px solid var(--edge);border-radius:.65rem;padding:.85rem}
.panel fieldset fieldset,.panel details[open] details[open]{background:var(--inset)}
summary{cursor:pointer;list-style-position:inside;font-weight:650;padding:.4rem}
details[open]>summary{color:var(--active-text);border-bottom:1px solid var(--edge);margin-bottom:.7rem}
button[aria-pressed=true]{background:var(--active-text);color:var(--surface);border-color:var(--active-text)}
.trial-result{padding:.8rem;border-inline-start:4px solid var(--success);background:var(--success-bg);margin:.6rem 0}
.trial-result.declined{background:var(--warning-bg);border-color:var(--warning)}
.trial-result dl{display:grid;grid-template-columns:minmax(7rem,1fr) 2fr;gap:.3rem}.trial-result dd{margin:0}
.field-example{font-weight:400;font-size:.86rem;color:var(--muted);margin:.2rem 0 .55rem}

dialog{border:2px solid var(--edge);border-radius:1rem;padding:1.4rem;color:var(--ink);background:var(--surface);max-width:min(28rem,90vw)}dialog::backdrop{background:#10182888}
.order-list {display:grid;gap:.6rem}
.order-detail {border:1px solid var(--edge);border-radius:.7rem;padding:.5rem}
.order-detail>summary {display:grid;grid-template-columns:minmax(10rem,2fr) repeat(4,minmax(0,1fr));gap:.65rem;align-items:center}
.order-detail>summary strong::before {content:"▸ ";color:var(--muted)}
.order-detail[open]>summary strong::before {content:"▾ "}
:where(fieldset,label,details,.panel,.card) {min-inline-size:0}
input:not([type=checkbox]):not([type=radio]),textarea,select {box-sizing:border-box;max-inline-size:100%;min-inline-size:0}
input[type=date] {width:100%;min-width:0;appearance:none}
:focus-visible {outline:3px solid var(--active-text);outline-offset:3px}
@media (hover:hover){summary:hover,button:not(:disabled):hover {box-shadow:inset 0 0 0 1px var(--edge)}}
@media(max-width:800px){
 body.nav-open {overflow:hidden}
 .sidebar {padding-top:max(1rem,env(safe-area-inset-top));padding-bottom:max(1rem,env(safe-area-inset-bottom));overflow-y:auto;overscroll-behavior:contain}
 .sidebar nav{min-height:0;overflow:auto}
 .order-detail>summary {grid-template-columns:repeat(2,minmax(0,1fr));font-size:.95rem}
 .order-detail>summary strong {grid-column:1/-1}
 .operation-table table,.operation-table tbody,.operation-table tr,.operation-table td{display:block;min-width:0;width:100%}
 .operation-table thead{position:absolute;clip-path:inset(100%);width:1px;height:1px;overflow:hidden}
 .operation-table td{display:grid;grid-template-columns:minmax(6rem,.8fr) minmax(0,1fr);gap:.3rem;overflow-wrap:anywhere}
 .operation-table td::before{content:attr(data-label);color:var(--muted)}
 .operation-table tr{margin-block:.8rem;border-block-start:2px solid var(--edge)}
 input,textarea,select{font-size:16px}
}

#nav-close {display:none}
@media(max-width:800px){
 #nav-close{display:block;align-self:flex-end;margin-bottom:.35rem}
 .recent-mobile table,.recent-mobile tbody,.recent-mobile tr,.recent-mobile td{display:block;width:100%;min-width:0}
 .recent-mobile thead{position:absolute;clip-path:inset(100%);width:1px;height:1px;overflow:hidden}
 .recent-mobile tr{padding:.6rem;border:1px solid var(--edge);border-radius:.6rem;margin-bottom:.55rem}
 .recent-mobile td{border:0;padding:.12rem .25rem;white-space:normal}
 .recent-mobile button{text-align:left;white-space:normal}
}

.lead-filters {display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,12rem),1fr));align-items:end}
.lead-filters label {min-width:0}
.lead-filters label :is(input:not([type=checkbox]),select) {width:100%}
#content, #content > div {min-inline-size:0;align-content:start}
@media(max-width:800px){
  .lead-grid {overflow:visible;border:0;background:transparent}
  .lead-grid table,.lead-grid tbody,.lead-grid tr {display:block;width:100%;min-width:0}
  .lead-grid thead {position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
  .lead-grid tr {margin-block:.65rem;padding:.65rem;border:1px solid var(--edge);border-radius:.65rem}
  .lead-grid td,.lead-grid td.lead-text {display:grid;grid-template-columns:minmax(5rem,35%) minmax(0,1fr);gap:.4rem;min-width:0;overflow-wrap:anywhere}
  .lead-grid td::before {content:attr(data-label);color:var(--muted);font-size:.82rem}
  .lead-grid .lead-text button {white-space:normal;overflow-wrap:anywhere}
}

[data-telegram-pilot] { display: grid; gap: 1rem; margin-bottom: 1rem; }
[data-telegram-pilot] .metric { min-width: min(12rem, 100%); }
[data-telegram-pilot] button { margin: .25rem .35rem .25rem 0; }
[data-telegram-pilot] label { display: block; margin: .5rem 0; }
[data-telegram-pilot] label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: .65rem; }
[data-telegram-pilot] label input[type="checkbox"] { width: auto; margin: 0; }
[data-telegram-pilot] code { overflow-wrap: anywhere; }

.tg-help{display:inline-flex;position:relative;vertical-align:middle;margin-inline-start:.4rem}
.tg-help>button{display:inline-grid;place-content:center;border:1px solid currentColor;border-radius:50%;background:transparent;color:inherit;width:1.4rem;height:1.4rem;min-height:0;padding:0;font-size:.85rem}
.tg-help>[role=tooltip]{position:absolute;z-index:12;inset-block-start:100%;inset-inline-start:0;width:min(17rem,65vw);padding:.7rem;background:#22283b;color:#fff;border-radius:.5rem;box-shadow:0 3px 10px #0003;line-height:1.45;font-size:.9rem;font-weight:400;white-space:normal}
@media(max-width:700px){.tg-help>[role=tooltip]{position:fixed;inset:auto 1rem 1rem;width:auto;z-index:100}}
