/* ══════════════════════════════════════════════════════════════
   modal.css — design system for the WealthOS modal engine
   ----------------------------------------------------------------
   Styles the config-rendered `.wm-card` modal (built by modalEngine.js).
   Reuses the legacy `.modal-overlay` backdrop from style.css; everything
   inside the card lives in the `.wm-` namespace so legacy `.modal` markup
   is untouched during migration. Uses ONLY variables from style.css.

   Aesthetic: spacious dark task-card — 20px radius, gradient accent
   hairline border, generous padding, property rows for meta fields,
   labelled sections + sub-panels, pill chips, suffix-adorned inputs,
   fixed footer. Bottom-sheet on mobile. Reduced-motion aware.
   ══════════════════════════════════════════════════════════════ */

/* ── Card ─────────────────────────────────────────────────────── */
.wm-card {
  position: relative;
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card), 0 24px 64px rgba(0, 0, 0, 0.5);
  transform: translateY(12px);
  transition: transform 0.25s ease;
}
/* Gradient hairline border (accent at low opacity) drawn as an inset ring
   so it survives the card's overflow:hidden. */
.wm-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, var(--accent-glow), rgba(139, 92, 246, 0.10) 40%, var(--border) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.modal-overlay--visible .wm-card { transform: translateY(0); }

.wm-card--sm { width: 440px; }
.wm-card--lg { width: 680px; }

/* ── Header ───────────────────────────────────────────────────── */
.wm-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 30px 18px;
  flex-shrink: 0;
}
.wm-context {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.wm-title-row { display: flex; align-items: center; gap: 10px; }
.wm-title-icon {
  display: inline-flex;
  color: var(--accent-light);
  flex-shrink: 0;
}
.wm-title-icon svg { width: 20px; height: 20px; display: block; }
.wm-title {
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: var(--text-primary);
  margin: 0;
}
.wm-close {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.wm-close:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Body ─────────────────────────────────────────────────────── */
.wm-body {
  padding: 6px 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 20px;                 /* vertical rhythm between sections */
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* ── Sections ─────────────────────────────────────────────────── */
.wm-section { display: flex; flex-direction: column; gap: 14px; }
.wm-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: default;
  color: inherit;
}
button.wm-section__head { cursor: pointer; }
.wm-section__label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.wm-section__caret {
  color: var(--text-tertiary);
  font-size: 13px;
  transition: transform 0.2s;
}
.wm-section--collapsed .wm-section__caret { transform: rotate(-90deg); }
.wm-section--collapsed .wm-section__body { display: none; }

/* Sub-panel (embedded block: payment section, credit mini-form, lots…) */
.wm-section--panel .wm-section__body {
  background: var(--bg-panel-alt);
  border-radius: var(--radius-md);
  padding: 18px 18px;
}

/* ── Field grid (responsive 2-col) ────────────────────────────── */
.wm-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px 16px;
}
@media (min-width: 560px) {
  .wm-grid { grid-template-columns: 1fr 1fr; }
  .wm-field--full { grid-column: 1 / -1; }
  /* Property rows and checkboxes always span full width. */
  .wm-field--row, .wm-field--check { grid-column: 1 / -1; }
}

/* ── Field wrappers ───────────────────────────────────────────── */
.wm-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.wm-field[hidden] { display: none; }

/* Property row: label left (fixed column), control right. */
.wm-field--row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 8px 14px;
}
.wm-field--row .wm-label { margin: 0; }
.wm-field--row .wm-control { min-width: 0; }
@media (max-width: 559px) {
  .wm-field--row { grid-template-columns: 1fr; align-items: stretch; }
}

.wm-label {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}
.wm-field--stack .wm-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.wm-control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wm-hint { font-size: 11px; color: var(--text-tertiary); line-height: 1.5; }
.wm-error { font-size: 12px; color: var(--down); }

/* ── Inputs ───────────────────────────────────────────────────── */
.wm-input {
  width: 100%;
  height: 40px;
  box-sizing: border-box;
  padding: 0 12px;
  background: var(--bg-panel-alt);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea.wm-input { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
select.wm-input { appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7690' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.wm-input::placeholder { color: var(--text-tertiary); }
.wm-input:hover { border-color: var(--border); }
.wm-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-panel);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
/* Numbers use DM Mono. */
.wm-input[inputmode="decimal"],
.wm-input[type="number"] { font-family: var(--font-mono); letter-spacing: 0.3px; }

.wm-field--invalid .wm-input { border-color: var(--down); }
.wm-field--invalid .wm-input:focus { box-shadow: 0 0 0 3px var(--down-dim); }

/* Lookup / derived values that aren't user-editable render as clean text —
   no box — until explicitly unlocked (readonly removed → normal input). */
.wm-input--lookup[readonly] {
  background: transparent;
  border-color: transparent;
  padding-left: 0;
  box-shadow: none;
  color: var(--text-primary);
  cursor: default;
}
.wm-input--lookup[readonly]:hover { border-color: transparent; }

/* Label with an inline action (e.g. FX "editar"). */
.wm-label--action { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wm-fx-edit {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--accent-light);
  text-decoration: none;
  text-transform: none;
  letter-spacing: 0;
}
.wm-fx-edit:hover { text-decoration: underline; }

/* Suffix adornment (MXN, %, USD) inside the field. */
.wm-affix { position: relative; display: flex; align-items: center; }
.wm-affix .wm-input { padding-right: 52px; }
.wm-affix__suffix {
  position: absolute;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ── Chips (single-select pill group) ─────────────────────────── */
.wm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.wm-chip {
  padding: 8px 16px;
  min-height: 38px;
  background: var(--bg-panel-alt);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.wm-chip:hover { border-color: var(--border); color: var(--text-primary); }
.wm-chip--on {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Checkbox row ─────────────────────────────────────────────── */
.wm-check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
}
.wm-check input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.wm-field--check { grid-column: 1 / -1; }

.wm-static { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }

/* Custom field host — stack an internal label + control on the shared rhythm. */
.wm-custom { display: flex; flex-direction: column; gap: 7px; min-width: 0; }

/* ── Footer (fixed, non-scrolling) ────────────────────────────── */
.wm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 30px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.wm-footer .btn--ghost { margin-right: auto; }

/* Danger button fallback — the engine's confirm dialog is global, but
   .btn--danger is only defined in holdings.css / settings.css. This ensures
   danger buttons render on every page (page-specific rules still override). */
.wm-footer .btn--danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  border: none;
}
.wm-footer .btn--danger:hover {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
}

/* ── Built-in confirm dialog ──────────────────────────────────── */
.wm-confirm .wm-confirm__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 26px 28px 8px;
}
.wm-confirm__icon { display: inline-flex; color: var(--down); flex-shrink: 0; }
.wm-confirm__title { font-size: 18px; }
.wm-confirm__body { padding: 6px 28px 8px; }
.wm-confirm__msg { margin: 0; color: var(--text-secondary); font-size: 14px; line-height: 1.6; }

/* ── Legacy-body bridge ───────────────────────────────────────
   Some highly-custom modals (Registrar gasto, Vehículo) reuse their original
   markup cloned into the engine card. Restyle that legacy markup to the new
   look — scoped to .wm-body so it never touches un-migrated legacy modals. */
.wm-body .form-group { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.wm-body .form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.wm-body .form-row .form-group { flex: 1; }
.wm-body .form-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-tertiary); min-height: auto; display: block;
}
.wm-body .form-input {
  width: 100%; height: 40px; box-sizing: border-box; padding: 0 12px;
  background: var(--bg-panel-alt); border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: var(--font-body); font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.wm-body textarea.form-input { height: auto; padding: 10px 12px; }
.wm-body .form-input:hover { border-color: var(--border); }
.wm-body .form-input:focus { outline: none; border-color: var(--accent); background: var(--bg-panel); box-shadow: 0 0 0 3px var(--accent-dim); }
/* Auto-filled / derived read-only fields ("Se llena automáticamente") render as
   clean text — no box. Datepicker inputs are read-only too but keep their box. */
.wm-body .form-input[readonly]:not(.datepicker__input) {
  background: transparent;
  border-color: transparent;
  padding-left: 0;
  box-shadow: none;
  color: var(--text-primary);
  cursor: default;
}
.wm-body .form-input[readonly]:not(.datepicker__input):hover { border-color: transparent; }
.wm-body .input-affix { position: relative; display: flex; align-items: center; }
.wm-body .input-affix .form-input { padding-right: 52px; }
.wm-body .input-affix__suffix { position: absolute; right: 12px; font-family: var(--font-mono); font-size: 12px; color: var(--text-tertiary); pointer-events: none; }
.wm-body .form-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 13px; color: var(--text-secondary); margin: 4px 0; }
.wm-body .form-check input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); margin-top: 1px; flex-shrink: 0; }
.wm-body .modal__section-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--text-tertiary); border: 0; padding: 8px 0 0; margin: 0; }

/* ── Mobile: bottom sheet, footer always visible ──────────────── */
@media (max-width: 560px) {
  .modal-overlay:has(.wm-card) { align-items: flex-end; }
  .wm-card, .wm-card--sm, .wm-card--lg {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
  }
  .modal-overlay--visible .wm-card { transform: translateY(0); }
  .wm-header { padding: 22px 20px 14px; }
  .wm-body { padding: 4px 20px 20px; gap: 18px; }
  .wm-footer { padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .wm-grid { grid-template-columns: 1fr; }
}

/* ── Reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .wm-card { transition: none; transform: none; }
  .modal-overlay--visible .wm-card { transform: none; }
}
