/* ============================================
   COMPONENTS: Modals โ€” Obsidian Aurora
   ============================================
   Glassmorphism overlays, tonal dialogs.
   ============================================ */

/* =================== Standard Modal =================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.75);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  place-items: center;
  /* Overlays built in JS open with an inline `display:flex`, where place-items
     only centres the cross axis — name the main axis too or they hug the left
     edge. The `.show` (grid) path opts back out below. */
  justify-content: center;
  z-index: var(--z-modal);
}

.modal-overlay.show {
  display: grid;
  /* This path never needed the rule above: place-items centres the box inside a
     full-width auto track. Keep that track stretching, or the `min-width: 90%`
     under 768px would resolve against a shrunk track. */
  justify-content: normal;
}

.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--elevation-3);
  min-width: 400px;
  max-width: 520px;
  animation: modalFadeIn 0.18s ease;
  /* GPU layer promotion — without this the modal (sitting on a backdrop-filter
     overlay) scrolls via main-thread rasterization instead of the compositor,
     which reads as "not smooth" even when there's no outright frame drop. */
  transform: translateZ(0);
  will-change: transform;
}

.modal-header {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.modal-header h4 {
  margin: 0;
  font-size: var(--font-size-lg);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--color-primary);
  background: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 18px;
  /* Scroll containers here get an inline overflow-y:auto from JS (max-height +
     overflow-y). Without these, wheel scroll can chain into the page behind the
     overlay at the list boundaries and gets a slower repaint path. */
  overscroll-behavior: contain;
  contain: content;
}

.modal-body p {
  margin: 0;
  line-height: var(--line-height-relaxed);
}

.modal-body .form-group {
  margin-bottom: 12px;
}

.modal-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Modal Actions Grid */
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
  padding-top: 4px;
}

.modal-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Modal Content Variants */
.modal-content {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalFadeIn 0.18s ease;
}

.modal-content.modal-medium {
  max-width: 600px;
}

.modal-content-large {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* =================== Symbol Mapping Modal =================== */

#symbolMappingModal {
  position: fixed !important;
  inset: 0 !important;
  background: rgba(0, 0, 0, 0.7) !important;
  display: none;
  place-items: center !important;
  z-index: var(--z-modal) !important;
}

#symbolMappingModal.show {
  display: grid !important;
}

#symbolMappingModal .modal-content {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalFadeIn 0.18s ease;
}

#symbolMappingModal .modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#symbolMappingModal .modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

#symbolMappingModal .modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

#symbolMappingModal .modal-close {
  background: none;
  border: none;
  font-size: var(--font-size-2xl);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

#symbolMappingModal .modal-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* =================== Symbol Modal (alternate) =================== */

.symbol-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-toast);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.symbol-modal-overlay.show {
  opacity: 1;
}

.symbol-modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.symbol-modal-overlay.show .symbol-modal-content {
  transform: scale(1);
}

.symbol-modal-header {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.1));
  color: var(--text);
  padding: 20px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.symbol-modal-header h3 {
  margin: 0;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.symbol-modal-close {
  background: none;
  border: none;
  color: white;
  font-size: var(--font-size-2xl);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.symbol-modal-close:hover {
  opacity: 1;
}

.symbol-modal-body {
  padding: 25px;
  max-height: calc(85vh - 140px);
  overflow-y: auto;
}

.symbol-modal-footer {
  padding: 15px 25px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.symbol-modal-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.symbol-modal-empty i {
  font-size: 3rem;
  margin-bottom: 15px;
  opacity: 0.5;
}

/* =================== Custom Confirm Modal =================== */

.custom-confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.custom-confirm-modal.show {
  opacity: 1;
}

.custom-confirm-content {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  width: 90%;
  max-width: 450px;
  box-shadow: var(--elevation-4);
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.custom-confirm-modal.show .custom-confirm-content {
  transform: scale(1);
}

.custom-confirm-header {
  padding: 20px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.custom-confirm-header h4 {
  margin: 0;
  color: var(--text);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.custom-confirm-body {
  padding: 24px;
  color: var(--text);
  line-height: var(--line-height-relaxed);
}

.custom-confirm-footer {
  padding: 16px 24px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.custom-confirm-footer .btn {
  min-width: 100px;
}

/* =================== Email Instructions Modal =================== */

.email-instructions-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-toast);
  padding: 20px;
}

.instruction-steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.instruction-step {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.step-number {
  width: 40px;
  height: 40px;
  min-width: 40px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: var(--font-weight-bold);
}

.step-content {
  flex: 1;
}

.step-content h5 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-size: var(--font-size-base);
}

.step-content p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: var(--line-height-normal);
}

.step-content a {
  color: var(--color-primary);
  text-decoration: none;
  word-break: break-all;
}

.step-content a:hover {
  text-decoration: underline;
}

/* =================== Responsive =================== */

@media (max-width: 768px) {
  .modal {
    min-width: 90%;
    max-width: 90%;
  }

  #symbolMappingModal .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  #symbolMappingModal .modal-header h3 {
    font-size: var(--font-size-lg);
  }

  #symbolMappingModal .modal-body {
    padding: 16px;
  }

  .custom-confirm-content {
    width: 95%;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }

  .instruction-step {
    flex-direction: column;
  }

  .step-number {
    align-self: flex-start;
  }
}

/* =================== M7: Enhanced Modal Header (v2) =================== */

.modal-head-v2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(34,197,94,0.06) 0%, transparent 60%);
  position: relative;
}
.modal-head-v2::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, rgba(34,197,94,0.28) 0%, rgba(255,255,255,0.06) 45%, transparent 100%);
}
.modal-head-v2-left { display: flex; align-items: center; gap: 10px; }
.modal-head-icon {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: rgba(34,197,94,0.10);
  border: 1px solid rgba(34,197,94,0.28);
  display: grid; place-items: center;
  color: #22c55e;
  flex-shrink: 0;
}
.modal-head-icon i { font-size: 13px; }
.modal-head-v2-title { font: 600 16px/1 var(--font-family); letter-spacing: -0.01em; color: var(--text); }
.modal-head-v2-sub   { font: 400 11.5px/1.2 var(--font-family); color: var(--text-dim); margin-top: 3px; }

/* =================== M7: API Key Box =================== */

.api-key-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
  margin-bottom: 12px;
}
.api-key-label {
  font: 500 10.5px/1 var(--font-family);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.api-key-value {
  font: 500 12.5px/1 var(--font-mono);
  color: var(--text-secondary);
  word-break: break-all;
}

/* =================== M7: Account Option Cards =================== */

.account-options { display: flex; flex-direction: column; gap: 10px; }
.account-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 250ms ease;
  position: relative;
  overflow: hidden;
  text-align: left;
  width: 100%;
}
.account-option::before {
  content: '';
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 250ms ease;
  pointer-events: none;
}
.account-option.master::before { background: linear-gradient(135deg, rgba(34,197,94,0.07) 0%, transparent 60%); }
.account-option.slave::before  { background: linear-gradient(135deg, rgba(110,168,255,0.07) 0%, transparent 60%); }
.account-option:hover::before  { opacity: 1; }
.account-option:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.account-option.master:hover { border-color: rgba(34,197,94,0.28); }
.account-option.slave:hover  { border-color: rgba(110,168,255,0.35); }
.account-opt-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.account-option.master .account-opt-icon {
  background: rgba(34,197,94,0.10);
  border: 1px solid rgba(34,197,94,0.28);
  color: #22c55e;
}
.account-option.slave .account-opt-icon {
  background: rgba(110,168,255,0.10);
  border: 1px solid rgba(110,168,255,0.28);
  color: #6EA8FF;
}
.account-opt-text { flex: 1; }
.account-opt-title { font: 600 14px/1 var(--font-family); margin-bottom: 4px; }
.account-option.master .account-opt-title { color: #22c55e; }
.account-option.slave  .account-opt-title { color: #6EA8FF; }
.account-opt-desc { font: 400 12px/1.4 var(--font-family); color: var(--text-dim); }
.account-opt-arrow { color: var(--text-dim); transition: all 150ms ease; }
.account-option:hover .account-opt-arrow { transform: translateX(2px); }

/* =================== M7: Info Hint Box =================== */

.info-hint-box {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 11px 13px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.28);
  border-radius: 8px;
  font: 400 12px/1.5 var(--font-family);
  color: var(--text-secondary);
}
.info-hint-box i { color: #22c55e; flex-shrink: 0; margin-top: 2px; }
.info-hint-box strong { color: var(--text); font-weight: 600; }

/* =================== M7: Section Cards (Copy Settings / Volume) =================== */

.modal-sec-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  /* In a flex-column scroll body (max-height + overflow-y:auto) these cards must
     keep their natural height — without this they flex-shrink to fit and the last
     row + bottom padding get clipped (Copy Settings looked asymmetric / no bottom gap). */
  flex-shrink: 0;
}
.modal-sec-card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-sec-card-head i { color: #22c55e; font-size: 11px; }
.modal-sec-card-title {
  font: 600 11px/1 var(--font-family);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary, var(--text-dim));
}
.modal-sec-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 0; }

/* =================== M7: Toggle Rows (each row = mini card, matches prototype .setting-row) =================== */

.tgl-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
}
.tgl-row:last-child { margin-bottom: 0; }
.tgl-row-left { flex: 1; min-width: 0; }
.tgl-row-name { font: 600 13px/1.3 var(--font-family); color: var(--text); }
.tgl-row-desc { font: 400 11.5px/1.3 var(--font-family); color: var(--text-dim); margin-top: 3px; }

/* =================== M7: Toggle Switch =================== */

.tgl-sw { position: relative; width: 34px; height: 19px; flex-shrink: 0; }
.tgl-sw input { display: none; }
.tgl-sw .tgl-track {
  position: absolute; inset: 0;
  background: var(--surface-3, var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 150ms ease;
}
.tgl-sw .tgl-track::after {
  content: ''; position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 150ms ease;
}
.tgl-sw input:checked + .tgl-track { background: #22c55e; border-color: #22c55e; }
.tgl-sw input:checked + .tgl-track::after { background: #000; left: calc(100% - 15px); }

/* =================== M7: Volume Grid =================== */

.vol-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* =================== M1: Platform Option Cards =================== */

.plat-grid { display: flex; flex-direction: column; gap: 8px; }
.plat-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 200ms ease;
  position: relative;
}
.plat-option:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.25); background: var(--surface-3, var(--surface-2)); }
.plat-option.selected { border-color: var(--color-success); background: rgba(34,197,94,0.06); }
.plat-option-ic {
  width: 38px; height: 38px;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
  font-size: 16px;
  border: 1px solid transparent;
}

/* Official vendor icon marks (MetaQuotes / Spotware) — see static/img/platforms/SOURCES.md.
   Same 38px geometry as .plat-option-ic so the row reads exactly as it did with the
   Font Awesome glyphs. Neutral tile, never a brand-coloured tint: both vendors forbid
   recolouring, and a coloured wash behind a multi-colour mark muddies it. All three
   marks are near-square, so max-width/max-height alone keeps them optically level —
   no per-vendor sizing, and the aspect ratio can never be distorted. */
.plat-option-logo {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--surface-3, rgba(255,255,255,0.05));
  border: 1px solid var(--border);
  display: grid; place-items: center;
  padding: 5px;
}
.plat-option-logo img {
  display: block;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
}

.plat-option-info { flex: 1; min-width: 0; }
.plat-option-info strong { display: block; font: 600 13px/1 var(--font-family); color: var(--text); margin-bottom: 3px; }
/* display:block so the wrapped cTrader line uses its own 1.45 line-height instead of
   inheriting the parent block's much taller strut. */
.plat-option-info small  { display: block; font: 400 11.5px/1.45 var(--font-family); color: var(--text-dim); }
.plat-option-check {
  font-size: 16px;
  color: var(--color-success);
  opacity: 0;
  transition: opacity 150ms ease;
}
.plat-option.selected .plat-option-check { opacity: 1; }

/* =================== M3: Symbol Mapping =================== */

.sm-sec-title {
  font: 600 11px/1 var(--font-family);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 10px;
}
.sm-map-table { width: 100%; }
.sm-map-head, .sm-map-row {
  display: grid;
  grid-template-columns: 1fr 1fr 64px;
  gap: 0;
  border-bottom: 1px solid var(--border);
}
.sm-map-head { background: rgba(255,255,255,0.02); }
.sm-map-head span, .sm-map-row span {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.sm-map-head span { font: 600 10px/1 var(--font-family); letter-spacing: 0.08em; text-transform: uppercase; }
.sm-map-row span { color: var(--text); }
.sm-map-del {
  display: flex; align-items: center; justify-content: center;
  padding: 0 14px;
}
.sm-empty {
  text-align: center;
  padding: 28px 20px;
  color: var(--text-dim);
  font-size: 13px;
}
.sm-add-panel { padding: 14px; background: var(--surface-2); border-radius: 8px; }
.sm-add-title { font: 600 11px/1 var(--font-family); letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 12px; }
.sm-add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sm-select-label { font: 400 11.5px/1 var(--font-family); color: var(--text-dim); margin-bottom: 8px; }

/* =================== M4: Server Account Selection =================== */

.srv-list { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.srv-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 150ms ease;
}
.srv-row:last-child { border-bottom: none; }
.srv-row:hover { background: rgba(255,255,255,0.04); }
.srv-row.selected { background: rgba(34,197,94,0.06); }
.srv-check {
  width: 18px; height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 10px;
  color: transparent;
  background: transparent;
  transition: all 150ms ease;
}
.srv-check i { opacity: 0; transition: opacity 150ms ease; }
.srv-row.selected .srv-check { background: #22c55e; border-color: #22c55e; color: #000; }
.srv-row.selected .srv-check i { opacity: 1; }
.srv-row-main { flex: 1; min-width: 0; }
.srv-row-acct { font: 600 13px/1 var(--font-mono); color: var(--text); margin-bottom: 2px; }
.srv-row-meta { font: 400 11.5px/1 var(--font-family); color: var(--text-dim); }
.srv-count {
  font: 500 11px/1 var(--font-family);
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 7px;
  flex-shrink: 0;
}
.srv-empty { text-align: center; padding: 28px 20px; color: var(--text-dim); font-size: 13px; }

