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

:root {
    --primary:    #2563eb;
    --primary-d:  #1d4ed8;
    --success:    #16a34a;
    --danger:     #dc2626;
    --warning:    #d97706;
    --info:       #0891b2;
    --orange:     #ea580c;
    --teal:       #0d9488;
    --dark:       #1e293b;
    --secondary:  #64748b;
    --light:      #f1f5f9;
    --white:      #ffffff;
    --border:     #e2e8f0;
    --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --radius:     .5rem;
    --sidebar-w:  240px;
    --topbar-h:   56px;
    font-size:    16px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f8fafc; color: #1e293b; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ===== Auth ===== */
.auth-body { background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-container { width: 100%; max-width: 400px; }
.auth-card { background: var(--white); border-radius: 1rem; padding: 2rem; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.auth-logo { font-size: 3rem; text-align: center; margin-bottom: .5rem; }
.auth-title { font-size: 1.5rem; font-weight: 700; text-align: center; color: var(--dark); }
.auth-subtitle { text-align: center; color: var(--secondary); margin-bottom: 1.5rem; font-size: .9rem; }
.auth-form .form-group { margin-bottom: 1rem; }

/* ===== Layout ===== */
.sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-w);
    background: var(--dark); color: var(--white); z-index: 200;
    display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .25s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo { font-size: 1.1rem; font-weight: 700; }
.sidebar-close { background: none; border: none; color: var(--white); font-size: 1.1rem; cursor: pointer; padding: .25rem; }
.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; color: rgba(255,255,255,.8); transition: background .15s, color .15s; font-size: .95rem; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.1); color: var(--white); text-decoration: none; }
.nav-item.active { border-left: 3px solid var(--primary); }
.nav-icon { font-size: 1.1rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,.1); }
.user-info { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-name { font-size: .9rem; font-weight: 600; }
.user-role { font-size: .75rem; color: rgba(255,255,255,.6); text-transform: uppercase; }
.btn-logout { display: block; text-align: center; background: rgba(255,255,255,.1); color: var(--white); padding: .5rem; border-radius: var(--radius); font-size: .85rem; transition: background .15s; }
.btn-logout:hover { background: rgba(255,255,255,.2); text-decoration: none; }

.main-wrapper { min-height: 100vh; }
.topbar { height: var(--topbar-h); background: var(--white); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1rem; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.btn-menu { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: .25rem; color: var(--dark); }
.topbar-title { font-size: 1.1rem; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.badge-alert { background: var(--danger); color: var(--white); padding: .25rem .6rem; border-radius: 2rem; font-size: .8rem; cursor: pointer; }
.main-content { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150; }
.overlay.show { display: block; }

@media (min-width: 768px) {
    .sidebar { transform: translateX(0); }
    .sidebar-close { display: none; }
    .main-wrapper { margin-left: var(--sidebar-w); }
    .btn-menu { display: none; }
    .main-content { padding: 1.5rem 2rem; }
}

/* ===== Flash / Alerts ===== */
.flash { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; margin: 0 1rem .5rem; border-radius: var(--radius); font-size: .9rem; }
.flash button { background: none; border: none; cursor: pointer; font-size: 1rem; opacity: .7; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ===== Cards ===== */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: .875rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 1rem; margin: 0; }
.card-body { padding: 1rem; }
.card-alert { border-left: 3px solid var(--warning); }
.mt-4 { margin-top: 1rem; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius); border: none; cursor: pointer; font-size: .875rem; font-weight: 500; transition: opacity .15s, box-shadow .15s; text-decoration: none; }
.btn:hover { opacity: .85; text-decoration: none; }
.btn-primary  { background: var(--primary); color: var(--white); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--dark); }
.btn-outline:hover { background: var(--light); }
.btn-danger   { background: var(--danger); color: var(--white); }
.btn-whatsapp { background: #25d366; color: var(--white); }
.btn-sm  { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: .75rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; color: #374151; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .875rem; background: var(--white); color: var(--dark); transition: border-color .15s;
    appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { 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 .75rem center; padding-right: 2rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media(min-width:640px){ .form-grid { grid-template-columns: 1fr 1fr; } }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.form-row > * { flex: 1; min-width: 160px; }
.form-actions { display: flex; gap: .75rem; justify-content: flex-end; padding-top: 1rem; border-top: 1px solid var(--border); margin-top: 1rem; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 2rem; font-size: .75rem; font-weight: 600; }
.badge-primary   { background: #dbeafe; color: #1d4ed8; }
.badge-success   { background: #dcfce7; color: #166534; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-info      { background: #cffafe; color: #155e75; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-dark      { background: #1e293b; color: var(--white); }
.badge-orange    { background: #ffedd5; color: #9a3412; }
.badge-teal      { background: #ccfbf1; color: #134e4a; }
.badge-light     { background: var(--light); color: var(--secondary); }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media(min-width:768px){ .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 1rem; display: flex; align-items: center; gap: .75rem; box-shadow: var(--shadow); }
.stat-icon { font-size: 1.75rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .78rem; color: var(--secondary); margin-top: .2rem; }
.stat-success { border-left: 3px solid var(--success); }
.stat-info    { border-left: 3px solid var(--info); }
.stat-warning { border-left: 3px solid var(--warning); }

/* ===== Dashboard Grid ===== */
.dashboard-grid { display: grid; gap: 1rem; }
@media(min-width:768px){ .dashboard-grid { grid-template-columns: 1fr 1fr; } }
@media(min-width:1024px){ .dashboard-grid { grid-template-columns: repeat(3, 1fr); } }

/* ===== Funnel ===== */
.funnel-item { margin-bottom: .65rem; }
.funnel-label { display: flex; justify-content: space-between; align-items: center; margin-bottom: .25rem; }
.funnel-bar { height: 8px; background: var(--light); border-radius: 4px; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }
.bg-secondary { background: var(--secondary); }
.bg-info      { background: var(--info); }
.bg-primary   { background: var(--primary); }
.bg-warning   { background: var(--warning); }
.bg-orange    { background: var(--orange); }
.bg-teal      { background: var(--teal); }
.bg-success   { background: var(--success); }
.bg-danger    { background: var(--danger); }
.bg-dark      { background: var(--dark); }

/* ===== Origen / Ranking ===== */
.origen-item { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
.origen-item:last-child { border: none; }
.ranking-item { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.ranking-item:last-child { border: none; }
.ranking-pos { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: var(--white); font-size: .75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ranking-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--light); color: var(--secondary); font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ranking-info { flex: 1; }
.ranking-name { font-weight: 600; font-size: .875rem; }
.ranking-stats { font-size: .75rem; color: var(--secondary); }

/* ===== Recordatorios ===== */
.recordatorio-item { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.recordatorio-item:last-child { border: none; }
.rec-desc { font-size: .8rem; color: var(--secondary); margin: .2rem 0; }
.rec-fecha { font-size: .75rem; }

/* ===== Terrenos Resumen ===== */
.terrenos-resumen { display: flex; gap: 1rem; flex-wrap: wrap; }
.tres-item { flex: 1; min-width: 80px; padding: .75rem 1rem; border-radius: var(--radius); text-align: center; font-size: .875rem; }
.tres-disponible { background: #dcfce7; color: #166534; }
.tres-reservado  { background: #fef3c7; color: #92400e; }
.tres-vendido    { background: #fee2e2; color: #991b1b; }

/* ===== Filters bar ===== */
.filters-bar { background: var(--white); border-radius: var(--radius); padding: .75rem; margin-bottom: .75rem; box-shadow: var(--shadow); }
.filters-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters-form > * { flex: 1; min-width: 140px; }
.filters-form .btn { flex: 0 0 auto; }

/* ===== Page actions ===== */
.page-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; gap: .5rem; flex-wrap: wrap; }
.page-header  { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.d-flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ===== Prospectos list ===== */
.prospectos-list { display: flex; flex-direction: column; gap: .75rem; }
.prospecto-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: .875rem; }
.pc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .5rem; gap: .5rem; }
.pc-name { font-weight: 600; font-size: 1rem; }
.pc-name a { color: var(--dark); }
.pc-name a:hover { color: var(--primary); }
.estado-select { border: none; background: transparent; font-size: .75rem; font-weight: 600; cursor: pointer; padding: .2rem .4rem; border-radius: 2rem; }
.pc-info { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .5rem; }
.pc-tel { font-size: .875rem; font-weight: 500; }
.pc-email { font-size: .8rem; color: var(--secondary); }
.pc-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .5rem; }
.pc-asesor, .pc-fecha { font-size: .75rem; color: var(--secondary); }
.pc-notas { font-size: .8rem; color: var(--secondary); background: var(--light); padding: .4rem .6rem; border-radius: .3rem; }
.pc-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ===== Terrenos grid ===== */
.terrenos-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media(min-width:480px){ .terrenos-grid { grid-template-columns: 1fr 1fr; } }
@media(min-width:900px){ .terrenos-grid { grid-template-columns: repeat(3, 1fr); } }
.terreno-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.tc-img { height: 160px; overflow: hidden; background: var(--light); display: flex; align-items: center; justify-content: center; }
.tc-img img { width: 100%; height: 100%; object-fit: cover; }
.tc-no-img { font-size: 3rem; }
.tc-body { padding: .875rem; flex: 1; }
.tc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .35rem; }
.tc-codigo { font-weight: 700; font-size: .95rem; }
.tc-nombre { font-size: .9rem; color: var(--dark); margin-bottom: .2rem; }
.tc-proyecto { font-size: .75rem; color: var(--secondary); margin-bottom: .4rem; }
.tc-precio { font-size: 1.1rem; font-weight: 700; color: var(--success); }
.tc-area, .tc-ubicacion { font-size: .78rem; color: var(--secondary); margin-top: .2rem; }
.tc-actions { padding: .75rem .875rem; border-top: 1px solid var(--border); display: flex; gap: .4rem; }
.terrenos-badges { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ===== Galería ===== */
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: .5rem; margin-bottom: 1rem; }
.galeria-item { position: relative; border-radius: var(--radius); overflow: hidden; }
.galeria-item img { width: 100%; height: 120px; object-fit: cover; }
.galeria-principal { border: 3px solid var(--primary); }
.btn-del-img { position: absolute; top: .3rem; right: .3rem; background: rgba(0,0,0,.6); color: var(--white); border: none; border-radius: 50%; width: 22px; height: 22px; font-size: .75rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* ===== Detail ===== */
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
.detail-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.detail-grid { display: grid; gap: 1rem; }
@media(min-width:768px){ .detail-grid { grid-template-columns: 2fr 1fr; } }
.info-list { display: flex; flex-direction: column; gap: .5rem; }
.info-item { display: flex; flex-direction: column; font-size: .875rem; }
.info-label { font-size: .75rem; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .04em; }
.notas-box { background: var(--light); border-radius: var(--radius); padding: .75rem; font-size: .875rem; color: #374151; }

/* ===== Estados grid ===== */
.estados-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.btn-estado { border: 2px solid transparent; border-radius: var(--radius); padding: .5rem; font-size: .78rem; font-weight: 600; cursor: pointer; transition: opacity .15s, transform .1s; }
.btn-estado:hover { opacity: .85; transform: translateY(-1px); }
.btn-estado.active { border-color: var(--dark); }
.btn-secondary { background: #f1f5f9; color: #475569; }
.btn-info      { background: #cffafe; color: #155e75; }
.btn-primary   { background: #dbeafe; color: #1d4ed8; }
.btn-warning   { background: #fef3c7; color: #92400e; }
.btn-orange    { background: #ffedd5; color: #9a3412; }
.btn-teal      { background: #ccfbf1; color: #134e4a; }
.btn-success   { background: #dcfce7; color: #166534; }
.btn-danger    { background: #fee2e2; color: #991b1b; }
.btn-dark      { background: #1e293b; color: var(--white); }

/* ===== Interacciones ===== */
.interaccion-form { display: flex; flex-direction: column; gap: .75rem; }
.inter-item { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.inter-item:last-child { border: none; }
.inter-header { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .3rem; }
.inter-tipo { font-size: .7rem; font-weight: 700; padding: .2rem .5rem; border-radius: 2rem; text-transform: uppercase; }
.inter-nota     { background: #f1f5f9; color: #475569; }
.inter-llamada  { background: #dbeafe; color: #1d4ed8; }
.inter-whatsapp { background: #dcfce7; color: #166534; }
.inter-visita   { background: #fef3c7; color: #92400e; }
.inter-email    { background: #cffafe; color: #155e75; }
.inter-cambio_estado { background: #f3e8ff; color: #6b21a8; }
.inter-user { font-size: .78rem; font-weight: 600; }
.inter-fecha { font-size: .75rem; color: var(--secondary); margin-left: auto; }
.inter-desc { font-size: .875rem; color: #374151; }
.inter-estado-change { font-size: .75rem; color: var(--secondary); margin-top: .25rem; }

/* ===== Asesores ===== */
.asesores-list { display: flex; flex-direction: column; gap: .75rem; }
.asesor-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: .875rem; display: flex; align-items: center; gap: .75rem; }
.ac-rank { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #60a5fa); color: var(--white); font-weight: 700; font-size: .875rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ac-avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--light); color: var(--secondary); font-weight: 700; font-size: 1.2rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ac-info { flex: 1; }
.ac-name { font-weight: 600; }
.ac-stats { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .78rem; color: var(--secondary); margin-top: .2rem; }
.ac-actions { display: flex; gap: .4rem; }

/* ===== Pagination ===== */
.pagination { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: center; margin-top: 1rem; }
.page-link { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--white); color: var(--dark); font-size: .875rem; transition: background .15s; }
.page-link:hover { background: var(--light); text-decoration: none; }
.page-link.active { background: var(--primary); color: var(--white); border-color: var(--primary); }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--secondary); }
.empty-icon  { font-size: 3rem; margin-bottom: .75rem; }

/* ===== Utilities ===== */
.text-muted  { color: var(--secondary); font-size: .875rem; }
.text-danger { color: var(--danger); }
