/* ==========================================================================
   BTC Trading Simulator — base styles, layout and shared components
   ========================================================================== */
:root {
  --bg: #0a1020;
  --bg-2: #0e1629;
  --card: #121c33;
  --card-2: #172340;
  --border: #22314f;
  --border-strong: #2e4068;
  --text: #eef3fb;
  --muted: #8d9dba;
  --faint: #5f6f8f;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.14);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.14);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.15);
  --amber: #f5b301;
  --amber-dim: rgba(245, 179, 1, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --sidebar-w: 248px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: #7fb0ff; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h2 { font-size: 1.02rem; }
code, .mono { font-family: var(--mono); }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.icon-lg { width: 28px; height: 28px; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.nowrap { white-space: nowrap; }
.pos, .up { color: var(--green); }
.neg, .down { color: var(--red); }
[hidden] { display: none !important; }

/* ---------- Simulation banner ---------- */
.sim-banner {
  position: sticky; top: 0; z-index: 60;
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; justify-content: center;
  padding: 7px 16px; text-align: center;
  background: repeating-linear-gradient(-45deg, #f5b301 0 14px, #e2a500 14px 28px);
  color: #1b1400; font-size: 0.82rem; letter-spacing: 0.04em;
}
.sim-banner strong { font-weight: 800; }
.sim-banner-sub { font-weight: 500; opacity: 0.85; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: calc(100vh - 34px);
  background: linear-gradient(to right, var(--bg-2) var(--sidebar-w), var(--bg) var(--sidebar-w)); }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--bg-2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 34px; height: calc(100vh - 34px); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 16px; }
.brand-icon { color: var(--amber); }
.brand-name { font-weight: 750; letter-spacing: 0.01em; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; }
.nav-section { margin: 14px 10px 4px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 520; font-size: 0.93rem; border: 0; background: none;
  width: 100%; text-align: left; cursor: pointer; font-family: inherit;
}
.nav-link:hover { background: var(--card); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--blue-dim); color: #cfe0ff; }
.nav-link.active .icon { color: var(--blue); }
.nav-count { margin-left: auto; background: var(--amber); color: #1b1400; border-radius: 99px; font-size: 0.72rem; padding: 0 7px; font-weight: 700; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 10px 16px; }
.who { display: flex; align-items: center; gap: 10px; padding: 4px 8px 10px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--blue-dim); color: #cfe0ff; display: grid; place-items: center; font-weight: 700; flex: none; }
.who-text { min-width: 0; }
.who-name { font-weight: 600; font-size: 0.9rem; }
.who-email { font-size: 0.76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 28px;
  border-bottom: 1px solid var(--border); background: rgba(10, 16, 32, 0.85);
  position: sticky; top: 34px; z-index: 30; backdrop-filter: blur(8px);
}
.page-title { font-size: 1.25rem; display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1440px; width: 100%; }
.topbar .nav-toggle { display: none; }
.nav-backdrop { display: none; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-header.wrap { flex-wrap: wrap; }
.link-sm { font-size: 0.86rem; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat-grid.compact .stat { background: var(--card-2); }
.stat-grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; min-width: 0; height: 100%;
}
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.82rem; font-weight: 550; }
.stat-label .icon { width: 16px; height: 16px; color: var(--faint); }
.stat-value { font-size: 1.42rem; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.stat-up .stat-value { color: var(--green); }
.stat-down .stat-value { color: var(--red); }
.stat-warn .stat-value { color: var(--amber); }
.stat-link { color: inherit; display: block; }
.stat-link:hover { text-decoration: none; }
.stat-link:hover .stat { border-color: var(--border-strong); background: var(--card-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer; color: #fff;
  background: var(--card-2); line-height: 1.2; white-space: nowrap; text-decoration: none;
  transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn:focus-visible, .form-control:focus-visible, .tab:focus-visible, .seg-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn[disabled], .btn.is-disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--blue); }
.btn-buy { background: var(--green); color: #04220f; }
.btn-sell { background: var(--red); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--card-2); }
.btn-danger-text { color: #ff8a8a; }
.btn-sm { padding: 7px 12px; font-size: 0.84rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); width: 38px; height: 38px; display: inline-grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--card-2); }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 15px; }
.form-label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 6px; color: #d6e0f0; }
.form-control {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-2); color: var(--text);
  font: inherit; font-size: 0.95rem;
}
.form-control::placeholder { color: var(--faint); }
.form-control:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-dim); }
select.form-control { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea.form-control { resize: vertical; min-height: 70px; }
.has-error .form-control { border-color: var(--red); }
.field-error { color: #ff8a8a; font-size: 0.82rem; margin: 5px 0 0; }
.form-help { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }
.checkbox { display: flex; gap: 8px; align-items: center; margin: 4px 0 16px; color: var(--muted); font-size: 0.9rem; }
.checkbox input { accent-color: var(--blue); width: 16px; height: 16px; }
.notice {
  display: flex; gap: 10px; align-items: flex-start; background: var(--amber-dim); color: #ffe08a;
  border: 1px solid rgba(245, 179, 1, 0.3); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 0.85rem; margin: 0 0 16px;
}
.notice .icon { margin-top: 2px; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .form-control { flex: 1; }
.inline-form { display: inline; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- Alerts ---------- */
.flashes { display: flex; flex-direction: column; gap: 10px; }
.alert { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 0.92rem; }
.alert-success { background: var(--green-dim); border-color: rgba(34,197,94,.35); color: #b6f5cc; }
.alert-error { background: var(--red-dim); border-color: rgba(239,68,68,.35); color: #ffc2c2; }
.alert-info { background: var(--blue-dim); border-color: rgba(59,130,246,.35); color: #cfe0ff; }
.alert-warning { background: var(--amber-dim); border-color: rgba(245,179,1,.35); color: #ffe08a; }
.alert-close { background: none; border: 0; color: inherit; font-size: 1.2rem; cursor: pointer; line-height: 1; opacity: 0.7; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 0.74rem; font-weight: 650; border: 1px solid transparent; vertical-align: middle; white-space: nowrap; }
.badge-pending { background: var(--amber-dim); color: #ffd35c; border-color: rgba(245,179,1,.3); }
.badge-approved, .badge-active, .badge-completed { background: var(--green-dim); color: #7ee2a2; border-color: rgba(34,197,94,.3); }
.badge-rejected, .badge-suspended { background: var(--red-dim); color: #ff9c9c; border-color: rgba(239,68,68,.3); }
.badge-deactivated { background: rgba(141,157,186,.12); color: var(--muted); border-color: var(--border); }
.badge-sim { background: var(--amber-dim); color: #ffd35c; border-color: rgba(245,179,1,.3); text-transform: uppercase; letter-spacing: .04em; font-size: .66rem; }
.badge-admin { background: var(--blue-dim); color: #a9c8ff; border-color: rgba(59,130,246,.3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid rgba(34,49,79,.6); vertical-align: top; }
.table tbody tr:hover { background: rgba(23,35,64,.5); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.side { font-weight: 700; font-size: .78rem; padding: 2px 8px; border-radius: 6px; }
.side-buy { background: var(--green-dim); color: var(--green); }
.side-sell { background: var(--red-dim); color: var(--red); }

/* ---------- Tabs / segmented ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--bg-2); padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.tab { padding: 6px 13px; border-radius: 7px; color: var(--muted); font-size: .86rem; font-weight: 600; background: none; border: 0; cursor: pointer; font-family: inherit; display: inline-flex; gap: 6px; align-items: center; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { background: var(--card-2); color: var(--text); }
.tab-count { background: var(--border); border-radius: 99px; padding: 0 7px; font-size: .72rem; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 34px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state .icon { color: var(--faint); }
.empty-state p { margin: 0; max-width: 420px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.details { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 0 0 16px; font-size: .92rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.plain-list { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; font-size: .9rem; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.split { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
.narrow { max-width: 760px; display: flex; flex-direction: column; gap: 20px; }
.update-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.update-list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.update-list li:last-child { border-bottom: 0; }
.row-between { flex-direction: row !important; justify-content: space-between; align-items: center; gap: 12px; }
.spinner { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--blue); animation: spin .8s linear infinite; vertical-align: -3px; }

/* ---------- Dialog ---------- */
.dialog { border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(3, 7, 18, .7); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.dialog-head h2 { font-size: 1.15rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: calc(100vh - 34px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; gap: 18px; }
.auth-wrap .flashes { width: min(440px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.1rem; }
.auth-brand .icon { color: var(--amber); }
.auth-card { width: min(440px, 100%); padding: 28px; box-shadow: var(--shadow); }
.auth-title { font-size: 1.4rem; margin-bottom: 6px; }
.auth-card > .muted { margin: 0 0 20px; font-size: .9rem; }
.auth-switch { text-align: center; color: var(--muted); font-size: .9rem; margin: 18px 0 0; }
.auth-foot { color: var(--faint); font-size: .78rem; text-align: center; max-width: 440px; }
.error-card { text-align: center; }
.error-code { font-size: 3.4rem; font-weight: 800; color: var(--amber); line-height: 1; margin-bottom: 8px; }
.error-card .btn { margin-top: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app-shell { background: var(--bg); }
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; z-index: 80; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(3,7,18,.6); z-index: 70; }
  .topbar .nav-toggle { display: inline-grid; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 18px 16px 40px; }
}
@media (max-width: 560px) {
  .sim-banner-sub { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 1.12rem; }
  .card { padding: 16px; }
  .details { grid-template-columns: 1fr; gap: 2px; }
  .details dd { margin-bottom: 8px; }
  .page-title { font-size: 1.08rem; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
}
