/* ================================================================
   QuantAIQmt — Dark Theme Stylesheet
   ================================================================ */

/* ── CSS Variables ─────────────────────────────────────────────── */

:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --red: #ff6b6b;
  --green: #3fb950;
  --yellow: #d2991d;
  --blue: #58a6ff;
  --orange: #f0883e;
  --purple: #a371f7;
  --active: rgba(88, 166, 255, 0.12);
  --hover-bg: rgba(255, 255, 255, 0.04);
  --sidebar-width: 220px;
}

/* Light mode overrides */
html.light {
  --bg: #ffffff;
  --card: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text2: #656d76;
  --active: rgba(9, 105, 218, 0.1);
  --hover-bg: rgba(0, 0, 0, 0.04);
}

/* ── Reset ─────────────────────────────────────────────────────── */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
table { border-collapse: collapse; }

/* ── Utility classes ────────────────────────────────────────────── */

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.space-y-1 > * + * { margin-top: 0.25rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.font-mono { font-family: 'JetBrains Mono', 'Consolas', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-xl { border-radius: 0.75rem; }
.shrink-0 { flex-shrink: 0; }
.min-w-0 { min-width: 0; }
.overflow-auto { overflow: auto; }
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }
.whitespace-nowrap { white-space: nowrap; }
.transition { transition: all 0.2s ease; }
.transition-colors { transition: background-color 0.2s, border-color 0.2s, color 0.2s; }
.transition-transform { transition: transform 0.3s ease; }

/* ── Spacing ───────────────────────────────────────────────────── */

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.ml-auto { margin-left: auto; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-1\.5 { padding-top: 0.375rem; padding-bottom: 0.375rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }

/* ── Max width ──────────────────────────────────────────────────── */

.max-w-6xl { max-width: 72rem; }
.max-w-7xl { max-width: 80rem; }
.max-w-lg { max-width: 32rem; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* ── Grid ───────────────────────────────────────────────────────── */

.grid { display: grid; }
.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 (min-width: 1024px) {
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ── Responsive visibility ──────────────────────────────────────── */

@media (min-width: 768px) {
  .md\:ml-220px { margin-left: var(--sidebar-width); }
  .md\:hidden { display: none; }
  .md\:block { display: block; }
}
@media (min-width: 640px) {
  .sm\:inline { display: inline; }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Cards ──────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 1.25rem;
}
.card:hover { border-color: var(--blue); transition: border-color 0.2s; }

.card .card-label {
  font-size: 0.8125rem;
  color: var(--text2);
  margin-bottom: 0.5rem;
}
.card .card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Buttons ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--card);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--blue); background: var(--hover-bg); }
.btn.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
.btn.primary:hover { background: #388bfd; }
.btn.active { background: #1f6feb; border-color: var(--blue); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }

.btn-group { display: flex; border-radius: 0.375rem; overflow: hidden; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 0.375rem 0 0 0.375rem; }
.btn-group .btn:last-child { border-radius: 0 0.375rem 0.375rem 0; }
.btn-group .btn + .btn { border-left: none; }

/* ── Forms ──────────────────────────────────────────────────────── */

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="email"],
select,
textarea {
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

/* ── Tables ─────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  color: var(--text2);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--hover-bg); }

th.text-right, td.text-right { text-align: right; }

/* ── Badges ─────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-bull, .badge-up { background: rgba(255,107,107,0.15); color: var(--red); }
.badge-bear, .badge-down { background: rgba(63,185,80,0.15); color: var(--green); }
.badge-dinglong { background: rgba(255,215,0,0.12); color: #ffd700; }
.badge-admin { background: rgba(163,113,247,0.15); color: var(--purple); }
.badge-analyst { background: rgba(88,166,255,0.15); color: var(--blue); }
.badge-viewer { background: rgba(139,148,158,0.15); color: var(--text2); }

/* ── Status dots ────────────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.status-ok { background: var(--green); }
.status-warn { background: var(--yellow); }
.status-err { background: var(--red); }
.status-pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Spinner ────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading ────────────────────────────────────────────────────── */

.loading-box {
  text-align: center;
  padding: 3rem;
  color: var(--text2);
}

/* ── Error ──────────────────────────────────────────────────────── */

.error-box {
  background: rgba(255,107,107,0.08);
  border: 1px solid var(--red);
  border-radius: 0.5rem;
  padding: 1rem;
  color: var(--red);
  font-size: 0.875rem;
}

/* ── Section header ─────────────────────────────────────────────── */

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ── Tabs ───────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  overflow-x: auto;
}
.tab-btn {
  padding: 0.625rem 1.25rem;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Collapsible ────────────────────────────────────────────────── */

.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.collapsible-header:hover { border-color: var(--blue); }
.collapsible-body { display: none; }
.collapsible-body.open { display: block; }
.collapsible-header .arrow { transition: transform 0.2s; font-size: 0.75rem; }
.collapsible-header.open .arrow { transform: rotate(90deg); }

/* ── Auth pages (no sidebar) ────────────────────────────────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 24rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 2rem;
}
.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.25rem;
}
.auth-card .subtitle {
  text-align: center;
  color: var(--text2);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text2);
  margin-bottom: 0.375rem;
  font-weight: 500;
}
.form-group input {
  width: 100%;
}
.form-error {
  background: rgba(255,107,107,0.08);
  border: 1px solid var(--red);
  border-radius: 0.375rem;
  padding: 0.625rem 0.75rem;
  color: var(--red);
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}
.btn-full {
  width: 100%;
  padding: 0.625rem;
  font-size: 0.9375rem;
  font-weight: 600;
}
.auth-link {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text2);
  margin-top: 1rem;
}
.auth-link a { color: var(--blue); }
.auth-link a:hover { text-decoration: underline; }

/* ── Gauge ──────────────────────────────────────────────────────── */

.gauge-track {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, #58a6ff, #7ee787, #d2991d, #f0883e, #ff6b6b);
  position: relative;
  margin: 8px 0 16px;
}
.gauge-fill {
  position: absolute; right: 0; top: 0;
  height: 10px; border-radius: 0 5px 5px 0;
  background: var(--bg);
  transition: width 0.5s ease;
}
.gauge-needle {
  position: absolute; top: -5px; width: 3px; height: 20px;
  border-radius: 2px; background: #fff;
  transform: translateX(-50%); transition: left 0.5s ease;
  box-shadow: 0 0 6px rgba(255,255,255,0.4);
}
.gauge-labels {
  display: flex; justify-content: space-between;
  font-size: 0.75rem; color: var(--text2);
}

/* ── Sector table row expansion ─────────────────────────────────── */

.sector-toggle { cursor: pointer; user-select: none; }
.sector-toggle .arrow {
  display: inline-block; transition: transform 0.2s;
  margin-right: 6px; font-size: 10px;
}
.sector-toggle.expanded .arrow { transform: rotate(90deg); }
.stock-row { display: none; }
.stock-row.open { display: table-row; cursor: pointer; }
.stock-detail {
  padding: 8px 14px 8px 50px;
  font-size: 13px; color: var(--text2);
  border-bottom: 1px solid var(--border);
  line-height: 1.8;
}

/* ── Drawer ─────────────────────────────────────────────────────── */

.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 100; display: none;
}
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 100%; max-width: 32rem;
  background: var(--bg); border-left: 1px solid var(--border);
  z-index: 101; transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

/* ── Quick link cards ───────────────────────────────────────────── */

.quick-link {
  display: block;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  transition: border-color 0.2s;
}
.quick-link:hover { border-color: var(--blue); }
.quick-link .icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.quick-link .label { font-weight: 500; color: var(--text); }
.quick-link .desc { font-size: 0.75rem; color: var(--text2); margin-top: 0.25rem; }

/* ── Modal ──────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 28rem;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

/* ── Scrollbar ──────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Responsive tables ──────────────────────────────────────────── */

@media (max-width: 768px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  th:nth-child(5), td:nth-child(5),
  th:nth-child(6), td:nth-child(6) { display: none; }
}

/* ── Position badges (auction gauge) ────────────────────────────── */

.pos-hot {
  display: inline-block; padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
  background: rgba(255,107,107,.15); color: var(--red);
}
.pos-warm {
  display: inline-block; padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
  background: rgba(240,136,62,.15); color: var(--orange);
}
.pos-neutral {
  display: inline-block; padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
  background: rgba(210,153,29,.15); color: var(--yellow);
}
.pos-cool {
  display: inline-block; padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
  background: rgba(126,231,135,.15); color: var(--green);
}
.pos-cold {
  display: inline-block; padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 600;
  background: rgba(88,166,255,.15); color: var(--blue);
}

/* ── Nav button (date navigator) ────────────────────────────────── */

.nav-btn {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card); color: var(--text); cursor: pointer; font-size: 14px;
  transition: all .2s; user-select: none;
}
.nav-btn:hover { border-color: var(--blue); background: var(--hover-bg); }

/* ── Stock row detail (auction sector expand) ───────────────────── */

.stock-detail {
  padding: 8px 14px 8px 50px; font-size: 13px; color: var(--text2);
  border-bottom: 1px solid var(--border); line-height: 1.8;
}

/* ── Leading relaxed ────────────────────────────────────────────── */

.leading-relaxed { line-height: 1.625; }
