/* ==========================================================================
   Dashboard — Valoracion Inmuebles
   Modern admin dashboard styles
   ========================================================================== */

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

:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-error: #dc2626;
  --color-error-light: #fee2e2;
  --color-muted: #64748b;
  --color-muted-light: #f1f5f9;
  --color-text: #1e293b;
  --color-text-secondary: #475569;
  --color-border: #e2e8f0;
  --color-bg: #f8fafc;
  --color-card: #ffffff;
  --color-sidebar: #1e293b;
  --color-sidebar-text: #94a3b8;
  --color-sidebar-active: #2563eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --sidebar-width: 250px;
  --topbar-height: 64px;
  --transition: 0.2s ease;
}

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   2. Layout
   -------------------------------------------------------------------------- */
.app-layout {
  min-height: 100vh;
}

.main-content {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  margin-left: var(--sidebar-width);
}

.content-body {
  flex: 1;
  padding: 24px 32px 40px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   3. Sidebar
   -------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.sidebar-close {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--color-sidebar-text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.sidebar-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  text-decoration: none;
}

.nav-item.active {
  background: var(--color-sidebar-active);
  color: #ffffff;
}

.nav-item-logout {
  color: #f87171;
}

.nav-item-logout:hover {
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-sidebar-active);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-info {
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--color-sidebar-text);
}

/* --------------------------------------------------------------------------
   4. Topbar
   -------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 32px;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--color-text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.topbar-menu-btn:hover {
  background: var(--color-muted-light);
}

/* --------------------------------------------------------------------------
   5. Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 0.95rem;
}

/* --------------------------------------------------------------------------
   6. Stats Grid
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
  padding: 20px;
  border-left: 4px solid var(--color-primary);
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-card--success {
  border-left-color: var(--color-success);
}

.stat-card--warning {
  border-left-color: var(--color-warning);
}

.stat-card--muted {
  border-left-color: var(--color-muted);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--color-text);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-weight: 500;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------------
   7. Tables
   -------------------------------------------------------------------------- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

.table tbody tr:hover {
  background: #f8fafc;
}

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

.text-right {
  text-align: right;
}

.text-muted {
  color: var(--color-muted);
}

/* --------------------------------------------------------------------------
   8. Forms
   -------------------------------------------------------------------------- */
.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.form-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.form-grid-6 {
  grid-template-columns: repeat(6, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.form-group-span2 {
  grid-column: span 2;
}

.form-input,
select.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-input::placeholder {
  color: #94a3b8;
}

.form-input-sm,
select.form-input-sm {
  padding: 7px 10px;
  font-size: 0.82rem;
}

select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.form-actions {
  position: sticky;
  bottom: 0;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  z-index: 40;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

.filters-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filters-row .form-group {
  min-width: 160px;
}

.valoracion-form {
  padding: 24px;
}

/* --------------------------------------------------------------------------
   9. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.88rem;
  font-family: var(--font);
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform 0.1s ease;
  outline: none;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
  text-decoration: none;
}

.btn-secondary {
  background: var(--color-card);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-muted-light);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--color-muted);
}

.btn-ghost:hover {
  background: var(--color-muted-light);
  color: var(--color-text);
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

/* --------------------------------------------------------------------------
   10. Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge--borrador {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.badge--publicada {
  background: var(--color-success-light);
  color: var(--color-success);
}

.badge--archivada {
  background: var(--color-muted-light);
  color: var(--color-muted);
}

.badge--nueva {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.badge--contactada {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.badge--convertida {
  background: var(--color-success-light);
  color: var(--color-success);
}

.badge--descartada {
  background: var(--color-muted-light);
  color: var(--color-muted);
}

/* --------------------------------------------------------------------------
   11. Alerts
   -------------------------------------------------------------------------- */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 20px;
}

.alert-success {
  background: var(--color-success-light);
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: var(--color-error-light);
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* --------------------------------------------------------------------------
   12. Empty State
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--color-muted);
}

.empty-state p {
  font-size: 0.95rem;
  margin-bottom: 16px;
}

/* --------------------------------------------------------------------------
   13. Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 0;
}

.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: var(--font);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.pagination-btn:hover {
  background: var(--color-muted-light);
  border-color: #cbd5e1;
}

.pagination-btn.active {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   14. Show Page
   -------------------------------------------------------------------------- */
.show-grid {
  display: grid;
  grid-template-columns: 7fr 3fr;
  gap: 24px;
}

.show-price {
  padding: 20px;
}

.show-price-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.show-price-m2 {
  font-size: 0.95rem;
  color: var(--color-muted);
  margin-top: 4px;
}

.show-features {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px;
}

.show-feature {
  flex: 1 1 140px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--color-border);
}

.show-feature-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-bottom: 4px;
}

.show-feature-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
}

.show-meta {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.show-meta dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
}

.show-meta dd {
  font-size: 0.92rem;
  color: var(--color-text);
  margin: 2px 0 0;
}

.shortcode-display {
  background: var(--color-sidebar);
  color: #e2e8f0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.82rem;
  overflow-x: auto;
  user-select: all;
  margin: 12px 0;
}

/* --------------------------------------------------------------------------
   15. Energy Badges
   -------------------------------------------------------------------------- */
.energy-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 26px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
  border-radius: 4px;
  text-transform: uppercase;
}

.energy-a { background: #16a34a; }
.energy-b { background: #65a30d; }
.energy-c { background: #ca8a04; }
.energy-d { background: #ea580c; }
.energy-e { background: #dc2626; }
.energy-f { background: #b91c1c; }
.energy-g { background: #991b1b; }

/* --------------------------------------------------------------------------
   16. Comparables
   -------------------------------------------------------------------------- */
.comparable-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.comparable-row:last-child {
  border-bottom: none;
}

/* --------------------------------------------------------------------------
   17. Login Page
   -------------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 24px;
}

.login-card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text);
  margin-top: 12px;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-form .btn {
  margin-top: 8px;
}

/* --------------------------------------------------------------------------
   18. Utilities
   -------------------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --------------------------------------------------------------------------
   19. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid-6 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .sidebar-close {
    display: block;
  }

  .topbar-menu-btn {
    display: flex;
  }

  .topbar {
    padding: 0 16px;
  }

  .content-body {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .show-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-2,
  .form-grid-3,
  .form-grid-4,
  .form-grid-6 {
    grid-template-columns: 1fr;
  }

  .form-group-span2 {
    grid-column: span 1;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

  .filters-row .form-group {
    min-width: 0;
  }

  .form-actions {
    padding: 12px 16px;
  }
}

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

  .stat-value {
    font-size: 1.4rem;
  }

  .show-price-value {
    font-size: 1.5rem;
  }

  .login-card {
    padding: 28px 20px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
