:root {
  --bg: #0b1220;
  --bg-2: #0f172a;
  --card: rgba(15, 23, 42, 0.82);
  --border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok-bg: rgba(16, 185, 129, 0.14);
  --warn-bg: rgba(251, 191, 36, 0.12);
  --bad-bg: rgba(248, 113, 113, 0.12);
  --unknown-bg: rgba(148, 163, 184, 0.12);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "Tajawal", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  direction: rtl;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(800px 400px at 80% -10%, rgba(16, 185, 129, 0.18), transparent 60%),
    radial-gradient(700px 350px at 10% 0%, rgba(59, 130, 246, 0.12), transparent 55%),
    linear-gradient(180deg, #0b1220 0%, #0b1220 100%);
  z-index: -1;
}

.site-header {
  padding: 28px 20px 8px;
  max-width: 1240px;
  margin: 0 auto;
}
.brand {
  display: flex;
  gap: 16px;
  align-items: center;
}
.brand-icon {
  font-size: 2.4rem;
  filter: drop-shadow(0 6px 16px rgba(16, 185, 129, 0.35));
}
.site-header h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  background: linear-gradient(90deg, #34d399, #60a5fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.tagline strong { color: #cbd5e1; }

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.mode-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.mode-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 8px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(52, 211, 153, 0.15));
  color: #34d399;
}

.field-label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { min-width: 0; }

.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: stretch;
}

.text-input,
.select {
  background: #0b1526;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: var(--font);
}
.text-input {
  flex: 1 1 320px;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  direction: ltr;
  text-align: left;
}
.select {
  width: 100%;
}
.text-input:focus,
.select:focus {
  outline: 2px solid rgba(16, 185, 129, 0.45);
  border-color: rgba(16, 185, 129, 0.5);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #04140d;
  border: none;
  border-radius: 12px;
  padding: 12px 28px;
  font-family: var(--font);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; transform: none; }
.mt-12 { margin-top: 14px; }

.options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 12px;
}
.check {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  cursor: pointer;
}
.inline-field {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}
.inline-field .select { width: auto; padding: 6px 8px; border-radius: 8px; }

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-word;
}
.hint a { color: #7dd3fc; }
.link-btn {
  background: none;
  border: none;
  color: #7dd3fc;
  cursor: pointer;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  padding: 0;
  direction: ltr;
  unicode-bidi: embed;
}
.link-btn:hover { text-decoration: underline; }

.status {
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  background: rgba(59, 130, 246, 0.1);
  color: #bfdbfe;
  font-weight: 500;
}
.status.error {
  background: var(--bad-bg);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
}
.status .spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(191, 219, 254, 0.3);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  text-align: center;
}
.stat .num {
  font-size: 1.5rem;
  font-weight: 800;
  display: block;
  line-height: 1.2;
}
.stat .lbl { color: var(--muted); font-size: 0.85rem; }
.stat.ok .num { color: #34d399; }
.stat.warn .num { color: #fbbf24; }
.stat.bad .num { color: #f87171; }
.stat.neutral .num { color: #93c5fd; }

.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.results-toolbar h2 { margin: 0; font-size: 1.2rem; }
.count-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-right: 6px;
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.session-tabs { margin: 4px 0 10px; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.88rem;
}
.tab:hover { color: var(--text); border-color: rgba(148, 163, 184, 0.35); }
.tab.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
}
.tab.src-benzinga.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}
.tab.src-tapeboard.active {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.45);
  color: #d8b4fe;
}

/* ——— Table ——— */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.45);
  margin-top: 10px;
  -webkit-overflow-scrolling: touch;
}

.results-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 960px;
  font-size: 0.88rem;
}
.results-table thead th {
  background: rgba(15, 23, 42, 0.98);
  color: var(--muted);
  font-weight: 700;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: right;
}
.results-table thead th.num,
.results-table tbody td.num {
  text-align: left;
  direction: ltr;
  font-variant-numeric: tabular-nums;
}
.results-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  vertical-align: middle;
  background: transparent;
}
.results-table tbody tr:last-child td { border-bottom: none; }
.results-table tbody tr:hover td {
  background: rgba(148, 163, 184, 0.06);
}

.col-ticker { min-width: 64px; }
.col-company { min-width: 140px; max-width: 220px; }
.col-status { min-width: 110px; }
.col-rank { min-width: 52px; }
.col-price { min-width: 70px; }
.col-change { min-width: 80px; }
.col-mcap { min-width: 80px; }
.col-vol { min-width: 72px; }
.col-sector { min-width: 90px; max-width: 140px; }
.col-halal, .col-debt { min-width: 72px; }
.col-links { min-width: 150px; }

.ticker-cell {
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #e2e8f0;
  direction: ltr;
  display: inline-block;
  letter-spacing: 0.02em;
}
.company-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  color: var(--muted);
}
.sector-cell {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  color: #cbd5e1;
}
.pos { color: #34d399; }
.neg { color: #f87171; }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill-ok { background: var(--ok-bg); color: #34d399; }
.pill-warn { background: var(--warn-bg); color: #fbbf24; }
.pill-bad { background: var(--bad-bg); color: #f87171; }
.pill-unknown { background: var(--unknown-bg); color: #94a3b8; }

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.links a {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 0.82rem;
  direction: ltr;
}
.links a:hover { text-decoration: underline; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 0;
}

.about-card h3 { margin-top: 0; }
.about-card ol { padding-right: 1.2rem; color: var(--muted); }
.about-card li { margin-bottom: 6px; }
.disclaimer {
  margin-bottom: 0;
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 10px 16px 30px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.hidden { display: none !important; }

@media (max-width: 720px) {
  .site-header h1 { font-size: 1.35rem; }
  .brand-icon { font-size: 1.8rem; }
  .input-row { flex-direction: column; }
  .btn-primary { width: 100%; }
  .results-toolbar { flex-direction: column; align-items: flex-start; }
  .table-wrap { border-radius: 12px; }
}
