/* ── Shared UI Components ──────────────────────────────────────────
   Glass cards, buttons, badges, toggles, feed, toast, health dot.
   ────────────────────────────────────────────────────────────────── */

/* ── Glass Card ──────────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow), var(--glass-highlight);
  overflow: hidden;
}

.glass__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--glass-border);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.glass__body {
  padding: var(--sp-4);
}

/* ── Button ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.3);
  color: var(--bank-a);
}

.btn--primary:hover {
  background: rgba(59, 130, 246, 0.3);
}

.btn--danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--danger);
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn--warning {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.25);
  color: var(--warning);
}

.btn--warning:hover {
  background: rgba(245, 158, 11, 0.25);
}

.btn--success {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.25);
  color: var(--success);
}

.btn--success:hover {
  background: rgba(34, 197, 94, 0.25);
}

.btn--sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Badge ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-mono);
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
}

.badge--success { color: var(--success); border-color: rgba(34, 197, 94, 0.3); background: rgba(34, 197, 94, 0.1); }
.badge--danger  { color: var(--danger);  border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.1); }
.badge--warning { color: var(--warning); border-color: rgba(245, 158, 11, 0.3); background: rgba(245, 158, 11, 0.1); }
.badge--info    { color: var(--info);    border-color: rgba(59, 130, 246, 0.3); background: rgba(59, 130, 246, 0.1); }

/* ── Health Dot ──────────────────────────────────────────────────── */
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-base);
}

.health-dot--ok     { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
.health-dot--warn   { background: var(--warning); box-shadow: 0 0 6px rgba(245, 158, 11, 0.5); }
.health-dot--error  { background: var(--danger);  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); }

/* ── Toggle Switch ───────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.toggle__track {
  width: 36px;
  height: 20px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  transition: background var(--transition-fast);
  position: relative;
}

.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: all var(--transition-fast);
}

.toggle--active .toggle__track {
  background: rgba(59, 130, 246, 0.3);
  border-color: rgba(59, 130, 246, 0.4);
}

.toggle--active .toggle__thumb {
  left: 18px;
  background: var(--bank-a);
}

/* ── Feed ────────────────────────────────────────────────────────── */
.feed {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.feed__item:hover {
  background: rgba(255, 255, 255, 0.02);
}

.feed__item--scenario {
  background: rgba(245, 158, 11, 0.04);
}

.feed__item--error {
  background: rgba(239, 68, 68, 0.04);
}

.feed__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
}

.toast {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--text-primary);
  animation: toastIn 300ms ease forwards;
  max-width: 360px;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--danger  { border-left: 3px solid var(--danger); }
.toast--warning { border-left: 3px solid var(--warning); }
.toast--info    { border-left: 3px solid var(--info); }

.toast--exit {
  animation: toastOut 200ms ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* ── Stat Counter ────────────────────────────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat__value {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.stat__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Input ───────────────────────────────────────────────────────── */
.input {
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast);
}

.input:focus {
  border-color: rgba(59, 130, 246, 0.4);
}

.input--sm {
  width: 72px;
  text-align: center;
}

/* ── Select ──────────────────────────────────────────────────────── */
.select {
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 12L2 6h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

.select option {
  color: #1a1a2e;
  background: #ffffff;
}

/* ── Popup / Modal ───────────────────────────────────────────────── */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 150ms ease;
}

.popup {
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.popup__close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-lg);
  padding: var(--sp-1);
}

.popup__close:hover {
  color: var(--text-primary);
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ── Table ───────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

.table th {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  border-bottom: 1px solid var(--glass-border);
}

.table td {
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ── Onboarding Popup ──────────────────────────────────────────────── */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 300ms ease;
}

.onboarding {
  max-width: 480px;
  width: 90%;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.onboarding__header {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.onboarding__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.onboarding__step {
  display: flex;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.onboarding__icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: rgba(59, 130, 246, 0.15);
  border-radius: var(--radius-sm);
  color: var(--bank-a);
}

.onboarding__dismiss {
  align-self: center;
  padding: var(--sp-2) var(--sp-6);
}

/* ── Help Tip Popover ───────────────────────────────────────────── */
.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: var(--text-2xs);
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.help-tip:hover {
  color: var(--text-accent);
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.1);
}

.help-tip__content {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  padding: var(--sp-3);
  font-size: var(--text-sm);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
  z-index: 300;
  white-space: normal;
  text-transform: none;
  letter-spacing: normal;
}

.help-tip__content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--glass-border);
}

/* Downward variant for items near top of page (avoids nav clipping) */
.help-tip--down .help-tip__content {
  bottom: auto;
  top: calc(100% + 8px);
}

.help-tip--down .help-tip__content::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--glass-border);
}

.help-tip--open .help-tip__content {
  display: block;
  animation: toastIn 150ms ease forwards;
}

/* ── Role Group (nav) ──────────────────────────────────────────── */
.nav__role-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.nav__role-label {
  font-size: var(--text-2xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* ── Button Disabled by Role ───────────────────────────────────── */
.btn--role-blocked {
  opacity: 0.35;
  cursor: not-allowed;
  position: relative;
}

.btn--role-blocked::after {
  content: attr(data-role-hint);
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-2xs);
  color: var(--text-primary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 300;
}

.btn--role-blocked:hover::after {
  display: block;
}

/* ── Show Help Button ──────────────────────────────────────────── */
.nav__help-btn {
  background: none;
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: var(--text-2xs);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav__help-btn:hover {
  color: var(--text-accent);
  border-color: rgba(59, 130, 246, 0.3);
}
