/* Modern Dark UI Design System for Idealista Scraper */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #121829;
  --bg-card: rgba(22, 30, 52, 0.6);
  --bg-card-hover: rgba(30, 41, 71, 0.8);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Brand colors */
  --color-brand: #b4db00; /* Idealista lime-green */
  --color-brand-rgb: 180, 219, 0;
  --color-primary: #6366f1; /* Indigo */
  --color-success: #10b981; /* Green */
  --color-warning: #f59e0b; /* Amber */
  --color-danger: #ef4444;  /* Red */
  --color-info: #06b6d4;    /* Cyan */
  
  --shadow-sm: 0 2px 8px -2px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 20px -4px rgba(0,0,0,0.6);
  --shadow-lg: 0 10px 30px -10px rgba(0,0,0,0.8);
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  
  --font-sans: 'Inter', sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(180, 219, 0, 0.06) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* App Layout */
.app-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 10;
  transition: var(--transition-normal);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 3rem;
  padding-left: 0.5rem;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--color-brand), var(--color-primary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--bg-primary);
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #ffffff, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item button {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-fast);
}

.nav-item button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: var(--transition-fast);
}

.nav-item.active button {
  background-color: rgba(180, 219, 0, 0.1);
  color: var(--color-brand);
  font-weight: 600;
  border-left: 3px solid var(--color-brand);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding-left: 0.85rem; /* account for border width */
}

.nav-item button:hover:not(.active button) {
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  transform: translateX(3px);
}

.sidebar-footer {
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* Main Content Area */
.main-content {
  margin-left: 260px;
  flex-grow: 1;
  padding: 2.5rem 3rem;
  max-width: 1600px;
  width: calc(100% - 260px);
}

/* Page Section Base styling */
.page-section {
  display: none;
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.page-section.active {
  display: block;
}

.section-header {
  margin-bottom: 2rem;
}

.section-title {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #ffffff 40%, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Glassmorphism Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  transition: var(--transition-normal);
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.12);
  box-shadow: var(--shadow-lg);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Grid Layouts */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stats-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.stats-value {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.stats-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stats-trend {
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.trend-up { color: var(--color-danger); }
.trend-down { color: var(--color-success); }

/* Charts Section */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

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

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Two columns content layout */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

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

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

input, select, textarea {
  width: 100%;
  background: rgba(10, 14, 26, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(180, 219, 0, 0.15);
  background: rgba(10, 14, 26, 0.9);
}

.form-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Buttons */
.btn {
  background-color: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
}

.btn:hover {
  background-color: rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--color-brand);
  border-color: var(--color-brand);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: #c5f100;
  border-color: #c5f100;
  box-shadow: 0 4px 14px 0 rgba(180, 219, 0, 0.35);
}

.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--text-primary);
}

.btn-danger:hover {
  background: #f87171;
  border-color: #f87171;
  box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.35);
}


.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Database Init Banner */
.banner {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(245, 158, 11, 0.15));
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.banner-text h4 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}

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

/* Tab Container/Selection */
.ai-toggle {
  display: flex;
  background: rgba(10, 14, 26, 0.6);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}

.ai-toggle-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.6rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: var(--transition-fast);
}

.ai-toggle-btn.active {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  font-weight: 600;
}

/* Console Terminal for Sync Progress */
.console {
  background-color: #05070f;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  height: 400px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #38bdf8; /* Light Blue */
  line-height: 1.6;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.8);
}

.console-line {
  margin-bottom: 0.35rem;
  white-space: pre-wrap;
  word-break: break-all;
}

.console-line.error { color: var(--color-danger); }
.console-line.success { color: var(--color-success); }
.console-line.warn { color: var(--color-warning); }
.console-line.info { color: #a855f7; } /* purple */

/* Sync status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.idle { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }
.status-badge.syncing { background: rgba(99, 102, 241, 0.15); color: var(--color-primary); }
.status-badge.completed { background: rgba(16, 185, 129, 0.15); color: var(--color-success); }
.status-badge.error { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); }

/* Table Styles */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

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

th {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: rgba(255,255,255,0.02);
}

.badge-estado {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-estado.activo {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
}

.badge-estado.vendido {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-danger);
}

.price-drop-badge {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.price-drop-pct {
  font-size: 0.75rem;
  color: var(--color-success);
  font-weight: 600;
}

.link-idealista {
  color: var(--color-brand);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.link-idealista:hover {
  text-decoration: underline;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 7, 15, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
  animation: fadeIn 0.3s ease forwards;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 750px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

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

.modal-body {
  padding: 1.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: rgba(255,255,255,0.02);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.detail-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.detail-val {
  font-size: 1rem;
  font-weight: 600;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  background: var(--bg-secondary);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 1rem 1.5rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.warn { border-left-color: var(--color-warning); }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Sparkles animation for pulsing elements */
.pulse-sync {
  position: relative;
}

.pulse-sync::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  background-color: var(--color-brand);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ringPulse 1.5s infinite ease-out;
}

@keyframes ringPulse {
  0% { width: 10px; height: 10px; opacity: 1; }
  100% { width: 35px; height: 35px; opacity: 0; }
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timeline-item {
  display: flex;
  gap: 1rem;
  position: relative;
  padding-bottom: 0.5rem;
}

.timeline-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 17px;
  top: 30px;
  bottom: 0;
  width: 1px;
  background: var(--border-color);
}

.timeline-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-color);
  color: var(--color-brand);
  flex-shrink: 0;
}

.timeline-content {
  flex-grow: 1;
}

.timeline-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timeline-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.15rem 0;
}

.timeline-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
