/* ============================================================================
   AlgoTrade Studio — Design System
   A modern, professional "trading terminal" UI. Dark-first, light supported.
   Pure CSS, no framework. All theming via CSS custom properties on :root.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Brand */
  --brand-1: #16d4c8;   /* electric teal */
  --brand-2: #3b82f6;   /* blue */
  --brand-grad: linear-gradient(135deg, #16d4c8 0%, #3b82f6 100%);

  /* Semantic market colors */
  --buy:  #22c55e;      /* green / long */
  --sell: #f43f5e;      /* red / short */
  --warn: #f59e0b;
  --info: #38bdf8;

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.20);
  --shadow-2: 0 8px 24px rgba(0,0,0,.28);
  --shadow-3: 0 20px 60px rgba(0,0,0,.45);
  --ring: 0 0 0 3px rgba(22,212,200,.28);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  --sidebar-w: 244px;
  --topbar-h: 62px;
  --transition: 160ms cubic-bezier(.4,0,.2,1);
}

/* Dark theme (default) */
:root, :root[data-theme="dark"] {
  --bg:        #0b1017;
  --bg-2:      #0f1621;
  --panel:     #131c29;
  --panel-2:   #17212f;
  --panel-hi:  #1d2a3a;
  --border:    #223247;
  --border-hi: #2d4260;
  --text:      #e8eef6;
  --text-2:    #9fb0c3;
  --text-3:    #6b7d92;
  --overlay:   rgba(4,8,13,.66);
  --glass:     rgba(19,28,41,.72);
}

/* Light theme */
:root[data-theme="light"] {
  --bg:        #eef2f7;
  --bg-2:      #e6ecf3;
  --panel:     #ffffff;
  --panel-2:   #f6f9fc;
  --panel-hi:  #eef3f9;
  --border:    #d8e1ec;
  --border-hi: #c3d1e0;
  --text:      #0f1b2d;
  --text-2:    #47586c;
  --text-3:    #7688a0;
  --overlay:   rgba(20,32,48,.42);
  --glass:     rgba(255,255,255,.82);
  --shadow-2: 0 8px 24px rgba(30,50,80,.12);
  --shadow-3: 0 20px 60px rgba(30,50,80,.20);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
::selection { background: rgba(22,212,200,.30); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; }
.gap-1 { gap: 6px; } .gap-2 { gap: 12px; } .gap-3 { gap: 18px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.spread { display:flex; align-items:center; justify-content:space-between; }
.stack { display:flex; flex-direction:column; }
.pos { color: var(--buy); } .neg { color: var(--sell); }
.text-sm { font-size: 12.5px; } .text-lg { font-size: 16px; }
.mt-1{margin-top:8px}.mt-2{margin-top:16px}.mt-3{margin-top:24px}
.mb-1{margin-bottom:8px}.mb-2{margin-bottom:16px}.mb-3{margin-bottom:24px}

/* ---------- App shell ---------- */
#app { min-height: 100%; }

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.shell.collapsed { grid-template-columns: 72px 1fr; }

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 11px;
  height: var(--topbar-h); padding: 0 18px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: var(--brand-grad); display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(22,212,200,.35);
  color: #04121a;
}
.brand .logo svg { width: 20px; height: 20px; }
.brand .name { font-weight: 750; font-size: 15.5px; letter-spacing: .2px; white-space: nowrap; }
.brand .name span { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.shell.collapsed .brand .name, .shell.collapsed .nav-label, .shell.collapsed .nav-section-t { display: none; }

.nav { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }
.nav-section-t { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-3); padding: 16px 12px 7px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 10px; color: var(--text-2);
  cursor: pointer; margin: 2px 0; font-weight: 550; font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
  position: relative; white-space: nowrap;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-hi); color: var(--text); }
.nav-item.active::before {
  content:""; position:absolute; left:-12px; top:50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--brand-1);
}
.shell.collapsed .nav-item { justify-content: center; padding: 10px; }

.sidebar .side-foot { padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* Topbar */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: var(--glass); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 17px; font-weight: 700; }
.topbar .crumb { color: var(--text-3); font-size: 12.5px; margin-top: -2px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text-2); display: grid; place-items: center;
  cursor: pointer; transition: all var(--transition);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-hi); background: var(--panel-hi); }
.icon-btn svg { width: 18px; height: 18px; }

.content { padding: 24px 26px 60px; max-width: 1360px; width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.card.pad { padding: 20px; }
.card-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content: space-between; gap: 12px; }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 680; }
.card-b { padding: 20px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px){ .grid.cols-4{grid-template-columns:repeat(2,1fr)} .grid.cols-3{grid-template-columns:repeat(2,1fr)} }
@media (max-width: 680px){ .grid.cols-2,.grid.cols-3,.grid.cols-4{grid-template-columns:1fr} }

/* Stat tile */
.stat { position: relative; overflow: hidden; }
.stat .stat-top { display:flex; align-items:center; justify-content: space-between; }
.stat .stat-ic { width: 40px; height: 40px; border-radius: 11px; display:grid; place-items:center; background: var(--panel-hi); color: var(--brand-1); }
.stat .stat-ic svg { width: 20px; height: 20px; }
.stat .stat-v { font-size: 27px; font-weight: 760; margin: 14px 0 2px; letter-spacing: -.5px; }
.stat .stat-l { color: var(--text-2); font-size: 12.5px; font-weight: 550; }
.stat .stat-d { font-size: 12px; margin-top: 6px; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13.5px;
  cursor: pointer; transition: all var(--transition); white-space: nowrap; font-family: inherit;
}
.btn:hover { border-color: var(--border-hi); background: var(--panel-hi); }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand-grad); border: none; color: #04121a; font-weight: 700; box-shadow: 0 6px 18px rgba(22,212,200,.28); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.buy { background: var(--buy); border: none; color: #04140a; font-weight: 700; }
.btn.sell { background: var(--sell); border: none; color: #fff; font-weight: 700; }
.btn.danger { background: transparent; border-color: rgba(244,63,94,.5); color: var(--sell); }
.btn.danger:hover { background: rgba(244,63,94,.12); }
.btn.ghost { background: transparent; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 8px; }
.btn.lg { height: 44px; padding: 0 22px; font-size: 15px; }
.btn.block { width: 100%; }
.btn-group { display: inline-flex; gap: 8px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  border-radius: 100px; font-size: 11.5px; font-weight: 650; letter-spacing: .2px;
  background: var(--panel-hi); color: var(--text-2); border: 1px solid var(--border);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--buy);  background: rgba(34,197,94,.12);  border-color: rgba(34,197,94,.3); }
.badge.red   { color: var(--sell); background: rgba(244,63,94,.12);  border-color: rgba(244,63,94,.3); }
.badge.amber { color: var(--warn); background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.3); }
.badge.blue  { color: var(--info); background: rgba(56,189,248,.12); border-color: rgba(56,189,248,.3); }
.badge.teal  { color: var(--brand-1); background: rgba(22,212,200,.12); border-color: rgba(22,212,200,.3); }
.badge.grey  { color: var(--text-3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 620; color: var(--text-3); font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--panel-2); white-space: nowrap;
  position: sticky; top: 0;
}
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr { transition: background var(--transition); }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl.rows-click tbody tr { cursor: pointer; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }
.field .err { font-size: 11.5px; color: var(--sell); margin-top: 6px; }
.input, .select, textarea.input {
  width: 100%; height: 42px; padding: 0 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
  font-size: 14px; font-family: inherit; transition: border var(--transition), box-shadow var(--transition);
  outline: none;
}
textarea.input { height: auto; padding: 11px 13px; resize: vertical; min-height: 90px; }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--brand-1); box-shadow: var(--ring); }
.input::placeholder { color: var(--text-3); }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7d92' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px; cursor: pointer; }
.input-group { display: flex; gap: 10px; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); }
.input-icon .input { padding-left: 40px; }
.checkbox { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; font-size: 13.5px; }
.checkbox input { width: 17px; height: 17px; accent-color: var(--brand-1); }

/* Segmented control */
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: transparent; color: var(--text-2); padding: 7px 15px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; font-family: inherit; transition: all var(--transition); }
.seg button.active { background: var(--panel-hi); color: var(--text); box-shadow: var(--shadow-1); }
.seg button.buy.active { background: var(--buy); color: #04140a; }
.seg button.sell.active { background: var(--sell); color: #fff; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
@media (max-width: 900px){ .auth-wrap { grid-template-columns: 1fr; } .auth-brandside { display: none; } }
.auth-brandside {
  background: radial-gradient(1200px 600px at 20% 10%, rgba(22,212,200,.16), transparent 60%),
              radial-gradient(900px 500px at 90% 90%, rgba(59,130,246,.18), transparent 55%),
              var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 54px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.auth-brandside .bs-top { display: flex; align-items: center; gap: 12px; }
.auth-brandside h1 { font-size: 40px; line-height: 1.12; margin: 0 0 16px; letter-spacing: -1px; }
.auth-brandside h1 span { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.auth-brandside p.lead { color: var(--text-2); font-size: 15.5px; max-width: 420px; }
.auth-feats { display: flex; flex-direction: column; gap: 14px; margin-top: 26px; }
.auth-feats .f { display: flex; gap: 12px; align-items: flex-start; }
.auth-feats .f .fi { width: 34px; height: 34px; border-radius: 9px; background: var(--panel); border: 1px solid var(--border); display:grid; place-items:center; color: var(--brand-1); flex-shrink: 0; }
.auth-feats .f .fi svg { width: 17px; height: 17px; }
.auth-formside { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.4px; }
.auth-card .sub { color: var(--text-2); margin-bottom: 26px; }
.auth-alt { text-align: center; margin-top: 22px; color: var(--text-2); font-size: 13.5px; }
.auth-alt a { color: var(--brand-1); font-weight: 600; }
.grid-fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* Password strength meter */
.pwmeter { height: 5px; border-radius: 6px; background: var(--border); overflow: hidden; margin-top: 8px; }
.pwmeter > div { height: 100%; width: 0; transition: width var(--transition), background var(--transition); border-radius: 6px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 280px; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-left: 3px solid var(--brand-1); border-radius: 11px; padding: 13px 15px; box-shadow: var(--shadow-3);
  display: flex; gap: 11px; align-items: flex-start; animation: toastIn .25s ease;
}
.toast.ok  { border-left-color: var(--buy); }
.toast.err { border-left-color: var(--sell); }
.toast.warn{ border-left-color: var(--warn); }
.toast .ti { flex-shrink: 0; margin-top: 1px; } .toast .ti svg { width: 18px; height: 18px; }
.toast.ok .ti{color:var(--buy)} .toast.err .ti{color:var(--sell)} .toast.warn .ti{color:var(--warn)} .toast.info .ti{color:var(--info)}
.toast .tt { font-weight: 640; font-size: 13.5px; }
.toast .tm { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(3px); z-index: 150; display: grid; place-items: center; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal { width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); animation: modalIn .2s cubic-bezier(.2,.9,.3,1); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 780px; }
@keyframes modalIn { from { opacity:0; transform: translateY(14px) scale(.98) } to { opacity:1; transform:none } }
.modal-h { padding: 18px 22px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content: space-between; }
.modal-h h3 { margin: 0; font-size: 16.5px; }
.modal-b { padding: 22px; overflow-y: auto; }
.modal-f { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 54px 20px; color: var(--text-3); }
.empty .ei { width: 52px; height: 52px; border-radius: 14px; background: var(--panel-2); display: grid; place-items: center; margin: 0 auto 16px; color: var(--text-3); }
.empty .ei svg { width: 26px; height: 26px; }
.empty h4 { margin: 0 0 6px; color: var(--text-2); font-size: 15px; }

.spinner { width: 20px; height: 20px; border: 2.5px solid var(--border-hi); border-top-color: var(--brand-1); border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg) } }
.loading-full { display: grid; place-items: center; padding: 70px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); font-weight: 550; }
.kv dd { margin: 0; font-weight: 550; }

.pill-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.pill-tabs button { border: none; background: transparent; color: var(--text-2); padding: 11px 15px; cursor: pointer; font-weight: 600; font-size: 13.5px; font-family: inherit; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.pill-tabs button.active { color: var(--text); border-bottom-color: var(--brand-1); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.4px; }
.page-head p { margin: 0; color: var(--text-2); font-size: 13.5px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-grad); color: #04121a; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.avatar.sm { width: 28px; height: 28px; font-size: 11.5px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }

.dropdown { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-3); padding: 6px; z-index: 60; animation: modalIn .15s ease; }
.menu .mi { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.menu .mi:hover { background: var(--panel-hi); color: var(--text); }
.menu .mi svg { width: 16px; height: 16px; }
.menu .sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu .mi.danger { color: var(--sell); }

.code-inline { font-family: var(--font-mono); background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; font-size: 12.5px; }
.copy-box { display:flex; align-items:center; gap: 8px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px 4px 4px 13px; }
.copy-box code { flex: 1; font-family: var(--font-mono); font-size: 12.5px; overflow-x: auto; white-space: nowrap; color: var(--text-2); }

.log-line { font-family: var(--font-mono); font-size: 12px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.log-line .lvl { display: inline-block; width: 62px; font-weight: 700; }
.lvl.ERROR,.lvl.CRITICAL{color:var(--sell)} .lvl.WARNING{color:var(--warn)} .lvl.INFO{color:var(--info)} .lvl.DEBUG{color:var(--text-3)}

/* Mobile sidebar */
.sb-backdrop { display: none; }
@media (max-width: 860px){
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 120; width: var(--sidebar-w); transform: translateX(-100%); transition: transform var(--transition); }
  .shell.mobile-open .sidebar { transform: none; }
  .shell.mobile-open .sb-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 110; }
  .content { padding: 18px; }
}
.menu-toggle { display: none; }
@media (max-width: 860px){ .menu-toggle { display: grid; } }
