/* ========================================
   CryptoQuant Analytics Dashboard — Main CSS
   Dark theme, RTL, Professional financial dashboard
   ======================================== */

:root {
  --bg-primary: #0a0c10;
  --bg-secondary: #0f1117;
  --bg-card: #141720;
  --bg-card-hover: #1a1e2a;
  --border: #1e2230;
  --border-light: #2a2f40;
  --accent: #f7931a;
  --accent-hover: #ffa940;
  --bull: #00c896;
  --bull-bg: rgba(0,200,150,0.1);
  --bear: #ff4757;
  --bear-bg: rgba(255,71,87,0.1);
  --volatile: #f7931a;
  --volatile-bg: rgba(247,147,26,0.1);
  --neutral: #8892a4;
  --neutral-bg: rgba(136,146,164,0.1);
  --text-primary: #e8eaf0;
  --text-secondary: #8892a4;
  --text-muted: #555f70;
  --font-fa: 'Vazirmatn', sans-serif;
  --sidebar-width: 260px;
  --header-height: 60px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-fa);
  background: var(--bg-primary);
  color: var(--text-primary);
  direction: rtl;
  line-height: 1.7;
  min-height: 100vh;
}

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

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

.main-content {
  flex: 1;
  margin-right: var(--sidebar-width);
  padding: calc(var(--header-height) + 20px) 24px 40px;
  min-width: 0;
}

/* ========== Header ========== */
.app-header {
  position: fixed;
  top: 0;
  right: var(--sidebar-width);
  left: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

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

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.header-user .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ========== Sidebar ========== */
.app-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.sidebar-logo .logo-icon {
  font-size: 1.4rem;
}

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

.nav-section {
  margin-bottom: 4px;
}

.nav-section-title {
  padding: 8px 20px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-item {
  display: block;
  padding: 8px 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: all var(--transition);
  cursor: pointer;
  border-right: 3px solid transparent;
}

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

.nav-item.active {
  background: var(--bg-card);
  color: var(--accent);
  border-right-color: var(--accent);
}

.nav-item .nav-icon {
  margin-left: 8px;
  width: 18px;
  display: inline-block;
  text-align: center;
}

/* Submenu */
.nav-submenu {
  display: none;
  padding-right: 20px;
}

.nav-submenu.open {
  display: block;
}

.nav-submenu .nav-item {
  padding: 6px 20px;
  font-size: 0.8rem;
}

.nav-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-toggle::after {
  content: '\25C0'; /* left arrow in RTL */
  font-size: 0.6rem;
  transition: transform var(--transition);
}

.nav-toggle.open::after {
  transform: rotate(-90deg);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 20px;
}

/* ========== Cards ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--transition);
}

.card:hover {
  border-color: var(--border-light);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========== Signal Badges ========== */
.signal-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.signal-bullish {
  background: var(--bull-bg);
  color: var(--bull);
}

.signal-bearish {
  background: var(--bear-bg);
  color: var(--bear);
}

.signal-volatile {
  background: var(--volatile-bg);
  color: var(--volatile);
}

.signal-neutral {
  background: var(--neutral-bg);
  color: var(--neutral);
}

/* ========== Metric Header (Widget Pages) ========== */
.widget-page {
  max-width: 1200px;
}

.metric-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.metric-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.metric-name-en {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  margin-top: 2px;
  direction: ltr;
  text-align: right;
}

.metric-live-value {
  display: flex;
  align-items: center;
  gap: 12px;
}

.current-value {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.updated-at {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.metric-actions {
  display: flex;
  gap: 8px;
}

/* ========== Range Selector ========== */
.range-selector {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
}

.range-btn {
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.range-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.range-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ========== Chart Container ========== */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  position: relative;
  height: 400px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ========== Explanation Blocks ========== */
.widget-explanation {
  margin-bottom: 24px;
}

.explanation-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.explanation-block h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent);
}

.explanation-block p {
  margin-bottom: 8px;
  color: var(--text-secondary);
  line-height: 2;
}

.explanation-block ul {
  padding-right: 20px;
  color: var(--text-secondary);
}

.explanation-block li {
  margin-bottom: 4px;
}

/* Signal explanation items */
.signal-explanation {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.signal-item {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
}

.signal-item.bullish { background: var(--bull-bg); }
.signal-item.bearish { background: var(--bear-bg); }
.signal-item.volatile { background: var(--volatile-bg); }

.signal-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.signal-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.signal-item p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0;
}

.warning-list li {
  color: var(--volatile);
}

/* ========== Related Metrics ========== */
.related-metrics {
  margin-bottom: 24px;
}

.related-metrics h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

.related-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: all var(--transition);
}

.related-card:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-fa);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.78rem;
}

.btn-watchlist,
.btn-alert {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-family: var(--font-fa);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-watchlist:hover,
.btn-alert:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Forms ========== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-fa);
  font-size: 0.85rem;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ========== Alerts (UI) ========== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.alert-error {
  background: var(--bear-bg);
  color: var(--bear);
  border: 1px solid rgba(255,71,87,0.2);
}

.alert-success {
  background: var(--bull-bg);
  color: var(--bull);
  border: 1px solid rgba(0,200,150,0.2);
}

/* ========== Auth Pages ========== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 1.3rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.auth-logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-form {
  margin-bottom: 20px;
}

.auth-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-footer a {
  color: var(--accent);
}

/* ========== Dashboard Grid ========== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.dashboard-section {
  margin-bottom: 32px;
}

.dashboard-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Mini metric card */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all var(--transition);
  display: block;
  color: inherit;
}

.metric-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.metric-card .mc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.metric-card .mc-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.metric-card .mc-value {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
  margin-bottom: 8px;
}

.metric-card .mc-sparkline {
  height: 40px;
}

.metric-card .mc-sparkline canvas {
  width: 100% !important;
  height: 40px !important;
}

/* Top bar cards (price + key metrics) */
.top-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.top-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-card .tc-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.top-card .tc-value {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

/* ========== Combo Pages ========== */
.combo-status {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.combo-status h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.combo-checklist {
  list-style: none;
  padding: 0;
}

.combo-checklist li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.combo-checklist li:last-child {
  border-bottom: none;
}

.check-icon {
  font-size: 1.1rem;
}

.check-icon.met { color: var(--bull); }
.check-icon.not-met { color: var(--bear); }

.combo-score {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  padding: 20px;
}

.combo-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.combo-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.combo-panel h4 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.combo-panel .panel-chart {
  height: 180px;
}

/* ========== User Pages ========== */
.user-page {
  max-width: 900px;
}

.user-page h1 {
  font-size: 1.3rem;
  margin-bottom: 24px;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  right: 3px;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--bull);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(-18px);
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .app-sidebar {
    transform: translateX(100%);
    transition: transform var(--transition);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-header {
    right: 0;
  }

  .main-content {
    margin-right: 0;
    padding: calc(var(--header-height) + 12px) 12px 24px;
  }

  .metric-header {
    flex-direction: column;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .top-bar {
    grid-template-columns: 1fr 1fr;
  }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ========== Utility ========== */
.text-bull { color: var(--bull); }
.text-bear { color: var(--bear); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.ltr { direction: ltr; text-align: right; }
