/* ============================================================
   Import Calculator — scoped styles under .iam-calc
   ============================================================ */

/* Cuando la calculadora vive en una página de WP, asegurar que use todo el
   ancho disponible incluso si el bloque padre tiene constraints menores. */
.wp-block-shortcode .iam-calc,
.entry-content .iam-calc,
.wp-block-post-content .iam-calc {
  width: 100%;
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
}

.iam-calc {
  --bg:        #0a0c0f;
  --surface:   #111318;
  --border:    #1e2229;
  --border2:   #272d37;
  --muted:     #3a424f;
  --text-dim:  #6b7585;
  --text:      #c8d0dc;
  --text-hi:   #edf0f5;
  --accent:    #3b82f6;
  --accent2:   #60a5fa;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --red:       #ef4444;
  --radius:    10px;
  --radius-lg: 16px;
  --mono:      'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans:      'Syne', system-ui, -apple-system, sans-serif;

  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.iam-calc *,
.iam-calc *::before,
.iam-calc *::after {
  box-sizing: border-box;
}

/* ── Access Gate (Token validation) ──────────────────── */
.iam-access-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  background: linear-gradient(135deg, #0a0c0f 0%, #111318 100%);
  padding: 2rem;
}

.iam-gate-container {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 3rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.iam-gate-container h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-hi);
  margin: 0 0 1rem;
}

.iam-gate-container p {
  color: var(--text-dim);
  margin: 0 0 2rem;
  line-height: 1.6;
}

.iam-gate-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.iam-gate-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.iam-gate-field label {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

.iam-gate-input {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.iam-gate-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.iam-gate-btn {
  padding: 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.iam-gate-btn:hover:not(:disabled) {
  background: var(--accent2);
  transform: translateY(-2px);
}

.iam-gate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.iam-gate-message {
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  min-height: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.iam-gate-error {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.iam-gate-success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ── Topbar ─────────────────────────────────────────── */
.iam-calc .iam-topbar {
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10,12,15,0.9);
}
.iam-calc .iam-logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-hi);
  display: flex;
  align-items: center;
  gap: 10px;
}
.iam-calc .iam-logo-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.iam-calc .iam-tasa-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 100px;
}
.iam-calc .iam-tasa-badge .iam-val { color: var(--green); font-weight: 500; }
.iam-calc .iam-tasa-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  animation: iam-pulse 2s infinite;
}
@keyframes iam-pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.3; }
}

/* ── Layout ─────────────────────────────────────────── */
.iam-calc .iam-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 60px;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .iam-calc .iam-main { grid-template-columns: 1fr; }
}

/* ── Cards ──────────────────────────────────────────── */
.iam-calc .iam-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.iam-calc .iam-card + .iam-card { margin-top: 16px; }
.iam-calc .iam-card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.iam-calc .iam-card-title::before {
  content: '';
  display: inline-block;
  width: 3px; height: 14px;
  background: var(--accent);
  border-radius: 2px;
}

/* ── Tratado toggle ─────────────────────────────────── */
.iam-calc .iam-toggle-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.iam-calc .iam-toggle-btn {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.iam-calc .iam-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.iam-calc .iam-toggle-btn:not(.active):hover {
  border-color: var(--muted);
  color: var(--text);
}
.iam-calc .iam-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ── Form elements ──────────────────────────────────── */
.iam-calc .iam-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.iam-calc .iam-field-grid.iam-cols-1 { grid-template-columns: 1fr; }
.iam-calc .iam-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.iam-calc .iam-field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.iam-calc .iam-field select,
.iam-calc .iam-field input {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text-hi);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}
.iam-calc .iam-field select:focus,
.iam-calc .iam-field input:focus {
  border-color: var(--accent);
}
.iam-calc .iam-field select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.iam-calc .iam-select-wrap { position: relative; }
.iam-calc .iam-select-wrap::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  font-size: 12px;
}
.iam-calc .iam-field input[type="number"] { -moz-appearance: textfield; }
.iam-calc .iam-field input[type="number"]::-webkit-outer-spin-button,
.iam-calc .iam-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* FOB display */
.iam-calc .iam-fob-display {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--green);
  min-height: 40px;
  display: flex;
  align-items: center;
}
.iam-calc .iam-fob-display.empty { color: var(--muted); }

.iam-calc .iam-version-info {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Divider ────────────────────────────────────────── */
.iam-calc .iam-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Auto-calculated 2-col grid ─────────────────────── */
.iam-calc .iam-auto-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.iam-calc .iam-auto-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 6px;
}

/* ── Results panel ──────────────────────────────────── */
.iam-calc .iam-results-panel {
  position: sticky;
  top: 16px;
}
.iam-calc .iam-result-section { margin-bottom: 4px; }
.iam-calc .iam-result-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 0 8px;
}
.iam-calc .iam-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.iam-calc .iam-result-row:last-child { border-bottom: none; }
.iam-calc .iam-result-row.iam-row-top {
  border-top: 1px solid var(--border2);
  padding-top: 10px;
  margin-top: 4px;
}
.iam-calc .iam-result-label {
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
}
.iam-calc .iam-result-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  text-align: right;
}
.iam-calc .iam-result-value.usd { color: var(--yellow); }
.iam-calc .iam-result-value.dop { color: var(--text); }
.iam-calc .iam-strong { font-weight: 600; color: var(--text); }

/* Total */
.iam-calc .iam-total-box {
  background: linear-gradient(135deg, rgba(59,130,246,0.10), rgba(34,197,94,0.05));
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 16px;
  text-align: center;
}
.iam-calc .iam-total-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.iam-calc .iam-total-amount {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--green);
  letter-spacing: -0.02em;
}
.iam-calc .iam-total-usd {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Tasa row ───────────────────────────────────────── */
.iam-calc .iam-tasa-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.iam-calc .iam-tasa-row input { flex: 1; }
.iam-calc .iam-refresh-btn {
  padding: 10px 12px;
  background: var(--border);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  white-space: nowrap;
}
.iam-calc .iam-refresh-btn:hover {
  background: var(--border2);
  color: var(--text);
}

/* ── Historial ──────────────────────────────────────── */
.iam-calc .iam-history-card {
  margin-top: 16px;
}
.iam-calc .iam-history-card .iam-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.iam-calc .iam-history-clear {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text-dim);
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s;
}
.iam-calc .iam-history-clear:hover {
  border-color: var(--red);
  color: var(--red);
}

.iam-calc .iam-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  margin: 0 -8px;
  padding: 0 8px;
}
.iam-calc .iam-history-empty {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 16px 8px;
  line-height: 1.5;
}

.iam-calc .iam-history-item {
  display: grid;
  grid-template-columns: 1fr auto 24px;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.iam-calc .iam-history-item:hover,
.iam-calc .iam-history-item:focus {
  border-color: var(--accent);
  outline: none;
}
.iam-calc .iam-history-item-main { min-width: 0; }
.iam-calc .iam-history-item-veh {
  font-size: 12px;
  color: var(--text-hi);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.iam-calc .iam-history-item-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.iam-calc .iam-history-item-total {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--green);
  font-weight: 500;
  white-space: nowrap;
}
.iam-calc .iam-history-item-del {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  width: 22px;
  height: 22px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.iam-calc .iam-history-item-del:hover {
  color: var(--red);
  background: rgba(239,68,68,0.1);
}

/* ── Status / loading ───────────────────────────────── */
.iam-calc .iam-status-bar {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  padding: 8px;
  font-family: var(--mono);
}
.iam-calc .iam-loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10,12,15,0.85);
  z-index: 20;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}
.iam-calc .iam-loading-overlay.show { display: flex; }
.iam-calc .iam-loading-text {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.iam-calc .iam-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: iam-spin 0.7s linear infinite;
}
@keyframes iam-spin { to { transform: rotate(360deg); } }

/* ── Gate (access denied) ───────────────────────────── */
.iam-gate {
  background: #111318;
  border: 1px solid #1e2229;
  border-radius: 16px;
  padding: 32px;
  color: #c8d0dc;
  font-family: system-ui, -apple-system, sans-serif;
  text-align: center;
  max-width: 520px;
  margin: 24px auto;
}
.iam-gate h3 { color: #edf0f5; margin: 0 0 8px; }
.iam-gate p  { color: #6b7585; margin: 0 0 16px; }
.iam-gate-btn {
  display: inline-block;
  padding: 10px 22px;
  background: #3b82f6;
  color: #fff !important;
  text-decoration: none;
  border-radius: 10px;
  font-weight: 600;
}

/* ── Print ──────────────────────────────────────────── */
@media print {
  .iam-calc { background: white; color: black; }
  .iam-calc .iam-topbar,
  .iam-calc .iam-pdf-btn,
  .iam-calc .iam-toggle-row,
  .iam-calc .iam-field select,
  .iam-calc .iam-field input { display: none; }
  .iam-calc .iam-main { grid-template-columns: 1fr; max-width: 100%; }
  .iam-calc .iam-results-panel { position: static; }
  .iam-calc .iam-card { border: 1px solid #ccc; background: white; }
  .iam-calc .iam-result-value,
  .iam-calc .iam-result-label,
  .iam-calc .iam-total-amount,
  .iam-calc .iam-total-usd { color: black !important; }
  .iam-calc .iam-total-box { background: #f0f0f0 !important; border: 1px solid #ccc !important; }
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 600px) {
  .iam-calc .iam-field-grid { grid-template-columns: 1fr; }
  .iam-calc .iam-main { padding: 16px 16px 60px; gap: 16px; }
  .iam-calc .iam-topbar { padding: 0 16px; }
}
