:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-raised: #182230;
  --border: #223047;
  --text: #e7edf5;
  --text-muted: #8b98ab;
  --accent: #3aa0ff;
  --accent-hover: #2b86e0;
  --accent-dim: rgba(58, 160, 255, 0.15);
  --danger: #e5533d;
  --danger-hover: #c8432f;
  --success: #2ecc71;
  --loss: #ef5350;
  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-raised: 0 4px 16px -6px rgba(0, 0, 0, 0.55);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Vazirmatn", "Tahoma", sans-serif;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

html[dir="rtl"] body { font-family: "Vazirmatn", "Tahoma", -apple-system, sans-serif; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 1px 0 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Crosshair mark — a small nod to "sniper": a ring with a center dot and
   four tick marks, drawn entirely with gradients (no image asset). */
.brand-mark {
  --tick: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  position: relative;
  flex-shrink: 0;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: var(--accent);
}
.brand-mark::before { top: -4px; bottom: -4px; left: 50%; width: var(--tick); transform: translateX(-50%); }
.brand-mark::after { left: -4px; right: -4px; top: 50%; height: var(--tick); transform: translateY(-50%); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}

.card h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 12px 0;
}

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

.field { margin-bottom: 12px; }
.field-grow { flex: 1; }
.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field { flex: 1; }

label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #06121f; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px -4px var(--accent-dim); }

.btn-danger { background: var(--danger); color: #1a0805; }
.btn-danger:hover { background: var(--danger-hover); box-shadow: 0 4px 14px -4px rgba(229, 83, 61, 0.35); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn:focus-visible,
input:focus-visible,
.suggestion-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button-row { display: flex; gap: 12px; margin-bottom: 12px; }

.side-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.side-toggle label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.side-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.side-toggle label:has(#side-buy:checked) { background: rgba(46, 204, 113, 0.16); color: var(--success); }
.side-toggle label:has(#side-sell:checked) { background: rgba(239, 83, 80, 0.16); color: var(--loss); }

.muted { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0 0 0; }

.status {
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-raised);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.pill-ok { background: rgba(46, 204, 113, 0.15); color: var(--success); }
.pill-none { background: rgba(239, 83, 80, 0.15); color: var(--loss); }
.pill-unknown { background: rgba(139, 152, 171, 0.15); color: var(--text-muted); }

.pill-ok::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pill-pulse 2s ease-in-out infinite;
}

@keyframes pill-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5); }
  50% { opacity: 0.6; box-shadow: 0 0 0 3px rgba(46, 204, 113, 0); }
}

.autocomplete { position: relative; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}

.suggestions.hidden { display: none; }

.suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.88rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.suggestion-item:hover { background: var(--surface); }
.suggestion-item .name { color: var(--text-muted); font-size: 0.8rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

html[dir="rtl"] .data-table th,
html[dir="rtl"] .data-table td { text-align: right; }

.data-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.gain { color: var(--success); }
.loss { color: var(--loss); }

.positions { display: flex; flex-direction: column; gap: 10px; }

.position-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.position-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.position-header .symbol { font-weight: 600; }

.position-status { font-size: 0.9rem; }

.hidden { display: none !important; }

.remove-link {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}
.remove-link:hover { color: var(--danger); }

@media (max-width: 560px) {
  .layout { padding: 16px; }
  .field-row { flex-direction: column; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: min(420px, 90vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h3 { margin: 0 0 10px 0; font-size: 1rem; }
.modal p { margin: 0 0 18px 0; color: var(--text-muted); font-size: 0.9rem; white-space: pre-wrap; }
.modal .button-row { margin: 0; justify-content: flex-end; }

.brokerage-auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 14, 0.82);
}

.brokerage-auth-dialog {
  width: min(1120px, 96vw);
  height: min(820px, 92vh);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.brokerage-auth-viewer {
  width: 100%;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111;
}
