/* Design System Tokens */
:root {
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Harmonious Dark Palette */
  --bg-app: #0a0e17;
  --bg-card: rgba(22, 28, 45, 0.7);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-glow: rgba(59, 130, 246, 0.35);

  --color-success: #10b981;
  --color-success-bg: rgba(16, 185, 129, 0.15);
  --color-success-border: rgba(16, 185, 129, 0.3);

  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.15);
  --color-warning-border: rgba(245, 158, 11, 0.3);

  --color-error: #ef4444;
  --color-error-bg: rgba(239, 68, 68, 0.15);
  --color-error-border: rgba(239, 68, 68, 0.3);

  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Global Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Lock vertical page scroll */
  -webkit-font-smoothing: antialiased;
}

/* Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  overflow: hidden;
}

/* Header */
.app-header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--bg-card-border);
  margin-bottom: 1.5rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  border-radius: 8px;
  padding: 4px;
  margin: -4px;
  transition: opacity var(--transition-fast);
}

.logo-link:hover {
  opacity: 0.85;
}

/* Decorative Paraguay Flag Stripes */
.flag-stripe {
  width: 4px;
  height: 40px;
  border-radius: 2px;
}
.flag-stripe.red { background-color: #d52b1e; }
.flag-stripe.white { background-color: #ffffff; }
.flag-stripe.blue { background-color: #0038a8; }

.logo-text h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Status Panel */
.status-panel {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: rgba(30, 41, 59, 0.5);
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  border: 1px solid var(--bg-card-border);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
  display: inline-block;
}

.status-dot.idle {
  background-color: var(--color-success);
  box-shadow: 0 0 10px var(--color-success);
}

.status-dot.running {
  background-color: var(--color-warning);
  box-shadow: 0 0 12px var(--color-warning);
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; transform: scale(1.1); }
}

.status-text {
  font-size: 0.925rem;
  font-weight: 500;
}

/* Buttons */
.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
  box-shadow: 0 4px 12px var(--color-primary-glow);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  background-color: var(--text-muted);
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-danger {
  background-color: var(--color-error);
  color: white;
  box-shadow: 0 4px 12px var(--color-error-border);
}

.btn-danger:hover:not(:disabled) {
  background-color: #dc2626;
  transform: translateY(-1px);
}

.btn-danger:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--bg-card-border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.15);
}

.btn-sm {
  font-size: 0.775rem;
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
}

/* Spinner */
.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

.btn-primary.running .btn-spinner {
  display: inline-block;
}

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

/* Dashboard Grid Layout */
.app-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.dashboard-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

/* Cards (Glassmorphism) */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  border: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.card-header {
  flex: 0 0 auto;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bg-card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.refresh-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.auto-refresh-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.375rem 0.625rem;
  border-radius: 99px;
  border: 1px solid var(--bg-card-border);
  transition: all var(--transition-fast);
}

.auto-refresh-indicator.fast {
  color: var(--color-primary);
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.1);
}

.auto-refresh-indicator svg {
  transition: transform 0.2s ease;
}

.spin-slow {
  animation: spin 3s linear infinite;
}

.spin-fast {
  animation: spin 1s linear infinite;
}

.card-body {
  flex: 1 1 auto;
  padding: 1.25rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* History Table */
.table-container {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: auto;
  width: 100%;
  min-height: 0;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.history-table th {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--bg-card-border);
}

.history-table td {
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.history-table tbody tr {
  transition: background-color var(--transition-fast);
}

.history-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.history-table tbody tr.selected-row {
  background-color: rgba(59, 130, 246, 0.08);
}
.history-table tbody tr.selected-row td:first-child {
  border-left: 3px solid var(--color-primary);
  padding-left: calc(1rem - 3px);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge.en_progreso {
  background-color: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid var(--color-warning-border);
}

.badge.exitoso {
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid var(--color-success-border);
}

.badge.fallido {
  background-color: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid var(--color-error-border);
}

/* Console Logger Card */
.console-card {
  height: 100%;
}

.console-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
  background-color: #05070c;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.console-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.console-id-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: rgba(255, 255, 255, 0.06);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

/* Origin badge (A / M) */
.origin-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
}

.origin-badge.auto {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.origin-badge.manual {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.origin-badge.unknown {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--bg-card-border);
}

.console-output {
  flex: 1 1 auto;
  min-height: 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: #a5b4fc;
  padding: 1.25rem;
  margin: 0;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Utils */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-bold { font-weight: 600; }

/* Footer */
.app-footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 1rem 0 0 0;
  border-top: 1px solid var(--bg-card-border);
  margin-top: 1.5rem;
  color: var(--text-muted);
  font-size: 0.825rem;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.app-footer a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* Progress Bar (full-width row under running execution) */
.progress-cell {
  padding: 0 1rem 0.75rem !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.progress-bar-container {
  width: 100%;
  background-color: rgba(255, 255, 255, 0.06);
  border-radius: 9999px;
  overflow: hidden;
  height: 22px;
  position: relative;
  border: 1px solid var(--bg-card-border);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #60a5fa, #a78bfa);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
  transition: width 0.5s ease;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.72rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

/* Running row subtle highlight */
.running-row td {
  background-color: rgba(59, 130, 246, 0.04);
}

.progress-row td {
  background-color: rgba(59, 130, 246, 0.04);
}

/* Table number columns alignment */
.col-num {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
}
.col-id {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.col-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* New Record Badge */
.new-record-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--color-success);
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  letter-spacing: 0.04em;
  vertical-align: middle;
  margin-left: 0.3rem;
  animation: fadein 0.4s ease;
}

@keyframes fadein {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1); }
}

/* ─── Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.modal-open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: linear-gradient(145deg, rgba(22, 28, 50, 0.98), rgba(15, 20, 38, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 2rem;
  max-width: 420px;
  width: calc(100% - 2rem);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.05);
  transform: scale(0.92) translateY(10px);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.modal-overlay.modal-open .modal {
  transform: scale(1) translateY(0);
}

.modal-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}

.modal-icon.danger {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  color: var(--color-error);
}

.modal-icon.primary {
  background: var(--color-primary-subtle);
  border: 1px solid rgba(0, 102, 204, 0.2);
  color: var(--color-primary);
}

.modal h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.modal p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.75rem;
}

.modal p strong {
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.modal-actions .btn {
  flex: 1;
}

/* ─── Toasts ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(22, 28, 50, 0.97);
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  padding: 0.875rem 1rem;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
  pointer-events: all;
  opacity: 0;
  transform: translateX(120%);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(0);
}

.toast-success { border-left: 3px solid var(--color-success); }
.toast-error   { border-left: 3px solid var(--color-error); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-info    { border-left: 3px solid var(--color-primary); }

.toast-icon {
  flex-shrink: 0;
  display: flex;
}
.toast-success .toast-icon { color: var(--color-success); }
.toast-error   .toast-icon { color: var(--color-error); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-info    .toast-icon { color: var(--color-primary); }

.toast-message {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-primary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.25rem;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

