/**
 * Admin Risk Control Page
 * Build: 20260201_ADMIN_REBUILD
 * Scoped under: .admin-page-risk
 */

/* ==========================================
   SECTION 1: RESET & VARIABLES
   ========================================== */
.admin-page-risk *,
.admin-page-risk *::before,
.admin-page-risk *::after {
  background-image: none !important;
  box-shadow: none !important;
}

.admin-page-risk {
  --ar-blue: #2B8CFF;
  --ar-blue-soft: rgba(43, 140, 255, 0.14);
  --ar-blue-border: rgba(43, 140, 255, 0.15);
  --ar-dark: #0B1220;
  --ar-panel: #0F1A2E;
  --ar-surface: #162038;
  --ar-text: #EAF2FF;
  --ar-muted: rgba(234, 242, 255, 0.55);
  --ar-success: #10B981;
  --ar-warning: #F59E0B;
  --ar-danger: #EF4444;
  --ar-radius: 18px;
  --ar-radius-sm: 12px;
  --ar-transition: 160ms ease;
}

/* ==========================================
   SECTION 2: PAGE CONTAINER
   ========================================== */
.admin-page-risk {
  padding: 24px;
  min-height: 100%;
}

/* ==========================================
   SECTION 3: HEADER
   ========================================== */
.ar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--ar-blue-border);
}

.ar-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--ar-text);
}

.ar-subtitle {
  font-size: 12px;
  color: var(--ar-muted);
  margin-top: 4px;
}

/* ==========================================
   SECTION 4: RISK OVERVIEW STRIP
   ========================================== */
.ar-overview-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.ar-overview-card {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  padding: 16px;
  text-align: center;
}

.ar-overview-card.warning {
  border-color: var(--ar-warning);
}

.ar-overview-card.danger {
  border-color: var(--ar-danger);
}

.ar-overview-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ar-text);
}

.ar-overview-value.good { color: var(--ar-success); }
.ar-overview-value.warning { color: var(--ar-warning); }
.ar-overview-value.danger { color: var(--ar-danger); }

.ar-overview-label {
  font-size: 11px;
  color: var(--ar-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* ==========================================
   SECTION 5: THRESHOLD PANELS
   ========================================== */
.ar-thresholds-section {
  margin-bottom: 24px;
}

.ar-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ar-text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ar-thresholds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.ar-threshold-card {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  padding: 20px;
}

.ar-threshold-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.ar-threshold-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ar-text);
}

.ar-threshold-status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.ar-threshold-status.ok {
  background: rgba(16, 185, 129, 0.14);
  color: var(--ar-success);
}

.ar-threshold-status.warning {
  background: rgba(245, 158, 11, 0.14);
  color: var(--ar-warning);
}

.ar-threshold-status.breach {
  background: rgba(239, 68, 68, 0.14);
  color: var(--ar-danger);
}

.ar-threshold-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.ar-threshold-current {
  font-size: 24px;
  font-weight: 700;
  color: var(--ar-text);
}

.ar-threshold-limit {
  font-size: 13px;
  color: var(--ar-muted);
}

.ar-threshold-bar {
  height: 6px;
  background: var(--ar-surface);
  border-radius: 3px;
  overflow: hidden;
}

.ar-threshold-fill {
  height: 100%;
  background: var(--ar-blue);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.ar-threshold-fill.warning { background: var(--ar-warning); }
.ar-threshold-fill.danger { background: var(--ar-danger); }

/* ==========================================
   SECTION 6: EXPOSURE SUMMARY
   ========================================== */
.ar-exposure-panel {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  padding: 20px;
  margin-bottom: 24px;
}

.ar-exposure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ar-blue-border);
}

.ar-exposure-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ar-text);
}

.ar-exposure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.ar-exposure-item {
  padding: 16px;
  background: var(--ar-surface);
  border-radius: var(--ar-radius-sm);
}

.ar-exposure-label {
  font-size: 11px;
  color: var(--ar-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.ar-exposure-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--ar-text);
  font-family: 'JetBrains Mono', monospace;
}

.ar-exposure-value.positive { color: var(--ar-success); }
.ar-exposure-value.negative { color: var(--ar-danger); }

/* ==========================================
   SECTION 7: RISK GATES
   ========================================== */
.ar-gates-panel {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  padding: 20px;
  margin-bottom: 24px;
}

.ar-gates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.ar-gate {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ar-surface);
  border-radius: var(--ar-radius-sm);
  border: 1px solid transparent;
}

.ar-gate.active {
  border-color: var(--ar-success);
  background: rgba(16, 185, 129, 0.05);
}

.ar-gate.triggered {
  border-color: var(--ar-danger);
  background: rgba(239, 68, 68, 0.05);
}

.ar-gate-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--ar-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.ar-gate.active .ar-gate-icon {
  background: rgba(16, 185, 129, 0.14);
}

.ar-gate.triggered .ar-gate-icon {
  background: rgba(239, 68, 68, 0.14);
}

.ar-gate-info {
  flex: 1;
}

.ar-gate-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ar-text);
}

.ar-gate-status {
  font-size: 11px;
  color: var(--ar-muted);
}

.ar-gate-toggle {
  width: 44px;
  height: 24px;
  background: var(--ar-surface);
  border: 1px solid var(--ar-blue-border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: var(--ar-transition);
}

.ar-gate-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--ar-muted);
  border-radius: 50%;
  transition: var(--ar-transition);
}

.ar-gate-toggle.on {
  background: var(--ar-blue);
  border-color: var(--ar-blue);
}

.ar-gate-toggle.on::after {
  left: 22px;
  background: white;
}

/* ==========================================
   SECTION 8: ALERTS LOG
   ========================================== */
.ar-alerts-panel {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  overflow: hidden;
}

.ar-alerts-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--ar-blue-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ar-alerts-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ar-text);
}

.ar-alerts-list {
  max-height: 300px;
  overflow-y: auto;
}

.ar-alert-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(43, 140, 255, 0.08);
}

.ar-alert-item:last-child {
  border-bottom: none;
}

.ar-alert-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.ar-alert-content {
  flex: 1;
}

.ar-alert-msg {
  font-size: 13px;
  color: var(--ar-text);
  margin-bottom: 4px;
}

.ar-alert-meta {
  font-size: 11px;
  color: var(--ar-muted);
}

.ar-alert-time {
  font-size: 11px;
  color: var(--ar-muted);
  white-space: nowrap;
}

/* ==========================================
   SECTION 9: EMPTY & LOADING
   ========================================== */
.ar-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ar-muted);
}

.ar-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.ar-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--ar-surface);
  border-top-color: var(--ar-blue);
  border-radius: 50%;
  animation: ar-spin 0.8s linear infinite;
}

@keyframes ar-spin {
  to { transform: rotate(360deg); }
}

/* ==========================================
   SECTION 10: RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .admin-page-risk {
    padding: 16px;
  }
  
  .ar-overview-value {
    font-size: 22px;
  }
  
  .ar-threshold-current {
    font-size: 18px;
  }
}

/* ==========================================
   SECTION 11: LEGACY COMPATIBILITY BRIDGE
   Build: 20260201_CSS_REBUILD
   Maps inline CSS variables from risk.js to new design
   ========================================== */
.admin-page-risk {
  /* Variable bridge for inline styles */
  --danger-base: var(--ar-danger);
  --success-base: var(--ar-success);
  --warning-base: var(--ar-warning);
  --brand-primary: var(--ar-blue);
  --accent-base: var(--ar-blue);
  --accent-purple: var(--ar-blue);
  --info-base: var(--ar-blue);
  --bg-dark: var(--ar-surface);
  --bg-darker: var(--ar-panel);
  --border-subtle: var(--ar-blue-border);
  --text-secondary: var(--ar-muted);
  --text-tertiary: var(--ar-muted);
}

/* Card compatibility */
.admin-page-risk .card {
  background: var(--ar-panel);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius);
  padding: 20px;
  margin-bottom: 16px;
}

.admin-page-risk .card-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--ar-blue-border);
  margin-bottom: 16px;
}

.admin-page-risk .card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ar-text);
}

/* Button compatibility */
.admin-page-risk .btn {
  padding: 8px 16px;
  background: var(--ar-surface);
  border: 1px solid var(--ar-blue-border);
  border-radius: 999px;
  color: var(--ar-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--ar-transition);
}

.admin-page-risk .btn:hover {
  background: var(--ar-blue-soft);
  border-color: var(--ar-blue);
}

.admin-page-risk .btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Loading ring compatibility */
.admin-page-risk .splash-ring {
  width: 32px;
  height: 32px;
  border: 3px solid var(--ar-surface);
  border-top-color: var(--ar-blue);
  border-radius: 50%;
  animation: ar-spin 0.8s linear infinite;
}

/* Alert compatibility */
.admin-page-risk .alert {
  padding: 14px 18px;
  border-radius: var(--ar-radius-sm);
  margin-bottom: 16px;
}

.admin-page-risk .alert-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--ar-warning);
}

.admin-page-risk .alert-danger {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--ar-danger);
}

.admin-page-risk .alert-info {
  background: var(--ar-blue-soft);
  border: 1px solid var(--ar-blue-border);
}

/* Stat card compatibility */
.admin-page-risk .stat-card {
  background: var(--ar-surface);
  padding: 16px;
  border-radius: var(--ar-radius-sm);
  border-left: 4px solid var(--ar-blue);
}

/* Input compatibility */
.admin-page-risk input[type="text"],
.admin-page-risk input[type="number"],
.admin-page-risk select {
  width: 100%;
  padding: 10px 14px;
  background: var(--ar-surface);
  border: 1px solid var(--ar-blue-border);
  border-radius: var(--ar-radius-sm);
  color: var(--ar-text);
  font-size: 14px;
}

.admin-page-risk input:focus,
.admin-page-risk select:focus {
  outline: none;
  border-color: var(--ar-blue);
}

/* Label compatibility */
.admin-page-risk label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ar-text);
  display: block;
  margin-bottom: 6px;
}

/* Toggle switch compatibility */
.admin-page-risk .toggle-switch {
  width: 48px;
  height: 26px;
  background: var(--ar-surface);
  border: 1px solid var(--ar-blue-border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: var(--ar-transition);
}

.admin-page-risk .toggle-switch.active {
  background: var(--ar-blue);
  border-color: var(--ar-blue);
}

/* Kill switch panel styling */
.admin-page-risk #globalKillSwitchCard {
  border-width: 2px !important;
}

.admin-page-risk #globalKillSwitchCard[style*="border-color:var(--danger-base)"],
.admin-page-risk #globalKillSwitchCard[style*="border:2px solid var(--danger-base)"] {
  border-color: var(--ar-danger) !important;
}

/* Config form grid */
.admin-page-risk #lpRiskConfigForm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

/* Risk limits grid */
.admin-page-risk #globalRiskLimits {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
