:root{
  --bg:#06080d;
  --bg-elev:#0b1020;
  --sidebar:#070b14;
  --sidebar-accent:#10182b;
  --surface:#0f1628;
  --surface-2:#131d31;
  --surface-3:#1a253d;
  --card:#0f172a;
  --card-soft:#111c33;
  --text:#eef4ff;
  --text-strong:#ffffff;
  --muted:#93a4bf;
  --border:#23314d;
  --border-soft:#1a2742;
  --input-bg:#0b1220;
  --input-border:#324463;
  --input-text:#f8fbff;
  --primary:#22c55e;
  --primary-hover:#16a34a;
  --primary-contrast:#03140b;
  --secondary:#0f766e;
  --secondary-hover:#115e59;
  --soft-bg:#0d1630;
  --soft-border:#25365a;
  --soft-text:#c4d7ff;
  --danger:#ef4444;
  --danger-hover:#dc2626;
  --danger-soft:#321014;
  --danger-border:#5b2027;
  --warning:#f59e0b;
  --warning-soft:#33240b;
  --warning-border:#5a4419;
  --success:#22c55e;
  --success-soft:#0d2415;
  --success-border:#1e4d2b;
  --info:#38bdf8;
  --info-soft:#082433;
  --info-border:#1d4458;
  --code-bg:#111827;
  --code-text:#c7d2fe;
  --shadow:0 18px 42px rgba(0,0,0,.34);
}

html[data-theme="light"]{
  --bg:#f3f5fb;
  --bg-elev:#eef2f9;
  --sidebar:#0f172a;
  --sidebar-accent:#1e293b;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --surface-3:#eef4fb;
  --card:#ffffff;
  --card-soft:#f8fafc;
  --text:#0f172a;
  --text-strong:#020617;
  --muted:#64748b;
  --border:#dbe2ea;
  --border-soft:#e2e8f0;
  --input-bg:#ffffff;
  --input-border:#cbd5e1;
  --input-text:#111827;
  --primary:#16a34a;
  --primary-hover:#15803d;
  --primary-contrast:#ffffff;
  --secondary:#0f766e;
  --secondary-hover:#115e59;
  --soft-bg:#eff6ff;
  --soft-border:#bfdbfe;
  --soft-text:#1d4ed8;
  --danger:#dc2626;
  --danger-hover:#b91c1c;
  --danger-soft:#fef2f2;
  --danger-border:#fecaca;
  --warning:#d97706;
  --warning-soft:#fef3c7;
  --warning-border:#fde68a;
  --success:#16a34a;
  --success-soft:#ecfdf5;
  --success-border:#a7f3d0;
  --info:#0284c7;
  --info-soft:#e0f2fe;
  --info-border:#bae6fd;
  --code-bg:#eef2ff;
  --code-text:#3730a3;
  --shadow:0 8px 24px rgba(15,23,42,.06);
}

*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:Inter,Arial,sans-serif;
  background:radial-gradient(circle at top left, rgba(34,197,94,.08), transparent 28%), var(--bg);
  color:var(--text);
  line-height:1.45;
}
a{color:var(--info);text-decoration:none}
a:hover{text-decoration:underline}
strong,h1,h2,h3,h4,h5,h6{color:var(--text-strong)}
.shell{display:flex;min-height:100vh;position:relative}
.sidebar{
  width:278px;
  background:linear-gradient(180deg,var(--sidebar),#050814 100%);
  color:var(--text);
  padding:22px;
  display:flex;
  flex-direction:column;
  gap:22px;
  border-right:1px solid rgba(255,255,255,.06);
  transition:width .22s ease,padding .22s ease,opacity .18s ease,transform .22s ease;
  overflow:hidden;
  flex:0 0 auto;
}
.sidebar-head{display:flex;flex-direction:column;gap:16px}
.sidebar-head__row{display:flex;align-items:center;justify-content:space-between;gap:12px}

.sidebar-toggle,.sidebar-reveal{
  appearance:none;border:1px solid rgba(255,255,255,.08);background:rgba(255,255,255,.04);color:var(--text);
  border-radius:12px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;
  transition:.18s ease background,.18s ease transform,.18s ease border-color;
}
.sidebar-toggle{width:42px;height:42px;font-size:26px;line-height:1;flex:0 0 auto}
.sidebar-toggle:hover,.sidebar-reveal:hover{background:rgba(255,255,255,.08);transform:translateY(-1px)}
.sidebar-reveal{
  position:fixed;top:16px;left:16px;z-index:70;padding:11px 14px;font-weight:800;box-shadow:var(--shadow);
}
html[data-theme="light"] .sidebar-toggle,html[data-theme="light"] .sidebar-reveal{background:var(--surface);border-color:var(--border);color:var(--text)}
html[data-theme="light"] .sidebar-toggle:hover,html[data-theme="light"] .sidebar-reveal:hover{background:var(--surface-2)}
body.shell-sidebar-collapsed .sidebar{width:0;padding:0;border-right:none;opacity:0;transform:translateX(-20px);pointer-events:none}
body.shell-sidebar-collapsed .main{padding-left:24px}
body.shell-sidebar-collapsed .sidebar-reveal{display:inline-flex}
.sidebar-reveal[hidden]{display:none!important}

.brand{display:flex;align-items:center;gap:14px}
.brand-badge{
  width:44px;height:44px;border-radius:12px;
  background:linear-gradient(135deg,var(--primary),#14b8a6);
  color:#04130b;display:flex;align-items:center;justify-content:center;font-weight:800;
  box-shadow:0 10px 24px rgba(34,197,94,.25);
}
.nav{display:flex;flex-direction:column;gap:8px}
.nav a{display:block;padding:12px 14px;border-radius:12px;color:#cbd5e1;transition:.18s ease background,.18s ease color,.18s ease transform;font-weight:600}
.nav a.active,.nav a:hover{background:var(--sidebar-accent);color:#fff;text-decoration:none;transform:translateX(2px)}
.sidebar-footer{margin-top:auto;display:flex;flex-direction:column;gap:14px}
.user-box{padding:14px;border:1px solid rgba(255,255,255,.08);border-radius:14px;background:rgba(255,255,255,.03);overflow:hidden}
.main{flex:1;padding:26px 28px;background:var(--bg);min-width:0;transition:padding .22s ease}
.main-auth{display:flex;flex-direction:column}
.topbar-guest{display:flex;justify-content:space-between;align-items:center;margin-bottom:26px;gap:16px}
.topbar-guest>div{display:flex;flex-direction:column;gap:4px}
.card{
  background:linear-gradient(180deg,var(--surface),var(--card));
  border:1px solid var(--border);
  border-radius:18px;
  padding:24px;
  box-shadow:var(--shadow);
}
.auth-wrap,.install-shell{display:flex;align-items:center;justify-content:center;flex:1;padding:32px}
.auth-card,.install-card{width:min(760px,100%)}
.install-card{width:min(920px,100%)}
.page-head{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:20px;gap:16px}
.page-head h1,.card h1,.card h2{margin:0 0 10px}
.muted{color:var(--muted)}
.stats-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px;margin-bottom:18px}
.stat-card{background:linear-gradient(180deg,var(--surface),var(--card-soft));border:1px solid var(--border);border-radius:18px;padding:18px 20px;display:flex;flex-direction:column;gap:8px;box-shadow:var(--shadow)}
.stat-card strong{font-size:34px}
.grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px;margin-bottom:18px}
.form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
.form-grid .full{grid-column:1/-1}
label{display:flex;flex-direction:column;gap:8px;font-weight:600;color:var(--text-strong)}
label input,label select,label textarea{
  width:100%;padding:13px 14px;border:1px solid var(--input-border);border-radius:12px;
  background:var(--input-bg);color:var(--input-text);font:inherit;
}
label input::placeholder,label textarea::placeholder{color:var(--muted)}
label input:focus,label select:focus,label textarea:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 4px rgba(34,197,94,.14)}
.checkbox{flex-direction:row;align-items:center;font-weight:500}
.checkbox input{width:auto}
.btn{
  appearance:none;border:none;border-radius:12px;padding:12px 16px;font:inherit;font-weight:700;cursor:pointer;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:.18s ease transform,.18s ease filter,.18s ease background;
}
.btn:hover{transform:translateY(-1px);filter:brightness(1.03)}
.btn-primary{background:linear-gradient(135deg,var(--primary),#14b8a6);color:var(--primary-contrast)}
.btn-primary:hover{background:linear-gradient(135deg,var(--primary-hover),#0f9f92)}
.btn-danger{background:var(--danger);color:#fff}
.btn-danger:hover{background:var(--danger-hover)}
.btn-outline{background:transparent;color:#e5e7eb;border:1px solid rgba(255,255,255,.16)}
html[data-theme="light"] .btn-outline{color:var(--text);border-color:var(--border)}
.btn-outline:hover{text-decoration:none;background:rgba(255,255,255,.06)}
html[data-theme="light"] .btn-outline:hover{background:var(--surface-2)}
.btn-full{width:100%}
.alert{padding:14px 16px;border-radius:12px;margin-bottom:18px}
.alert-success{background:var(--success-soft);border:1px solid var(--success-border);color:#d1fae5}
.alert-error{background:var(--danger-soft);border:1px solid var(--danger-border);color:#fecaca}
html[data-theme="light"] .alert-success{color:#065f46}
html[data-theme="light"] .alert-error{color:#991b1b}
.table-wrap{overflow:auto}
table{width:100%;border-collapse:collapse}
th,td{text-align:left;padding:12px 10px;border-bottom:1px solid var(--border-soft);vertical-align:top}
thead th{font-size:13px;text-transform:uppercase;color:var(--muted)}
.record{display:flex;justify-content:space-between;gap:16px;align-items:flex-start;padding:14px 0;border-bottom:1px solid var(--border-soft)}
.record:last-child{border-bottom:none;padding-bottom:0}
.record-main{display:flex;flex-direction:column;gap:6px}
.stack{display:flex;flex-direction:column;gap:12px}
.checklist{margin:0;padding-left:18px}
.code-box{padding:14px;border-radius:14px;background:var(--surface-2);border:1px dashed var(--border);margin-bottom:16px}
.break-all{word-break:break-all}
.mini-pre{margin:6px 0 0;padding:8px 10px;background:var(--surface-2);border:1px solid var(--border-soft);border-radius:10px;font-size:12px;white-space:pre-wrap}
.list-tight{margin:8px 0 0;padding-left:18px}
.auth-note{margin-top:16px;padding:14px;border-radius:12px;background:var(--surface-2);border:1px solid var(--border-soft)}
code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code-bg);color:var(--code-text);border-radius:8px;padding:2px 6px}

.twofa-box{margin-top:12px}
.twofa-qr-wrap{display:flex;gap:22px;align-items:flex-start;flex-wrap:wrap}
.twofa-label{font-weight:700;margin-bottom:10px}
.twofa-qr{width:220px;min-height:220px;padding:10px;border:1px solid var(--border);border-radius:16px;background:#fff;display:flex;align-items:center;justify-content:center}
.twofa-qr img,.twofa-qr canvas{display:block;max-width:100%;height:auto}
.twofa-copy{flex:1;min-width:280px;display:flex;flex-direction:column;gap:10px}

.sidebar-banner{padding:14px;border:1px solid rgba(34,197,94,.24);border-radius:14px;background:rgba(34,197,94,.08)}
.sidebar-banner strong{display:block;margin-bottom:6px;color:#fff}
.sidebar-banner a{display:inline-block;margin-top:10px;color:#bbf7d0;font-weight:700}
html[data-theme="light"] .sidebar-banner a{color:#166534}
.card-accent{border-color:rgba(34,197,94,.35);background:linear-gradient(180deg,rgba(34,197,94,.08),var(--surface))}
.card-inline-head{display:flex;justify-content:space-between;align-items:center;gap:16px;margin-bottom:16px}
.card-inline-head.align-start{align-items:flex-start}
.page-head-stack{align-items:flex-start}
.toolbar-row{display:flex;gap:10px;align-items:center}
.toolbar-row.wrap{flex-wrap:wrap}
.btn-soft{background:var(--soft-bg);color:var(--soft-text);border:1px solid var(--soft-border)}
.btn-soft:hover{text-decoration:none;background:var(--surface-3)}
.btn-outline-dark{background:var(--surface-2);color:var(--text);border:1px solid var(--border)}
.btn-outline-dark:hover{text-decoration:none;background:var(--surface-3)}
.btn-small{padding:8px 10px;border-radius:10px;font-size:13px}
.small-text{font-size:12px}.small-stat{font-size:18px!important;line-height:1.2}
.stats-grid-4{grid-template-columns:repeat(4,minmax(0,1fr))}.stats-grid-5{grid-template-columns:repeat(5,minmax(0,1fr))}
.compact-stack{gap:8px}.stack-xl{gap:18px}.filter-grid{align-items:end}
.table-compact td,.table-compact th{padding:10px 8px}.table-title{font-weight:700}.action-stack{display:flex;flex-direction:column;gap:8px;min-width:180px}.inline-form{display:inline-flex}
.status-chip{display:inline-flex;align-items:center;justify-content:center;padding:6px 10px;border-radius:999px;font-size:11px;font-weight:800;letter-spacing:.05em;text-transform:uppercase;border:1px solid var(--border);background:var(--surface-2);color:var(--text);white-space:nowrap}
.status-success,.status-running,.status-ready,.status-info{background:rgba(34,197,94,.14);border-color:rgba(34,197,94,.35);color:#bbf7d0}
.status-error,.status-danger{background:rgba(239,68,68,.14);border-color:rgba(239,68,68,.35);color:#fecaca}
.status-blocked{background:rgba(244,63,94,.16);border-color:rgba(244,63,94,.38);color:#fecdd3}
.status-warning,.status-paused{background:rgba(245,158,11,.16);border-color:rgba(245,158,11,.35);color:#fde68a}
.status-neutral,.status-stopped,.status-idle{background:rgba(148,163,184,.12);border-color:rgba(148,163,184,.24);color:#dbe7ff}
.status-draft{background:rgba(56,189,248,.14);border-color:rgba(56,189,248,.35);color:#bae6fd}
.status-backtesting,.status-finished{background:rgba(167,139,250,.14);border-color:rgba(167,139,250,.35);color:#e9d5ff}
.mode-paper{background:rgba(56,189,248,.14);border-color:rgba(56,189,248,.35);color:#bae6fd}
.mode-live{background:rgba(244,63,94,.14);border-color:rgba(244,63,94,.35);color:#fecdd3}
.mode-backtest{background:rgba(167,139,250,.14);border-color:rgba(167,139,250,.35);color:#e9d5ff}
.mode-draft{background:rgba(148,163,184,.12);border-color:rgba(148,163,184,.24);color:#dbe7ff}
.template-pills{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:10px;width:100%}
.template-pill{display:flex;flex-direction:column;gap:4px;padding:12px 14px;border:1px solid var(--border);border-radius:14px;background:var(--surface-2);color:var(--text)}
.template-pill span{font-size:12px;color:var(--muted)}
.template-pill.active,.template-pill:hover{text-decoration:none;border-color:rgba(34,197,94,.45);background:rgba(34,197,94,.08);box-shadow:0 0 0 1px rgba(34,197,94,.12)}
.builder-form{display:flex;flex-direction:column}.builder-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px}.builder-section{padding:18px;border:1px solid var(--border-soft);border-radius:16px;background:var(--surface-2)}.builder-section h3{margin:0 0 14px}
.checkbox-inline{display:flex;gap:10px;align-items:center;padding-top:10px}.checkbox-inline input{margin:0}
.checklist-danger li{color:#fca5a5}
.field-block.full{grid-column:1/-1}
.status-locked{background:rgba(245,158,11,.16);border-color:rgba(245,158,11,.35);color:#fde68a}

.theme-toggle{
  display:inline-flex;align-items:center;gap:10px;padding:10px 12px;border-radius:12px;
  border:1px solid rgba(255,255,255,.08);background:rgba(255,255,255,.04);color:var(--text);
}
.theme-toggle:hover{background:rgba(255,255,255,.08)}
html[data-theme="light"] .theme-toggle{background:var(--surface);border-color:var(--border);color:var(--text)}
html[data-theme="light"] .theme-toggle:hover{background:var(--surface-2)}
.theme-toggle__icon{font-size:16px;line-height:1}
.theme-toggle__text{font-weight:600}

.mt-16{margin-top:16px}
.mb-18{margin-bottom:18px}

::-webkit-scrollbar{width:11px;height:11px}
::-webkit-scrollbar-track{background:var(--bg-elev)}
::-webkit-scrollbar-thumb{background:var(--border);border-radius:999px;border:2px solid var(--bg-elev)}

.subsection-pills{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-bottom:18px}
.subsection-pill{display:flex;flex-direction:column;gap:4px;padding:14px 16px;border:1px solid var(--border);border-radius:16px;background:var(--surface-2);color:var(--text);transition:.18s ease background,.18s ease border-color,.18s ease transform}
.subsection-pill span{font-size:12px;color:var(--muted)}
.subsection-pill:hover,.subsection-pill.is-active{text-decoration:none;border-color:rgba(34,197,94,.45);background:rgba(34,197,94,.08);box-shadow:0 0 0 1px rgba(34,197,94,.12);transform:translateY(-1px)}
.tag-list{display:flex;flex-wrap:wrap;gap:8px}
.tag-chip{display:inline-flex;align-items:center;justify-content:center;padding:6px 10px;border-radius:999px;border:1px solid var(--border-soft);background:var(--surface-2);color:var(--text);font-size:12px;font-weight:700}
.form-help{display:block;margin-top:6px;color:var(--muted);font-size:12px;line-height:1.45}
.empty-state{padding:16px 18px;border:1px dashed var(--border);border-radius:14px;background:var(--surface-2);color:var(--muted)}
.table-actions{display:flex;flex-wrap:wrap;gap:8px}

@media (max-width:1200px){
  .stats-grid-5{grid-template-columns:repeat(3,minmax(0,1fr))}
  .template-pills{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media (max-width:980px){
  .shell{display:block}
  .sidebar{width:auto;transform:none!important;opacity:1!important;pointer-events:auto!important}
  .stats-grid,.grid-2,.form-grid,.stats-grid-4,.stats-grid-5,.builder-grid,.template-pills,.subsection-pills{grid-template-columns:1fr}
  .main{padding:18px}
  .card-inline-head{flex-direction:column;align-items:flex-start}
  .action-stack{min-width:0}
  .topbar-guest{flex-direction:column;align-items:flex-start}
}

@media (max-width:980px){
  .sidebar-reveal{top:12px;left:12px}
  body.shell-sidebar-collapsed .sidebar{width:auto;height:0}
}


/* v4.5 shell sidebar reveal refinement */
.sidebar-reveal{
  top:16px;
  left:16px;
  bottom:auto;
  min-width:46px;
  width:46px;
  height:46px;
  padding:0;
  border-radius:12px;
  font-size:18px;
  font-weight:800;
  box-shadow:0 12px 30px rgba(2,6,23,.38);
}
.sidebar-reveal__icon{font-size:22px;line-height:1}
.sidebar-reveal__text{display:none}
body.shell-sidebar-collapsed .main{padding-left:86px}
@media (max-width: 960px){
  .sidebar-reveal{top:14px;left:14px;bottom:auto;width:44px;height:44px;padding:0;border-radius:12px}
  body.shell-sidebar-collapsed .main{padding-left:76px}
}
