* {
    box-sizing: border-box;
}

:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --input-border: #d1d5db;
    --primary: #111827;
    --primary-2: #1f2937;
    --soft-blue-bg: #eef2ff;
    --soft-blue-text: #3730a3;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --radius: 14px;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar {
    background: #0f172a;
    color: #fff;
    padding: 14px 0;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.15);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar .brand {
    font-weight: 700;
    font-size: 22px;
    letter-spacing: -0.02em;
}

.topnav {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.topnav a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    opacity: 0.95;
}

.topnav a:hover {
    opacity: 1;
    text-decoration: underline;
}

.page {
    padding: 36px 0 48px;
}

h1 {
    margin: 0 0 24px;
    font-size: 28px;
    letter-spacing: -0.03em;
}

h2, h3 {
    margin-top: 0;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid rgba(229, 231, 235, 0.7);
}

.auth-card {
    max-width: 420px;
    margin: 48px auto;
}

.grid {
    display: grid;
    gap: 16px;
}

.stats-grid {
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 20px;
}

.two-cols {
    grid-template-columns: repeat(2, 1fr);
}

.three-cols {
    grid-template-columns: repeat(3, 1fr);
}

.stat-card {
    padding: 18px 18px 16px;
    min-height: 102px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--border);
}

.stat-card h3 {
    margin: 0;
    font-size: 15px;
    color: var(--muted);
    font-weight: 700;
}

.stat-card p {
    margin: 10px 0 0;
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--primary);
}

.stat-link {
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
    border-color: #cbd5e1;
}

.form-group {
    margin-bottom: 16px;
}

label {
    display: block;
    margin-bottom: 7px;
    font-weight: 700;
    font-size: 14px;
    color: var(--primary);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
}

textarea {
    resize: vertical;
}

.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    line-height: 1.2;
    transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn:hover {
    opacity: 0.96;
    transform: translateY(-1px);
}

.btn-light {
    background: #e5e7eb;
    color: var(--primary);
}

.btn-light:hover {
    background: #dbe0e6;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: 14px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table th {
    background: #f8fafc;
    font-weight: 800;
    font-size: 14px;
    color: var(--primary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.table td {
    font-size: 14px;
}

.table tbody tr:hover {
    background: #fafcff;
}

.table a {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 700;
}

.table a:hover {
    text-decoration: underline;
}

.table small {
    display: inline-block;
    margin-top: 4px;
    color: var(--muted);
    line-height: 1.35;
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-weight: 600;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e5e7eb;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-badge {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-badge-table {
    background: var(--soft-blue-bg);
    color: var(--soft-blue-text);
}

.priority-badge {
    font-weight: 800;
}

.priority-alta {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.priority-media {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.priority-baja {
    background: var(--success-bg);
    color: var(--success-text);
}

.lead-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 0;
}

.message-box {
    margin-top: 8px;
    padding: 14px;
    background: #f9fafb;
    border-radius: 10px;
    border: 1px solid var(--border);
    min-height: 48px;
}

.note-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.note-item:last-child {
    border-bottom: 0;
}

.note-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--muted);
}

.inline-form {
    display: flex;
    gap: 16px;
    align-items: end;
    flex-wrap: wrap;
}

.inline-form .form-group {
    flex: 1 1 280px;
    margin-bottom: 0;
}

.timeline-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.timeline-item:last-child {
    border-bottom: 0;
}

.timeline-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--muted);
}

.filters-form {
    margin-bottom: 0;
}

.filters-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 16px;
    align-items: end;
}

.filters-grid-extended {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.filters-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: end;
}

.filters-actions .btn {
    min-width: 90px;
    text-align: center;
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filters-grid-extended {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .stats-grid,
    .two-cols,
    .three-cols,
    .filters-grid,
    .filters-grid-extended {
        grid-template-columns: 1fr;
    }

    .topbar-inner,
    .lead-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form .form-group {
        width: 100%;
    }

    .filters-actions {
        width: 100%;
    }

    .filters-actions .btn {
        width: 100%;
        text-align: center;
    }

    .table th,
    .table td {
        padding: 12px 8px;
    }
}
/* =======================================================
   MEJORAS — SEMÁFORO EN TABLAS
======================================================= */
tr.row-vencido { background:#fff5f5!important; border-left:4px solid #dc2626; }
tr.row-vencido:hover { background:#fee2e2!important; }
tr.row-hoy     { background:#fffbeb!important; border-left:4px solid #f59e0b; }
tr.row-hoy:hover { background:#fef3c7!important; }
tr.row-alta    { border-left:4px solid #f97316; }
tr.row-vencido td:first-child,
tr.row-hoy td:first-child,
tr.row-alta td:first-child { padding-left:10px; }

.stat-card.stat-danger  { border-left:4px solid #dc2626; }
.stat-card.stat-danger h3 { color:#991b1b; }
.stat-card.stat-danger p  { color:#dc2626; }
.stat-card.stat-warning { border-left:4px solid #f59e0b; }
.stat-card.stat-warning h3 { color:#92400e; }
.stat-card.stat-warning p  { color:#d97706; }
.stat-card.stat-muted   { border-left:4px solid var(--border); }
.stat-card small { font-size:12px; color:var(--muted); margin-top:4px; display:block; }

.section-label {
    display:block; font-size:11px; font-weight:800;
    text-transform:uppercase; letter-spacing:.07em;
    color:var(--muted); margin-bottom:14px;
}

/* =======================================================
   PIPELINE (DASHBOARD)
======================================================= */
.pipeline-grid { display:grid; grid-template-columns:repeat(8,1fr); gap:10px; }
.pipeline-item {
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    padding:14px 8px; border-radius:12px; text-decoration:none;
    min-height:80px; gap:6px; transition:transform .15s, box-shadow .15s;
}
.pipeline-item:hover { transform:translateY(-2px); box-shadow:0 8px 20px rgba(15,23,42,.12); }
.pipeline-count { font-size:28px; font-weight:900; letter-spacing:-.03em; line-height:1; }
.pipeline-label { font-size:11px; font-weight:700; text-align:center; text-transform:uppercase; letter-spacing:.04em; opacity:.85; }

/* Leyenda semáforo */
.semaforo-legend { display:flex; gap:16px; align-items:center; margin-bottom:10px; flex-wrap:wrap; }
.legend-item { font-size:12px; font-weight:700; padding:4px 10px; border-radius:999px; }
.legend-vencido { background:#fee2e2; color:#991b1b; border-left:3px solid #dc2626; }
.legend-hoy     { background:#fef3c7; color:#92400e; border-left:3px solid #f59e0b; }
.legend-alta    { background:#fff7ed; color:#c2410c; border-left:3px solid #f97316; }

/* =======================================================
   FICHA DEL LEAD
======================================================= */
.lead-topbar { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap; }
.lead-topbar-left { display:flex; flex-direction:column; gap:6px; }
.back-link { font-size:13px; color:var(--muted); text-decoration:none; font-weight:600; }
.back-link:hover { color:var(--primary); }
.lead-name { margin:0 0 4px; font-size:26px; letter-spacing:-.03em; }
.lead-meta-badges { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.lead-id { font-size:13px; color:var(--muted); font-weight:600; }

.status-pill, .priority-pill, .urgencia-pill {
    display:inline-flex; align-items:center; padding:4px 12px;
    border-radius:999px; font-size:12px; font-weight:800; white-space:nowrap;
}
.priority-alta  { background:var(--danger-bg);  color:var(--danger-text); }
.priority-media { background:var(--warning-bg); color:var(--warning-text); }
.priority-baja  { background:var(--success-bg); color:var(--success-text); }
.urgencia-vencido { background:#fee2e2; color:#991b1b; border:1.5px solid #dc2626; }
.urgencia-hoy     { background:#fef3c7; color:#92400e; border:1.5px solid #f59e0b; }

.lead-topbar-actions { display:flex; gap:10px; flex-wrap:wrap; align-items:flex-start; padding-top:4px; }
.btn-action {
    display:inline-flex; align-items:center; gap:6px; padding:10px 16px;
    border-radius:10px; font-size:14px; font-weight:700; text-decoration:none;
    transition:transform .12s, opacity .12s; white-space:nowrap;
}
.btn-action:hover { transform:translateY(-1px); opacity:.9; }
.btn-call    { background:#dcfce7; color:#166534; }
.btn-email   { background:#dbeafe; color:#1d4ed8; }
.btn-history { background:#f3f4f6; color:#374151; }
.history-count { background:#374151; color:#fff; border-radius:999px; font-size:11px; font-weight:800; padding:1px 7px; }

.lead-layout { display:grid; grid-template-columns:1fr 300px; gap:20px; align-items:start; margin-bottom:20px; }
.lead-col-main, .lead-col-side { display:flex; flex-direction:column; }

.card-message { border-left:4px solid #3b82f6; background:#f8faff; }

.form-row-3 { display:grid; grid-template-columns:repeat(3,1fr); gap:14px; }
.form-row-2 { display:grid; grid-template-columns:repeat(2,1fr); gap:14px; }
.input-vencido { border-color:#dc2626!important; background:#fff5f5!important; }
.input-hoy     { border-color:#f59e0b!important; background:#fffbeb!important; }
.doc-block { background:#fef3c7; border:1px solid #fde68a; border-radius:10px; padding:14px; }
.doc-block label { color:#92400e; }
.form-actions { padding-top:4px; }
.btn-sm { padding:8px 16px; font-size:13px; }

.contact-list { list-style:none!important; margin:0; padding:0!important; display:flex; flex-direction:column; gap:12px; }
.contact-list li { display:flex; align-items:center; gap:10px; font-size:14px; list-style:none!important; }
.contact-icon { font-size:16px; width:22px; text-align:center; flex-shrink:0; }
.contact-link { color:#1d4ed8; font-weight:700; text-decoration:none; word-break:break-all; }
.contact-link:hover { text-decoration:underline; }

.info-list { list-style:none!important; margin:0; padding:0!important; display:flex; flex-direction:column; gap:9px; }
.info-list li { display:flex; justify-content:space-between; align-items:baseline; font-size:13px; gap:8px; list-style:none!important; }
.info-list li span:first-child { color:var(--muted); flex-shrink:0; }
.info-list li strong { text-align:right; word-break:break-all; }

/* Historial: una columna */
.historial-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; }
.historial-total { font-size:12px; font-weight:700; color:var(--muted); background:var(--bg); border:1px solid var(--border); border-radius:999px; padding:3px 10px; }
.timeline { display:flex; flex-direction:column; }
.tl-item { display:flex; gap:12px; padding-bottom:20px; }
.tl-icon { font-size:18px; flex-shrink:0; width:26px; text-align:center; margin-top:1px; }
.tl-body { flex:1; min-width:0; }
.tl-meta { display:flex; justify-content:space-between; gap:8px; margin-bottom:4px; font-size:12px; color:var(--muted); }
.tl-meta strong { color:var(--primary); font-size:13px; }
.tl-text { margin:0; font-size:14px; line-height:1.5; color:var(--text); word-break:break-word; }
.tl-old-status { color:var(--muted); }
.tl-arrow { color:var(--muted); margin:0 5px; }

/* =======================================================
   ANALÍTICAS
======================================================= */
.analytics-kpis { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:20px; }
.analytics-row  { display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-bottom:20px; }
.analytics-row > .card { margin-bottom:0; }

/* =======================================================
   RESPONSIVE
======================================================= */
@media (max-width:960px) {
    .lead-layout { grid-template-columns:1fr; }
    .form-row-3  { grid-template-columns:1fr 1fr; }
    .pipeline-grid { grid-template-columns:repeat(4,1fr); }
    .analytics-kpis { grid-template-columns:repeat(2,1fr); }
    .analytics-row  { grid-template-columns:1fr; }
}
@media (max-width:600px) {
    .lead-topbar { flex-direction:column; }
    .lead-topbar-actions { width:100%; }
    .btn-action { flex:1; justify-content:center; }
    .form-row-3, .form-row-2 { grid-template-columns:1fr; }
    .pipeline-grid { grid-template-columns:repeat(2,1fr); }
    .analytics-kpis { grid-template-columns:1fr; }
}
