/* ============================================================================
   DeviTrade cabinet — theme. Dark by default; light via [data-theme="light"].
   Palette lifted from bybit_analysis/app.py and extended.
   ============================================================================ */

:root,
:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --card: #1c2330;
  --card-2: #11161f;
  --border: #2d3748;
  --border-soft: #21262d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #1fb6a3;
  --accent-dim: rgba(31, 182, 163, 0.15);
  --gold: #e0a64a;
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.14);
  --red: #f85149;
  --red-dim: rgba(248, 81, 73, 0.14);
  --yellow: #d29922;
  --yellow-dim: rgba(210, 153, 34, 0.14);
  --row-hover: rgba(255, 255, 255, 0.04);
  --row-stripe: rgba(255, 255, 255, 0.018);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #f3f5f8;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f4f6f9;
  --border: #d8dee4;
  --border-soft: #e6eaef;
  --text: #1f2328;
  --muted: #636c76;
  --accent: #0f9486;
  --accent-dim: rgba(15, 148, 134, 0.12);
  --gold: #b9791a;
  --green: #1a7f37;
  --green-dim: rgba(26, 127, 55, 0.10);
  --red: #cf222e;
  --red-dim: rgba(207, 34, 46, 0.10);
  --yellow: #9a6700;
  --yellow-dim: rgba(154, 103, 0, 0.12);
  --row-hover: rgba(0, 0, 0, 0.035);
  --row-stripe: rgba(0, 0, 0, 0.015);
  --shadow: 0 6px 20px rgba(140, 149, 159, 0.2);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── App layout ──────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px; font-weight: 800; font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 12px var(--accent); }
.brand .accent { color: var(--accent); }
.brand-mark { width: 30px; height: 30px; display: block; flex-shrink: 0; }
.login-logo { width: 132px; height: 132px; display: block; margin: 2px auto 12px; }

/* refresh button spin state */
.icon-btn .ri { display: inline-block; line-height: 1; }
.icon-btn.loading { pointer-events: none; opacity: 0.75; }
.icon-btn.loading .ri { animation: spin 0.7s linear infinite; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px; color: var(--muted);
  font-weight: 600; font-size: 0.9rem; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--row-hover); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-dim); color: var(--accent); }
.nav a .ico { width: 18px; text-align: center; font-size: 1rem; }
.sidebar .spacer { flex: 1; }
.sidebar-footer { padding: 12px 14px 18px; border-top: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 8px; }
.user-chip { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.user-chip .av { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-dim);
  color: var(--accent); display: grid; place-items: center; font-weight: 700; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); z-index: 5;
}
.page-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.content { padding: 24px 28px 56px; max-width: 1320px; width: 100%; }

/* ── Buttons / controls ──────────────────────────────────────────────────── */
.btn {
  padding: 9px 16px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-elev); color: var(--text); font-weight: 600; font-size: .85rem;
  cursor: pointer; transition: opacity .12s, transform .08s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%;
  padding: 11px; font-size: .95rem; }
.btn-primary:hover { opacity: .9; border-color: var(--accent); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 1.05rem;
  display: grid; place-items: center; transition: border-color .12s, background .12s;
}
.icon-btn:hover { border-color: var(--accent); }
.input, input[type=text], input[type=password], input[type=date], select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--card-2); color: var(--text); font-size: .9rem; outline: none;
  transition: border-color .12s;
}
.input:focus, input:focus, select:focus { border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }

/* ── Cards / KPIs ────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px;
}
.card.tight { padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title { font-size: .95rem; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { font-size: .78rem; color: var(--muted); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; right: -20px; top: -20px; width: 70px; height: 70px;
  border-radius: 50%; background: var(--accent-dim); opacity: .5; }
.kpi .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .delta { font-size: .82rem; font-weight: 600; }
.value.pos, .delta.pos, .pos { color: var(--green); }
.value.neg, .delta.neg, .neg { color: var(--red); }
.value.accent { color: var(--accent); }
.muted { color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) { .grid-2, .grid-2.even { grid-template-columns: 1fr; } }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  padding: 11px 14px; text-align: left; font-size: .7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border);
  background: var(--card-2); white-space: nowrap; position: sticky; top: 0;
}
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--row-stripe); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--row-hover); }
.sym { font-weight: 700; letter-spacing: .01em; }
.mono { font-family: 'Consolas', 'Menlo', monospace; font-size: .82rem; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: .72rem; font-weight: 700; }
.badge-long, .badge-buy { background: var(--green-dim); color: var(--green); }
.badge-short, .badge-sell { background: var(--red-dim); color: var(--red); }
.badge-open { background: var(--accent-dim); color: var(--accent); }
.badge-parent { background: var(--accent-dim); color: var(--accent); }
.badge-child { background: var(--yellow-dim); color: var(--yellow); }
.badge-neutral { background: var(--row-hover); color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 20px;
  font-size: .76rem; font-weight: 700; background: var(--row-hover); color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on { background: var(--green-dim); color: var(--green); } .pill.on .dot { background: var(--green); }
.pill.off { background: var(--red-dim); color: var(--red); } .pill.off .dot { background: var(--red); }
.pill.warn { background: var(--yellow-dim); color: var(--yellow); } .pill.warn .dot { background: var(--yellow); }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-box { width: 100%; height: 300px; position: relative; }
.chart-box canvas { width: 100% !important; height: 100% !important; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: .78rem; color: var(--muted); margin-top: 10px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: .78rem; box-shadow: var(--shadow); transform: translate(-50%, -120%);
  white-space: nowrap; opacity: 0; transition: opacity .08s; z-index: 9; }

/* ── States / banners ────────────────────────────────────────────────────── */
.banner { padding: 11px 15px; border-radius: 9px; font-size: .85rem; font-weight: 600; margin-bottom: 16px; }
.banner.info { background: var(--accent-dim); color: var(--accent); }
.banner.warn { background: var(--yellow-dim); color: var(--yellow); }
.banner.err { background: var(--red-dim); color: var(--red); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--card-2) 25%, var(--row-hover) 37%, var(--card-2) 63%);
  background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 6px; color: transparent; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ── Detail drawer (trade box) ───────────────────────────────────────────── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none;
  transition: opacity .15s; z-index: 40; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 94vw;
  background: var(--bg-elev); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .18s ease; z-index: 41; overflow-y: auto; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; background: var(--bg-elev); }
.drawer-body { padding: 18px 20px; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border-soft); font-size: .85rem; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border-soft);
  border-radius: 16px; padding: 32px 30px; box-shadow: var(--shadow); }
.login-card .brand { padding: 0 0 6px; font-size: 1.5rem; }
.login-sub { color: var(--muted); font-size: .85rem; margin-bottom: 24px; }
.login-card label.field { margin-bottom: 16px; }
.login-err { background: var(--red-dim); color: var(--red); padding: 10px 13px; border-radius: 9px;
  font-size: .84rem; font-weight: 600; margin-bottom: 16px; }
.login-foot { margin-top: 20px; text-align: center; color: var(--muted); font-size: .76rem; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    overflow-x: auto; }
  .sidebar .spacer, .sidebar-footer { display: none; }
  .nav { flex-direction: row; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 14px 16px; }
}
