/* ============================================================
   Market Insights — Centralized Alerts (Iter 25U)
   Bell in mi-topbar-right + right-anchored overlay panel.
   Follows market-insights-ux-ui skill:
     - 44x44 touch targets
     - z-index 9500 (page-overlays tier)
     - -popover suffix on the panel (global mobile clamp applies)
     - design tokens only
   ============================================================ */

/* --- Bell button -------------------------------------------- */
.mi-alerts-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  margin: 0 6px 0 2px;
  padding: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md, 8px);
  color: var(--text-secondary, #b0bec5);
  cursor: pointer;
  transition: background var(--transition, 180ms cubic-bezier(0.16, 1, 0.3, 1)),
              border-color var(--transition, 180ms cubic-bezier(0.16, 1, 0.3, 1)),
              color var(--transition, 180ms cubic-bezier(0.16, 1, 0.3, 1));
  -webkit-tap-highlight-color: transparent;
}
.mi-alerts-bell:hover,
.mi-alerts-bell:focus-visible {
  background: var(--bg-tertiary, #222226);
  border-color: var(--border, #2a2a30);
  color: var(--text-primary, #e0e0e0);
  outline: none;
}
.mi-alerts-bell[aria-expanded="true"] {
  background: var(--bg-tertiary, #222226);
  border-color: var(--accent-orange-border, rgba(79, 152, 163, 0.40));
  color: var(--text-primary, #e0e0e0);
}
.mi-alerts-bell svg {
  width: 18px;
  height: 18px;
  display: block;
  pointer-events: none;
}

/* Hidden until auth resolves (mi-alerts.js toggles .is-ready) */
.mi-alerts-bell:not(.is-ready) {
  display: none;
}

/* Mobile: ensure 44x44 hit area via transparent ::before, keep visual size */
@media (max-width: 640px) {
  .mi-alerts-bell {
    width: 40px;
    height: 40px;
    margin: 0 4px;
  }
  .mi-alerts-bell::before {
    content: '';
    position: absolute;
    inset: -4px;
  }
}

/* --- Badge -------------------------------------------------- */
.mi-alerts-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill, 999px);
  background: var(--red, #C24A4A);
  color: #fff;
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--bg-primary, #131316);
  letter-spacing: 0;
}
.mi-alerts-badge:empty,
.mi-alerts-badge[data-count="0"] {
  display: none;
}

/* --- Slow-pulse animation (unread > 0) ---------------------- */
.mi-alerts-bell.is-pulsing svg {
  animation: miAlertsPulse 2.4s ease-in-out infinite;
  transform-origin: 50% 20%;
  color: var(--accent-cyan, #4F98A3);
}
@keyframes miAlertsPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.08); opacity: 0.85; }
}
@media (prefers-reduced-motion: reduce) {
  .mi-alerts-bell.is-pulsing svg { animation: none; }
}

/* --- Panel (popover) ---------------------------------------- */
.mi-alerts-popover {
  position: fixed;
  top: 64px;
  right: 12px;
  left: auto;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 80px);
  background: var(--bg-card, #1c1c20);
  border: 1px solid var(--border, #2a2a30);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45),
              0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 9500;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  color: var(--text-primary, #e0e0e0);
}
.mi-alerts-popover.is-open {
  display: flex;
}

@media (max-width: 640px) {
  .mi-alerts-popover {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 78vh;
  }
}

/* --- Panel header + tabs ------------------------------------ */
.mi-alerts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border, #2a2a30);
  flex-shrink: 0;
}
.mi-alerts-head-title {
  font-size: var(--fs-md, 14px);
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
}
.mi-alerts-head-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.mi-alerts-head-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px);
  color: var(--text-muted, #8a8a8e);
  font: inherit;
  font-size: var(--fs-xs, 12px);
  padding: 6px 8px;
  cursor: pointer;
  min-height: 28px;
  transition: color var(--transition, 180ms ease), background var(--transition, 180ms ease);
}
.mi-alerts-head-btn:hover {
  color: var(--text-primary, #e0e0e0);
  background: var(--bg-tertiary, #222226);
}

.mi-alerts-tabs {
  display: flex;
  border-bottom: 1px solid var(--border, #2a2a30);
  background: var(--bg-card-inner, #18181c);
  flex-shrink: 0;
}
.mi-alerts-tab {
  flex: 1 1 50%;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 8px;
  color: var(--text-muted, #8a8a8e);
  font: inherit;
  font-size: var(--fs-sm, 13px);
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
  transition: color var(--transition, 180ms ease), border-color var(--transition, 180ms ease);
}
.mi-alerts-tab:hover { color: var(--text-secondary, #b0bec5); }
.mi-alerts-tab.is-active {
  color: var(--text-primary, #e0e0e0);
  border-bottom-color: var(--accent-cyan, #4F98A3);
}

/* --- Panel body --------------------------------------------- */
.mi-alerts-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mi-alerts-pane { display: none; padding: 6px 0; }
.mi-alerts-pane.is-active { display: block; }

.mi-alerts-empty,
.mi-alerts-loading,
.mi-alerts-error {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted, #8a8a8e);
  font-size: var(--fs-sm, 13px);
}
.mi-alerts-error { color: var(--red, #C24A4A); }

/* --- Alert item --------------------------------------------- */
.mi-alert-item {
  position: relative;
  display: block;
  padding: 12px 14px 12px 22px;
  border-bottom: 1px solid var(--border-subtle, rgba(42,42,48,0.3));
  transition: background var(--transition, 180ms ease);
}
.mi-alert-item:last-child { border-bottom: none; }
.mi-alert-item.is-unread {
  background: var(--accent-orange-dim, rgba(79, 152, 163, 0.08));
}
.mi-alert-item.is-unread::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 18px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-cyan, #4F98A3);
}
.mi-alert-item.severity-critical::before { background: var(--red, #C24A4A); }
.mi-alert-item.severity-warning::before { background: var(--yellow, #BB653B); }

.mi-alert-title {
  font-size: var(--fs-sm, 13px);
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
  margin: 0 0 4px;
  line-height: 1.35;
}
.mi-alert-body-text {
  font-size: var(--fs-xs, 12px);
  color: var(--text-secondary, #b0bec5);
  margin: 0 0 6px;
  line-height: 1.45;
  word-wrap: break-word;
}
.mi-alert-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted, #8a8a8e);
  letter-spacing: 0.02em;
}
.mi-alert-meta-time { white-space: nowrap; }
.mi-alert-meta-cat {
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.mi-alert-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}
.mi-alert-action {
  background: none;
  border: 1px solid var(--border, #2a2a30);
  border-radius: var(--radius-sm, 6px);
  color: var(--text-muted, #8a8a8e);
  font: inherit;
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  min-height: 28px;
  transition: color var(--transition, 180ms ease), border-color var(--transition, 180ms ease);
}
.mi-alert-action:hover {
  color: var(--text-primary, #e0e0e0);
  border-color: var(--accent-orange-border, rgba(79, 152, 163, 0.40));
}

/* --- Settings pane ------------------------------------------ */
.mi-alerts-settings-group {
  padding: 12px 14px 6px;
  border-bottom: 1px solid var(--border-subtle, rgba(42,42,48,0.3));
}
.mi-alerts-settings-group:last-child { border-bottom: none; }
.mi-alerts-settings-cat {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted, #8a8a8e);
  margin: 0 0 8px;
}
.mi-alerts-setting-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}
.mi-alerts-setting-info {
  flex: 1 1 auto;
  min-width: 0;
}
.mi-alerts-setting-name {
  font-size: var(--fs-sm, 13px);
  font-weight: 500;
  color: var(--text-primary, #e0e0e0);
  margin: 0 0 2px;
}
.mi-alerts-setting-desc {
  font-size: var(--fs-xs, 12px);
  color: var(--text-muted, #8a8a8e);
  margin: 0;
  line-height: 1.4;
}
.mi-alerts-setting-toggles {
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* --- Toggle (compact switch) -------------------------------- */
.mi-alerts-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary, #b0bec5);
  user-select: none;
  min-height: 28px;
}
.mi-alerts-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.mi-alerts-toggle-track {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--bg-tertiary, #222226);
  border: 1px solid var(--border, #2a2a30);
  border-radius: 999px;
  transition: background var(--transition, 180ms ease), border-color var(--transition, 180ms ease);
  flex-shrink: 0;
}
.mi-alerts-toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  background: var(--text-muted, #8a8a8e);
  border-radius: 50%;
  transition: transform var(--transition, 180ms ease), background var(--transition, 180ms ease);
}
.mi-alerts-toggle input:checked + .mi-alerts-toggle-track {
  background: var(--accent-orange-dim, rgba(79, 152, 163, 0.18));
  border-color: var(--accent-orange-border, rgba(79, 152, 163, 0.40));
}
.mi-alerts-toggle input:checked + .mi-alerts-toggle-track .mi-alerts-toggle-thumb {
  transform: translateX(14px);
  background: var(--accent-cyan, #4F98A3);
}
.mi-alerts-toggle input:focus-visible + .mi-alerts-toggle-track {
  box-shadow: 0 0 0 2px var(--accent-orange-border, rgba(79, 152, 163, 0.40));
}

/* ============================================================
   Iter 25AB — Browser push toggle button (Settings pane top)
   ============================================================ */
.mi-alerts-push-block {
  margin-bottom: 4px;
}
.mi-alerts-push-btn {
  appearance: none;
  background: var(--bg-tertiary, #222226);
  color: var(--text-primary, #e0e0e0);
  border: 1px solid var(--border, #2a2a30);
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  min-width: 88px;
  min-height: 36px;
  transition: background 180ms cubic-bezier(0.16, 1, 0.3, 1),
              border-color 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.mi-alerts-push-btn:hover:not(:disabled) {
  background: var(--accent-orange-dim, rgba(79, 152, 163, 0.18));
  border-color: var(--accent-orange-border, rgba(79, 152, 163, 0.40));
}
.mi-alerts-push-btn[data-status="subscribed"] {
  background: rgba(14, 179, 91, 0.12);
  border-color: rgba(14, 179, 91, 0.40);
  color: var(--green, #0EB35B);
}
.mi-alerts-push-btn[data-status="denied"] {
  background: rgba(194, 74, 74, 0.10);
  border-color: rgba(194, 74, 74, 0.32);
  color: var(--red, #C24A4A);
}
.mi-alerts-push-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
@media (max-width: 640px) {
  .mi-alerts-push-btn {
    min-height: 44px;
    min-width: 96px;
    padding: 10px 14px;
  }
}
