/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #22263a;
  --border: #2a2f45;
  --text: #e8eaf0;
  --text-muted: #7a80a0;
  --accent: #4f8ef7;
  --accent-hover: #3a7af5;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Layout ---- */
#app { min-height: 100vh; }

.page { display: none; }
.page.active { display: block; }

/* ---- Login Page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-card .brand h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.login-card .brand p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin-top: 1rem;
  display: none;
}

/* ---- Main App Layout ---- */
.app-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  padding: 0 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.sidebar .logo span { color: var(--accent); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,0.15); color: var(--accent); }

.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}

.account-chip .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(79,142,247,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.account-chip .info { flex: 1; min-width: 0; }
.account-chip .info .name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-chip .info .login { font-size: 11px; color: var(--text-muted); }

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s;
}
.btn-logout:hover { color: var(--red); }

/* ---- Main Content ---- */
.main-content {
  padding: 2rem;
  overflow-y: auto;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.page-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

/* ---- Stat Grid ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.text-green { color: var(--green) !important; }
.text-red { color: var(--red) !important; }
.text-yellow { color: var(--yellow) !important; }

/* ---- Table ---- */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid rgba(42,47,69,0.6);
  transition: background 0.1s;
}

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

tbody td {
  padding: 10px 12px;
  color: var(--text);
  white-space: nowrap;
}

/* ---- Badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-buy { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-sell { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-pending { background: rgba(245,158,11,0.15); color: var(--yellow); }

/* ---- Loading ---- */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-muted);
  flex-direction: column;
  gap: 12px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---- Refresh Btn ---- */
.btn-icon {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Header bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 1rem;
    gap: 6px;
  }
  .sidebar .logo { width: 100%; padding-bottom: 0.75rem; }
  .sidebar-footer { display: none; }
  .nav-item { padding: 7px 10px; font-size: 12px; }
}
