/* ─── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg-primary:    #0a0e1a;
  --bg-secondary:  #0f1628;
  --bg-card:       rgba(16, 22, 45, 0.72);
  --bg-card-hover: rgba(22, 30, 58, 0.88);
  --border-color:  rgba(99, 130, 255, 0.14);
  --border-focus:  rgba(99, 130, 255, 0.55);

  --accent:        #6382ff;
  --accent-glow:   rgba(99, 130, 255, 0.35);
  --accent-2:      #a78bfa;
  --success:       #34d399;
  --error:         #f87171;
  --warning:       #fbbf24;
  --info:          #60a5fa;

  --text-primary:  #e8ecf8;
  --text-secondary:#8b98c4;
  --text-muted:    #4e5a7a;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-card: 0 4px 32px rgba(0,0,0,0.45), 0 1px 0 rgba(255,255,255,0.04) inset;
  --shadow-btn:  0 2px 12px rgba(99,130,255,0.3);

  --font: 'Inter', system-ui, sans-serif;
  --transition: 0.2s ease;
}

/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ─── Animated background orbs ─────────────────────────────────────────── */
.bg-orbs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  animation: drift 18s ease-in-out infinite;
}
.orb-1 { width: 520px; height: 520px; background: #4062ff; top: -120px; left: -80px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: #9c62ff; bottom: -60px; right: 5%; animation-delay: -6s; }
.orb-3 { width: 300px; height: 300px; background: #24d1c8; top: 40%; left: 50%; animation-delay: -12s; }

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(30px, -20px) scale(1.05); }
  66%       { transform: translate(-20px, 15px) scale(0.97); }
}

/* ─── Layout ────────────────────────────────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;
  max-width: 1140px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.grid-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.left-col, .right-col {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (max-width: 780px) {
  .grid-layout { grid-template-columns: 1fr; }
}

/* Evitar overflow en cualquier resolución */
*, *::before, *::after { max-width: 100%; }
img, video, iframe { max-width: 100%; height: auto; }

/* ─── Header ────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.brand { display: flex; align-items: center; gap: 1rem; }
.brand-icon { font-size: 2.2rem; filter: drop-shadow(0 0 12px var(--accent-glow)); }
.brand h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; background: linear-gradient(135deg, #e8ecf8 0%, var(--accent-2) 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.subtitle { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; font-weight: 400; letter-spacing: 0.3px; }
.app-version {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
  opacity: 0.55;
  margin-top: 2px;
  display: inline-block;
}

/* Status badge */
.status-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px; font-size: 0.8rem; font-weight: 500;
  border: 1px solid;
  transition: all var(--transition);
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; }
.badge-idle   { border-color: rgba(139,152,196,0.3); color: var(--text-secondary); }
.badge-idle   .badge-dot { background: var(--text-muted); }
.badge-running { border-color: rgba(251,191,36,0.5); color: var(--warning); }
.badge-running .badge-dot { background: var(--warning); animation: pulse-dot 1s ease-in-out infinite; }
.badge-done   { border-color: rgba(52,211,153,0.4); color: var(--success); }
.badge-done   .badge-dot { background: var(--success); }
.badge-error  { border-color: rgba(248,113,113,0.4); color: var(--error); }
.badge-error  .badge-dot { background: var(--error); }

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

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.card:hover { border-color: rgba(99,130,255,0.22); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border-color);
}
.card-header h2 {
  font-size: 0.92rem; font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; gap: 0.5rem; letter-spacing: 0.1px;
}
.card-header .icon { font-size: 1rem; }

.card-body { padding: 1.25rem 1.4rem; }

/* Tabs */
.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.tab-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-secondary); }
.tab-btn.active { background: var(--accent); color: #fff; box-shadow: 0 0 10px var(--accent-glow); }

.hint {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.72rem; font-weight: 600;
  display: grid; place-items: center;
  cursor: help;
}

/* ─── Form fields ───────────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 0.9rem; margin-bottom: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.4rem; }

label {
  font-size: 0.78rem; font-weight: 500; color: var(--text-secondary); letter-spacing: 0.3px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select.form-select {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0.55rem 0.85rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  width: 100%;
}
input:focus, select.form-select:focus {
  border-color: var(--border-focus);
  background: rgba(99,130,255,0.06);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--text-muted); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.5) brightness(1.5); cursor: pointer; }
/* Time picker: forzar dark mode para que sea legible en navegador con modo oscuro */
input[type="time"] {
  color-scheme: dark;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0.55rem 0.6rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input[type="time"]:focus {
  border-color: var(--border-focus);
  background: rgba(99,130,255,0.06);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.7) brightness(1.8); cursor: pointer; }
select.form-select option { background: var(--bg-card); color: var(--text-primary); }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 2.4rem; }
.btn-icon {
  position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: grid; place-items: center; padding: 4px;
  border-radius: 4px; transition: color var(--transition);
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { color: var(--text-secondary); }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-family: var(--font); font-weight: 600; font-size: 0.88rem; letter-spacing: 0.2px;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  padding: 0.6rem 1.1rem;
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.btn::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(rgba(255,255,255,0.08), transparent);
  opacity: 0; transition: opacity var(--transition);
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f6bff);
  color: #fff;
  box-shadow: var(--shadow-btn);
  padding: 0.75rem 1.6rem; font-size: 0.94rem;
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 20px rgba(99,130,255,0.5); transform: translateY(-1px); }

.btn-secondary {
  background: rgba(99,130,255,0.12);
  color: var(--accent);
  border: 1px solid rgba(99,130,255,0.25);
}
.btn-secondary:hover:not(:disabled) { background: rgba(99,130,255,0.2); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.05); color: var(--text-primary); }

.btn-sm { padding: 0.38rem 0.85rem; font-size: 0.8rem; border-radius: 8px; }
.btn-icon-left { font-size: 0.9rem; }

/* Spinner */
.btn-spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Env notice ────────────────────────────────────────────────────────── */
.env-notice {
  background: rgba(52,211,153,0.1); border: 1px solid rgba(52,211,153,0.25);
  border-radius: var(--radius-sm); padding: 0.65rem 1rem; font-size: 0.82rem;
  color: var(--success); margin-bottom: 0.75rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.env-icon { font-size: 1rem; }

/* ─── Summary ───────────────────────────────────────────────────────────── */
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.summary-item {
  background: rgba(255,255,255,0.03); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 0.9rem 1rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.summary-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; }
.summary-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); }

/* ─── Entries Table ─────────────────────────────────────────────────────── */
.entries-card { flex: 1; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border-color); }
th {
  padding: 0.55rem 0.75rem; text-align: left;
  font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.7px;
}
.col-actions { width: 60px; text-align: center; }

tbody tr {
  border-bottom: 1px solid rgba(99,130,255,0.07);
  transition: background var(--transition);
  animation: row-in 0.22s ease forwards;
}
@keyframes row-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
tbody tr:hover { background: rgba(99,130,255,0.05); }
tbody tr:last-child { border-bottom: none; }

td { padding: 0.55rem 0.75rem; }

.row-num { color: var(--text-muted); font-size: 0.78rem; font-weight: 500; }

td input[type="date"],
td input[type="number"] { padding: 0.38rem 0.6rem; font-size: 0.84rem; }

.btn-del {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; border-radius: 6px;
  padding: 4px 8px; transition: color var(--transition), background var(--transition);
}
.btn-del:hover { color: var(--error); background: rgba(248,113,113,0.12); }

/* Empty state */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
  display: none;
}
.empty-state.visible { display: block; }
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.5; }
.empty-state p { font-size: 0.88rem; margin-bottom: 0.35rem; }
.empty-hint { font-size: 0.78rem; color: var(--text-muted); }
.empty-hint strong { color: var(--accent); }

/* Footer */
.entries-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem;
  margin-top: 1.25rem; padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* ─── Log output ────────────────────────────────────────────────────────── */
.log-card { border-color: rgba(99,130,255,0.22); }

.log-output {
  background: rgba(0,0,0,0.35); border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  padding: 0.85rem 1rem; font-family: 'Courier New', monospace;
  font-size: 0.82rem; line-height: 1.7;
  max-height: 280px; overflow-y: auto;
  scroll-behavior: smooth;
}

.log-line { animation: log-fade 0.25s ease; display: flex; gap: 0.5rem; align-items: baseline; }
@keyframes log-fade { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: translateX(0); } }

.log-line.info    .log-msg { color: var(--text-secondary); }
.log-line.success .log-msg { color: var(--success); }
.log-line.error   .log-msg { color: var(--error); }
.log-line.done    .log-msg { color: var(--accent-2); font-weight: 600; }
.log-ts { color: var(--text-muted); font-size: 0.72rem; flex-shrink: 0; }

/* ─── Toasts ────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 99999;
  display: flex; flex-direction: column; gap: 0.6rem; pointer-events: none;
}
.toast {
  background: var(--bg-card); backdrop-filter: blur(16px);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  padding: 0.75rem 1.1rem;
  font-size: 0.84rem; display: flex; gap: 0.6rem; align-items: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: toast-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: all;
  max-width: 320px;
}
.toast.success { border-color: rgba(52,211,153,0.4); color: var(--success); }
.toast.error   { border-color: rgba(248,113,113,0.4); color: var(--error); }
.toast.info    { border-color: rgba(96,165,250,0.4); color: var(--info); }
.toast.warning { border-color: rgba(251,191,36,0.4); color: var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px) scale(0.9); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(40px) scale(0.9); }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,130,255,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,130,255,0.5); }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE  (max-width: 650px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 650px) {
  .container {
    padding: 0.75rem 0.75rem 3rem;
    width: 100%;
    box-sizing: border-box;
  }

  /* Header */
  .app-header {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
    align-items: center;
  }
  .brand { flex-direction: column; gap: 0.3rem; text-align: center; }
  .brand h1 { font-size: 1.3rem; }
  .status-badge { font-size: 0.75rem; align-self: center; }

  /* Tabs: full width */
  .tab-btn { padding: 0.85rem 0.5rem; font-size: 0.88rem; }

  /* Cards */
  .card { border-radius: var(--radius-md); }
  .card-body { padding: 0.85rem; }
  .card-header { padding: 0.85rem 1rem; }

  /* Buttons full width en footer */
  .entries-footer { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .btn { padding: 0.8rem 1rem; font-size: 0.92rem; }
  .btn-primary { font-size: 0.92rem; }

  /* Form inputs más grandes para touch */
  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="number"],
  input[type="time"],
  select.form-select {
    padding: 0.75rem 0.9rem;
    font-size: 1rem; /* Prevents auto-zoom on iOS */
  }

  /* Env notice: text wrapping */
  .env-notice {
    white-space: normal;
    word-break: break-word;
    font-size: 0.78rem;
  }

  /* ── Tabla de registros ───────────────────────────────────────────────── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Contener el overflow dentro de la card */
    max-width: calc(100vw - 1.5rem);
  }
  #entries-table {
    min-width: 440px; /* Permite scroll horizontal si hace falta */
    table-layout: fixed;
  }
  /* Columnas más compactas */
  th, td { padding: 0.5rem 0.35rem; font-size: 0.78rem; }
  td input[type="date"]   { width: 108px; min-width: 0; font-size: 0.82rem; padding: 0.35rem 0.3rem; }
  td input[type="time"]   { width:  82px; min-width: 0; font-size: 0.82rem; padding: 0.35rem 0.25rem; }
  td input[type="number"] { width:  48px; min-width: 0; font-size: 0.82rem; padding: 0.35rem 0.25rem; }
  .btn-del { padding: 10px 12px; font-size: 1.1rem; }
  .row-num { font-size: 0.75rem; width: 18px; }

  /* Summary grid: 2 columns compact */
  .summary-grid { gap: 0.5rem; }
  .summary-value { font-size: 1.3rem; }

  /* Toast en mobile: no se salga de pantalla */
  #toast-container { right: 0.5rem; left: 0.5rem; align-items: stretch; }
  .toast { max-width: 100%; }
}
