/* ============================================================
   AionVex Dashboard — Design System & Layout
   Plain CSS, no framework — shared-hosting friendly
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  /* Palette — dark trading theme */
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-hover: #1c2330;
  --border: #2a3140;
  --text: #e6e9ef;
  --text-dim: #9aa4b2;
  --text-faint: #6b7585;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --purple: #a78bfa;

  --green-bg: rgba(34, 197, 94, 0.12);
  --red-bg: rgba(239, 68, 68, 0.12);
  --yellow-bg: rgba(234, 179, 8, 0.12);
  --accent-bg: rgba(59, 130, 246, 0.12);

  --sidebar-w: 240px;
  --header-h: 60px;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
}

.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
.brand-name span { color: var(--accent); }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-faint);
  padding: 14px 12px 6px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}

.nav-item a:hover { background: var(--bg-hover); color: var(--text); }

.nav-item a.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon { width: 18px; text-align: center; font-size: 15px; }

/* Collapsible sub-menus (accordion) */
.nav-item.has-sub > a { cursor: pointer; }
.nav-arrow {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-faint);
  transition: transform 0.2s ease;
}
.nav-item.has-sub.open > a > .nav-arrow { transform: rotate(90deg); }
.nav-sub { display: none; padding-left: 16px; }
.nav-item.has-sub.open > .nav-sub { display: block; }
.nav-sub .nav-item a { font-size: 13px; padding: 7px 12px; }
.nav-bullet {
  width: 18px;
  text-align: center;
  font-size: 5px;
  color: var(--text-faint);
}
.nav-sub .nav-item a.active .nav-bullet,
.nav-item.has-sub > a:hover .nav-arrow { color: var(--accent); }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
}

/* Main area */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Header */
.header {
  height: var(--header-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none; border: none;
  color: var(--text); font-size: 20px;
  cursor: pointer;
}

.page-title { font-size: 16px; font-weight: 600; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.conn-status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-dim);
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
}

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot.warn { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot.unknown { background: var(--text-faint); }

/* Persistent system-health pill (header) — colour follows worst node state */
.sys-health-pill { text-decoration: none; cursor: pointer; transition: border-color .15s, color .15s; }
.sys-health-pill:hover { border-color: var(--text-dim); }
.sys-health-pill.state-online  { border-color: rgba(34,197,94,0.4);  color: var(--green); }
.sys-health-pill.state-warn    { border-color: rgba(234,179,8,0.45); color: var(--yellow); }
.sys-health-pill.state-offline { border-color: rgba(239,68,68,0.5);  color: var(--red); animation: killPulse 2s infinite; }
.sys-health-pill.state-unknown { color: var(--text-dim); }

.kill-switch {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 7px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s;
}
.kill-switch:hover { background: rgba(239, 68, 68, 0.25); }
.kill-switch.active { background: var(--red); color: #fff; border-color: var(--red); animation: killPulse 1.6s infinite; }
@keyframes killPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
}

.user-chip {
  display: flex; align-items: center; gap: 9px;
  cursor: pointer;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-chip .u-name { font-size: 13px; font-weight: 600; }
.user-chip .u-role { font-size: 11px; color: var(--text-faint); }

/* Content */
.content { padding: 24px; }

/* ---------- Components ---------- */

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}

.stat-value { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }

.stat-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; }

/* Panels */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-title { font-size: 14px; font-weight: 600; }

.panel-link { font-size: 12px; color: var(--accent); }
.panel-link:hover { text-decoration: underline; }

.panel-body { padding: 0; }
.panel-body.padded { padding: 20px; }

/* Grid helpers */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.num { font-family: var(--mono); }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge.buy    { background: var(--green-bg);  color: var(--green); }
.badge.sell   { background: var(--red-bg);    color: var(--red); }
.badge.pending{ background: var(--yellow-bg); color: var(--yellow); }
.badge.info   { background: var(--accent-bg); color: var(--accent); }
.badge.error  { background: var(--red-bg);    color: var(--red); }
.badge.ok     { background: var(--green-bg);  color: var(--green); }
.badge.muted  { background: rgba(154,164,178,0.12); color: var(--text-dim); }

/* Log list */
.log-list { padding: 6px 0; }
.log-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 9px 20px;
  font-size: 12.5px;
}
.log-row:hover { background: var(--bg-hover); }
.log-time { color: var(--text-faint); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; padding-top: 2px; }
.log-msg { color: var(--text-dim); }

/* ---------- Charts ---------- */
:root {
  /* validated dark-mode chart palette (dataviz reference instance) */
  --chart-s1: #3987e5;   /* series 1 — blue  */
  --chart-s2: #199e70;   /* series 2 — aqua  */
  --chart-good: #0ca30c; /* candle up   */
  --chart-crit: #d03b3b; /* candle down */
  --chart-grid: #2a3140;
  --chart-axis: #6b7585;
}

.chart-box { padding: 16px 20px 8px; }

.chart-legend {
  display: flex; gap: 18px;
  padding: 0 20px 4px;
  font-size: 12px; color: var(--text-dim);
}
.chart-legend .lg-item { display: flex; align-items: center; gap: 7px; }
.chart-legend .swatch { width: 14px; height: 3px; border-radius: 2px; }

.chart-svg { width: 100%; height: auto; display: block; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  z-index: 20;
  white-space: nowrap;
  display: none;
}
.chart-tooltip .tt-date { color: var(--text-faint); font-size: 11px; margin-bottom: 5px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.chart-tooltip .tt-row .swatch { width: 8px; height: 8px; border-radius: 2px; }
.chart-tooltip .tt-val { font-family: var(--mono); margin-left: auto; padding-left: 14px; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: end;
}

.field label {
  display: block;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--font);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { font-family: var(--mono); resize: vertical; min-height: 90px; }

/* Filter bar above tables */
.filter-bar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.filter-bar .field { min-width: 140px; margin: 0; }

/* Tabs */
.tabs {
  display: flex; gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none; border: none;
  color: var(--text-dim);
  font-size: 13px; font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

/* Live chart page */
.live-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.live-toolbar select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
}
.live-price {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
}
.live-canvas-wrap {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#liveChart { display: block; width: 100%; height: 460px; }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(59,130,246,0.08), transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(167,139,250,0.06), transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
}

.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 8px;
}
.login-brand .brand-logo { width: 42px; height: 42px; font-size: 20px; }
.login-brand .brand-name { font-size: 24px; }

.login-sub {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  margin-bottom: 28px;
}

.login-card .field { margin-bottom: 16px; }

.captcha-row { display: flex; gap: 10px; align-items: stretch; }
.captcha-row input { flex: 1; }
.captcha-img {
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
}
.captcha-hint { font-size: 10.5px; color: var(--text-faint); margin-top: 5px; }

.login-error {
  display: none;
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.35);
  color: var(--red);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 16px;
}

.btn-block { width: 100%; padding: 12px; font-size: 14px; }

.login-footer {
  text-align: center;
  margin-top: 22px;
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  z-index: 200;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  color: var(--text-dim); font-size: 20px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.4); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }

.modal .form-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.modal .field { margin-bottom: 0; }
.modal .field.full { grid-column: 1 / -1; }

.perm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-top: 4px;
}
.perm-grid label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-dim);
  cursor: pointer;
}
.perm-grid input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.row-actions { display: flex; gap: 6px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--green);
  color: var(--green);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  z-index: 300;
  display: none;
}
.toast.error { border-color: var(--red); color: var(--red); }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
  .header { padding: 0 16px; }
  .content { padding: 16px; }
  .user-chip .u-meta { display: none; }
}
