* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f7f9fb;
  --card-bg: #ffffff;
  --border: #e4e9ef;
  --border-strong: #d0d9e3;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #38a3e0;
  --primary-dark: #2b8cc4;
  --primary-soft: #e8f4fc;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --success: #10a37f;
  --success-soft: #e6f7f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 24px 16px;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* HEADER */
.header {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 14px;
  padding: 4px 4px 8px;
}

.header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* CARD */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

/* STEP HEADER */
.step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.step-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.count-badge {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
}

/* FORM */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

input[type="text"],
input[type="tel"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input::placeholder {
  color: #9ca3af;
}

.rif-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.flex-1 {
  flex: 1;
}

.input-with-icon {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-icon input {
  padding-left: 38px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* MESSAGES */
.message {
  margin-top: 14px;
  font-size: 0.875rem;
  min-height: 0;
}

.message.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
}

.message.success {
  color: var(--success);
  background: var(--success-soft);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
}

/* COMPANY INFO */
.company-info {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-row {
  display: flex;
  gap: 8px;
  font-size: 0.9rem;
}

.info-label {
  font-weight: 600;
  color: var(--primary-dark);
}

.info-value {
  color: var(--text);
}

/* TABLE */
.table-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.machine-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.machine-table thead {
  background: var(--bg);
}

.machine-table th {
  text-align: left;
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.machine-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.machine-table tbody tr:last-child td {
  border-bottom: none;
}

.machine-table tbody tr:hover {
  background: #fafcfe;
}

.actions-col {
  text-align: right;
  width: 90px;
}

.actions-cell {
  text-align: right;
  white-space: nowrap;
}

.os-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.os-tag.windows {
  background: #e6f0fb;
  color: #1d6fc2;
}

.os-tag.mac {
  background: #f0eef7;
  color: #5b4b8a;
}

/* EMPTY STATE */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 10px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
}

/* SUBMIT ACTIONS */
.submit-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* JSON PREVIEW */
.json-preview {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.json-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.json-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.json-preview pre {
  padding: 14px 16px;
  font-size: 0.8rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  overflow-x: auto;
  background: #fcfdfe;
  color: #374151;
  max-height: 320px;
  overflow-y: auto;
}

/* RESULT BOX */
.result-box {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  border: 1px solid #bfe9d9;
}

.result-box h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--success);
}

.result-box ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-box li {
  font-size: 0.85rem;
  word-break: break-all;
}

.result-box a {
  color: var(--primary-dark);
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(16, 24, 40, 0.15);
  animation: slideUp 0.2s ease;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  pointer-events: none;
  max-width: calc(100% - 32px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}


/* PREFIJO RIF */
.rif-prefix-group {
  flex: 0 0 90px;
}

.rif-prefix {
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
  padding: 10px 8px;
}

/* TELÉFONO */
.phone-row {
  display: flex;
  gap: 8px;
}

.phone-prefix {
  flex: 0 0 110px;
  padding: 10px 8px;
  font-weight: 500;
}

.phone-row input {
  flex: 1;
  min-width: 0;
}

/* ============================================================
   OVERLAY DE CARGA
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(247, 249, 251, 0.85);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  animation: fadeIn 0.2s ease;
}

.loading-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px 40px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 280px;
  max-width: 90vw;
  text-align: center;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.loading-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 320px;
}


/* ============================================================
   ENLACES DE DESCARGA CON BOTÓN COPIAR
   ============================================================ */
.result-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #fff8e6;
  border-left: 3px solid #f0b429;
  border-radius: 6px;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.link-row a {
  flex: 1;
  min-width: 0;
  word-break: break-all;
  color: var(--primary-dark);
  text-decoration: none;
  font-size: 0.85rem;
}

.link-row a:hover {
  text-decoration: underline;
}

.copy-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.copy-link-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.copy-link-btn svg {
  flex-shrink: 0;
}

.copy-link-btn.copied {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

/* ============================================================
   LOGO
   ============================================================ */
.logo-bar {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.logo-slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 180px;
  height: 80px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.logo-slot img {
  max-height: 64px;
  max-width: 240px;
  object-fit: contain;
  display: block;
}

.logo-fallback {
  display: none;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-muted);
}

.logo-slot.no-image img {
  display: none;
}

.logo-slot.no-image .logo-fallback {
  display: inline;
}

/* ============================================================
   MODAL DE ÉXITO
   ============================================================ */
.modal-success {
  max-width: 420px;
  padding: 32px 28px 24px;
  text-align: center;
  align-items: center;
  gap: 14px;
}

.modal-success-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  margin-bottom: 4px;
}

.modal-success-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.modal-success-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}


/* ============================================================
   SWITCH SERVIDOR/CLIENTE
   ============================================================ */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 26px;
  transition: background 0.2s;
}

.switch-slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.15);
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

.switch-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  min-width: 60px;
}

.switch-label.is-server {
  color: var(--primary-dark);
}

/* Badge en la tabla */
.server-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #fff3cd;
  color: #8a6300;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ANIMATIONS */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* RESPONSIVE */
@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .rif-row {
    flex-direction: column;
    align-items: stretch;
  }

  .rif-row .btn {
    justify-content: center;
  }

  .machine-table th:nth-child(3),
  .machine-table td:nth-child(3) {
    display: none;
  }

  .submit-actions {
    flex-direction: column-reverse;
  }

  .submit-actions .btn {
    justify-content: center;
  }

  .rif-prefix-group {
    flex: 0 0 auto;
  }

  .rif-prefix-group,
  .rif-prefix-group select {
    width: 100%;
  }
}