*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222535;
  --border: #2d3148;
  --primary: #5865f2;
  --primary-hover: #4752c4;
  --success: #23a55a;
  --danger: #ed4245;
  --warning: #f0b232;
  --text: #e3e5e8;
  --text-muted: #81848f;
  --bcn: #d4001a;
  --mad: #c8102e;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.5; }

/* LOGIN */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 380px; padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem 2rem; box-shadow: var(--shadow); }
.login-logo { color: var(--primary); margin-bottom: 1rem; }
.login-card h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 2rem; }

/* FORMS */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.6rem 0.75rem; color: var(--text); font-size: 0.9rem; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--primary); }
.error-msg { background: rgba(237,66,69,0.15); border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.85rem; margin-bottom: 0.75rem; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: all 0.15s; text-decoration: none; }
.btn-full { width: 100%; justify-content: center; padding: 0.75rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: rgba(237,66,69,0.15); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }
.btn-run { background: rgba(88,101,242,0.15); color: var(--primary); border: 1px solid var(--primary); }
.btn-run:hover { background: var(--primary); color: #fff; }

/* LAYOUT */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.navbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 1.5rem; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.navbar-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1rem; color: var(--text); }
.navbar-brand svg { color: var(--primary); }
.navbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.main { padding: 2rem 1.5rem; max-width: 1200px; margin: 0 auto; width: 100%; }

/* CITY SECTION */
.city-section { margin-bottom: 2.5rem; }
.city-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 2px solid var(--border); }
.city-badge { font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 99px; text-transform: uppercase; letter-spacing: 0.08em; }
.badge-bcn { background: rgba(212,0,26,0.15); color: var(--bcn); border: 1px solid rgba(212,0,26,0.3); }
.badge-mad { background: rgba(200,16,46,0.15); color: var(--mad); border: 1px solid rgba(200,16,46,0.3); }
.city-header h2 { font-size: 1.1rem; font-weight: 700; }
.city-header .city-count { color: var(--text-muted); font-size: 0.85rem; margin-left: auto; }

/* CARDS GRID */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.25rem; }

/* AUTOMATION CARD */
.auto-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; transition: border-color 0.2s; }
.auto-card.enabled { border-color: rgba(88,101,242,0.4); }
.auto-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; gap: 0.75rem; }
.auto-card-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.2rem; }
.auto-card-url { font-size: 0.75rem; color: var(--text-muted); word-break: break-all; }

/* TOGGLE */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 24px; cursor: pointer; transition: all 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--text-muted); border-radius: 50%; transition: all 0.2s; }
.toggle input:checked + .toggle-slider { background: rgba(88,101,242,0.2); border-color: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: var(--primary); }

/* STATS ROW */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat-item { display: flex; flex-direction: column; gap: 0.1rem; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 0.9rem; font-weight: 700; }

/* STATUS BADGE */
.status-badge { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 99px; }
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-idle { color: var(--text-muted); background: var(--surface2); }
.status-running { color: var(--warning); background: rgba(240,178,50,0.1); animation: pulse 1.5s infinite; }
.status-success { color: var(--success); background: rgba(35,165,90,0.1); }
.status-error { color: var(--danger); background: rgba(237,66,69,0.1); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* INTERVAL */
.interval-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.interval-row input { width: 70px; }
.interval-row span { font-size: 0.8rem; color: var(--text-muted); }

/* CARD ACTIONS */
.card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* LOGS MODAL */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 200; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 90%; max-width: 700px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.log-entry { display: flex; gap: 0.75rem; padding: 0.35rem 0; border-bottom: 1px solid rgba(255,255,255,0.04); font-size: 0.8rem; font-family: 'SF Mono', 'Consolas', monospace; }
.log-ts { color: var(--text-muted); flex-shrink: 0; }
.log-info { color: var(--text); }
.log-success { color: var(--success); }
.log-error { color: var(--danger); }
.log-warning { color: var(--warning); }
.log-empty { color: var(--text-muted); text-align: center; padding: 2rem; }

/* PASSWORD MODAL */
.modal-sm { max-width: 380px; }

/* TOAST */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 300; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.65rem 1rem; font-size: 0.85rem; box-shadow: var(--shadow); animation: slideIn 0.2s ease; max-width: 300px; }
.toast-success { border-color: var(--success); color: var(--success); }
.toast-error { border-color: var(--danger); color: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* LAST RUN */
.last-run { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.5rem; }

/* RESPONSIVE */
@media (max-width: 640px) {
  .main { padding: 1rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .navbar { padding: 0 1rem; }
}

/* ── TYPE GROUP ──────────────────────────────────────────────────────────────── */
.type-group { margin-bottom: 2rem; }
.type-group-header {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.9rem;
  padding: 0.5rem 0.75rem; background: var(--surface2); border-radius: 8px;
  border-left: 3px solid var(--primary);
}
.type-group-header h3 { font-size: 0.9rem; font-weight: 700; flex: 1; }
.type-group-header .type-url { font-size: 0.72rem; color: var(--text-muted); }
.btn-add-instance { background: rgba(88,101,242,0.12); color: var(--primary); border: 1px dashed var(--primary); }
.btn-add-instance:hover { background: var(--primary); color: #fff; border-style: solid; }

/* ── INSTANCE CARD ───────────────────────────────────────────────────────────── */
.instance-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; transition: border-color 0.2s;
}
.instance-card.enabled { border-color: rgba(88,101,242,0.4); }
.instance-card-header { display: flex; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.75rem; }
.instance-label { font-weight: 700; font-size: 0.9rem; flex: 1; }
.instance-config-summary { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.6; }
.instance-config-summary span { display: inline-block; background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: 0.1rem 0.45rem; margin: 0.15rem 0.2rem 0.15rem 0; }

/* ── CONFIG MODAL ────────────────────────────────────────────────────────────── */
.modal-lg { max-width: 680px; }
.modal-body { padding: 0; }
.config-form { display: flex; flex-direction: column; gap: 0; }
.config-section { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.config-section:last-child { border-bottom: none; }
.config-section-title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--primary); margin-bottom: 0.9rem;
}
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.fields-grid .field-full { grid-column: 1 / -1; }
.field-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.3rem; display: block; }
.field-label .req { color: var(--danger); margin-left: 2px; }

/* Multicheck */
.multicheck-grid { display: grid; gap: 0.35rem; }
.multicheck-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.multicheck-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.mc-item { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; padding: 0.25rem 0.4rem; border-radius: 5px; transition: background 0.1s; font-size: 0.8rem; user-select: none; }
.mc-item:hover { background: var(--surface2); }
.mc-item input[type="checkbox"] { accent-color: var(--primary); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }
.mc-select-all { font-size: 0.72rem; color: var(--primary); cursor: pointer; margin-bottom: 0.4rem; display: inline-block; }
.mc-select-all:hover { text-decoration: underline; }

textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.75rem; color: var(--text); font-size: 0.9rem; outline: none; resize: vertical; min-height: 70px; font-family: inherit; }
textarea:focus { border-color: var(--primary); }

.modal-footer { padding: 0.9rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.6rem; }

/* Instance label input at top of form */
.instance-label-field { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface2); }
.instance-label-field input { font-size: 1rem; font-weight: 600; }

/* Cita concertada card */
.instance-card.cita-confirmed {
  border: 1.5px solid var(--success);
  background: linear-gradient(135deg, #0f1117 0%, #0d1f14 100%);
}
.cita-badge {
  font-size: 0.72rem; font-weight: 700; padding: 0.2rem 0.6rem;
  background: var(--success); color: #fff; border-radius: 99px;
  white-space: nowrap;
}
.cita-info { margin: 0.75rem 0; display: flex; flex-direction: column; gap: 0.4rem; }
.cita-info-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.82rem; }
.cita-info-label { color: var(--text-muted); font-size: 0.72rem; font-weight: 600; min-width: 70px; }
.cita-code-link {
  font-weight: 700; color: var(--success); font-size: 0.9rem;
  text-decoration: none; font-family: monospace; letter-spacing: 0.03em;
}
.cita-code-link:hover { text-decoration: underline; }

/* Cita inline (badge + código dentro de la card normal) */
.cita-inline {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 0.5rem 0 0.25rem; font-size: 0.82rem;
}
.instance-card.enabled .cita-badge { background: var(--success); }

/* Screenshots modal */
.screenshots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.screenshot-item {
  display: flex; flex-direction: column; gap: 0.4rem;
}
.screenshot-thumb {
  width: 100%; border-radius: 6px; border: 1px solid var(--border);
  cursor: pointer; transition: opacity 0.15s;
}
.screenshot-thumb:hover { opacity: 0.85; }
.screenshot-label {
  font-size: 0.75rem; color: var(--text-muted); text-align: center;
}

/* Screenshots por ejecución */
.run-group { margin-bottom: 1.5rem; }
.run-group-title {
  font-size: 0.75rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.4rem 0; border-bottom: 1px solid var(--border); margin-bottom: 0.75rem;
}
.run-group-shots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

/* Per-day schedule field */
.pds-grid { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.25rem 0; }
.pds-day { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.pds-day-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem; background: var(--surface2); cursor: default;
}
.pds-toggle { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.85rem; cursor: pointer; min-width: 90px; }
.pds-summary { font-size: 0.75rem; color: var(--text-muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pds-slots { padding: 0.6rem 0.75rem; border-top: 1px solid var(--border); }
.pds-any { margin-bottom: 0.4rem; font-size: 0.8rem; font-weight: 600; }
.pds-horarios-grid { display: flex; flex-wrap: wrap; gap: 0.2rem 0.5rem; }
.pds-horarios-grid .mc-item { font-size: 0.78rem; min-width: 52px; }
