:root {
    --primary: #18374c;
    --primary-2: #244f69;
    --secondary: #4a768d;
    --accent: #f2a541;
    --accent-dark: #d9871d;
    --canvas: #edf2f4;
    --surface: #ffffff;
    --surface-soft: #f6f9fa;
    --selection: #dce8ed;
    --border: #d2dfe4;
    --border-strong: #a8bfca;
    --text: #18374c;
    --muted: #66818f;
    --success: #2f7d52;
    --danger: #a33c42;
    --warning: #a7650d;
    --shadow: 0 18px 55px rgba(24, 55, 76, .10);
    --shadow-soft: 0 5px 18px rgba(24, 55, 76, .07);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 14px; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
::selection { background: #c4d6df; color: var(--primary); }

.app-shell { display: grid; grid-template-columns: 258px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; z-index: 20; display: flex; flex-direction: column; height: 100vh; padding: 28px 20px 20px; background: var(--primary); color: #fff; }
.brand { display: flex; align-items: center; gap: 9px; padding: 0 12px 28px; color: #fff; text-decoration: none; }
.brand-logo-white { display: block; width: 108px; height: auto; filter: brightness(0) invert(1); }
.brand-logo-large { width: 172px; }
.auth-brand-lockup { display: flex; align-items: center; gap: 13px; }
.brand-product { color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .22em; }
.main-nav { display: flex; flex-direction: column; gap: 6px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; color: rgba(255,255,255,.72); font-weight: 700; text-decoration: none; transition: .18s ease; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-icon { display: grid; width: 24px; height: 24px; place-items: center; font-size: 18px; }
.sidebar-user { display: flex; align-items: center; gap: 11px; margin-top: auto; padding: 18px 10px 12px; border-top: 1px solid rgba(255,255,255,.12); }
.avatar { display: grid; flex: 0 0 38px; height: 38px; place-items: center; border-radius: 50%; background: var(--accent); color: var(--primary); font-weight: 900; }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user strong { overflow: hidden; max-width: 150px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user small { margin-top: 3px; color: rgba(255,255,255,.58); font-size: 10px; text-transform: uppercase; }
.logout-link { padding: 8px 11px; color: rgba(255,255,255,.62); font-size: 12px; text-decoration: none; }

.app-main { min-width: 0; }
.topbar { display: flex; align-items: center; min-height: 84px; padding: 14px clamp(22px, 4vw, 52px); border-bottom: 1px solid var(--border); background: rgba(255,255,255,.92); backdrop-filter: blur(14px); }
.topbar h1 { margin: 2px 0 0; font-size: 22px; letter-spacing: -.02em; }
.topbar-eyebrow { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.role-chip { margin-left: auto; padding: 7px 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); color: var(--secondary); font-size: 11px; font-weight: 800; }
.menu-button { display: none; margin-right: 12px; border: 0; background: transparent; color: var(--primary); font-size: 22px; cursor: pointer; }
.content { width: min(1540px, 100%); margin: 0 auto; padding: 34px clamp(22px, 4vw, 52px) 60px; }

.eyebrow { display: block; margin-bottom: 7px; color: var(--secondary); font-size: 10px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.page-heading, .lead-detail-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h2, .lead-detail-heading h2 { margin: 0; font-size: clamp(27px, 3vw, 38px); letter-spacing: -.045em; }
.page-heading p, .lead-detail-heading p { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.hero-card { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 30px; overflow: hidden; margin-bottom: 24px; padding: 31px 34px; border-radius: 20px; background: linear-gradient(130deg, var(--primary), #315f78); color: #fff; box-shadow: var(--shadow); }
.hero-card::after { content: ""; position: absolute; right: -80px; bottom: -150px; width: 300px; height: 300px; border: 55px solid rgba(242,165,65,.15); border-radius: 50%; }
.hero-card > * { position: relative; z-index: 1; }
.hero-card .eyebrow { color: #e8bd7a; }
.hero-card h2 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.hero-card p { margin: 9px 0 0; color: rgba(255,255,255,.72); font-size: 15px; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 10px 17px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 800; text-decoration: none; transition: .16s ease; white-space: nowrap; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-2); }
.button-accent { background: var(--accent); color: var(--primary); }
.button-accent:hover { background: #ffc066; }
.button-secondary { border-color: var(--border-strong); background: #fff; color: var(--primary); }
.button-secondary:hover { border-color: var(--secondary); background: var(--surface-soft); }
.button-danger-ghost { border-color: #dfb4b7; background: #fff; color: var(--danger); }
.button-small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
.button-block { width: 100%; }
.text-link, .back-link { color: var(--secondary); font-weight: 800; text-decoration: none; }
.text-link:hover, .back-link:hover { color: var(--primary); }
.back-link { display: inline-block; margin-bottom: 20px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--primary); font-size: 18px; text-decoration: none; }

.panel { margin-bottom: 24px; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-soft); }
.panel-flush { padding: 0; overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 21px; }
.panel-heading-padded { margin: 0; padding: 21px 24px; border-bottom: 1px solid var(--border); }
.panel-heading h2 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); }
.count-badge { display: inline-grid; min-width: 34px; height: 30px; padding: 0 10px; place-items: center; border-radius: 999px; background: var(--primary); color: #fff; font-size: 12px; font-weight: 900; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { position: relative; overflow: hidden; padding: 21px; border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: var(--shadow-soft); text-decoration: none; }
.metric-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--secondary); }
.metric-card.metric-primary::before { background: var(--primary); }
.metric-card.metric-success::before { background: var(--success); }
.metric-card.metric-warning::before { background: var(--accent); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card span { font-size: 12px; font-weight: 800; text-transform: uppercase; }
.metric-card strong { display: block; margin: 7px 0 3px; font-size: 34px; letter-spacing: -.05em; }
.metric-card small { font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 12px 15px; background: #f4f7f8; color: var(--muted); text-align: left; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 15px; border-top: 1px solid #e5ecef; vertical-align: middle; }
.data-table tbody tr:hover { background: #f8fbfc; }
.data-table small.table-subtext, .table-subtext { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.lead-title { display: flex; min-width: 190px; flex-direction: column; text-decoration: none; }
.lead-title small { color: var(--secondary); font-size: 10px; font-weight: 900; letter-spacing: .05em; }
.lead-title strong { margin-top: 3px; font-size: 14px; }
.lead-title span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.person-line, .muted { display: block; }
.muted { margin-top: 4px; color: var(--muted); font-size: 11px; }
.status, .direction, .role-badge, .state-dot, .read-only-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 850; white-space: nowrap; }
.status-nuevo { background: #e5edf1; color: var(--primary); }
.status-en_estudio { background: #e2ebf6; color: #315f8c; }
.status-contactado { background: #efe9f8; color: #68479a; }
.status-en_negociacion { background: #fff0d8; color: #8d570e; }
.status-ganado { background: #dff1e6; color: #246a44; }
.status-perdido { background: #f7e1e3; color: #8c3238; }
.status-archivado, .status-trash { background: #e8e9eb; color: #555f66; }
.direction { border-radius: 7px; background: #f2f6f8; color: var(--secondary); }
.direction-soltac_empresa { border-left: 3px solid var(--accent); }
.direction-empresa_soltac { border-left: 3px solid var(--secondary); }
.state-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.state-dot.on { background: #e4f1e9; color: #246a44; }
.state-dot.on::before { background: var(--success); }
.state-dot.off { background: #edf0f1; color: #68757c; }
.state-dot.off::before { background: #89979e; }
.role-badge { background: #e7eef2; color: var(--primary); }

.filter-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 17px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 14px; background: #fff; }
.filter-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filter-form label { min-width: 155px; }
.filter-form .search-field { min-width: 260px; }
.filter-form label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.view-tabs { display: flex; padding: 4px; border-radius: 9px; background: var(--canvas); }
.view-tabs a { padding: 8px 11px; border-radius: 7px; color: var(--muted); font-size: 12px; font-weight: 800; text-decoration: none; }
.view-tabs a.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(24,55,76,.10); }

label { color: var(--primary); font-size: 12px; font-weight: 800; }
input, select, textarea { width: 100%; margin-top: 6px; padding: 10px 11px; border: 1px solid var(--border-strong); border-radius: 8px; outline: none; background: #fff; color: var(--text); }
textarea { min-height: 95px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(74,118,141,.12); }
input:disabled, select:disabled, textarea:disabled { border-color: var(--border); background: #f3f6f7; color: #647b88; opacity: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
.stack-form { display: flex; flex-direction: column; gap: 15px; }
.form-actions { display: flex; justify-content: flex-end; }
.optional { color: var(--muted); font-weight: 500; }
.field-help { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; font-weight: 500; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--primary); }
.checkbox span, .checkbox strong, .checkbox small { display: block; }
.checkbox small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.preference-box { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.preference-box h3 { margin: 0 0 3px; }
.profile-panel { max-width: 800px; }

.alert { margin-bottom: 18px; padding: 13px 16px; border: 1px solid; border-radius: 10px; font-weight: 650; }
.alert-success { border-color: #a9d1ba; background: #e7f4ec; color: #246a44; }
.alert-error { border-color: #e4b7ba; background: #fae9ea; color: #8c3238; }
.alert-warning { border-color: #e4c78f; background: #fff7e7; color: #79531c; }
.empty-state { padding: 50px 25px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; color: var(--primary); font-size: 18px; }
.empty-state p { margin-bottom: 0; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 22px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,31,43,.72); backdrop-filter: blur(4px); }
.modal-card { position: relative; display: flex; width: min(760px, 100%); max-height: calc(100vh - 44px); flex-direction: column; overflow: hidden; border-radius: 18px; background: #fff; box-shadow: 0 30px 100px rgba(6,25,36,.42); animation: modal-enter .18s ease-out; }
.modal-card.modal-wide { width: min(1020px, 100%); }
.modal-card.modal-small { width: min(620px, 100%); }
.modal-card > form { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 25px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 25px; }
.modal-header p { margin: 7px 0 0; color: var(--muted); }
.modal-close { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--primary); cursor: pointer; font-size: 24px; }
.modal-body { min-height: 0; overflow-y: auto; padding: 23px 25px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 25px; border-top: 1px solid var(--border); background: #f7f9fa; }
.form-section { margin-bottom: 20px; padding: 17px; border: 1px solid var(--border); border-radius: 12px; }
.form-section:last-child { margin-bottom: 0; }
.form-section h3 { margin: 0 0 15px; font-size: 16px; }
.form-section-accent { border-left: 4px solid var(--accent); background: #fffaf1; }
.modal-open { overflow: hidden; }
@keyframes modal-enter { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.lead-detail-heading { align-items: flex-end; }
.lead-heading-line { display: flex; gap: 8px; margin-bottom: 12px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.detail-actions form { margin: 0; }
.locked-banner { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; padding: 15px 18px; border: 1px solid #d7c496; border-radius: 12px; background: #fff8e8; }
.locked-banner > span { font-size: 22px; }
.locked-banner strong, .locked-banner p { display: block; margin: 0; }
.locked-banner p { margin-top: 3px; color: #735b2a; font-size: 12px; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .65fr); gap: 22px; align-items: start; }
.detail-main { min-width: 0; }
.sticky-panel { position: sticky; top: 105px; }
.read-only-chip { background: #edf1f2; color: var(--muted); }
.assignment-summary { display: flex; flex-direction: column; gap: 15px; }
.assignment-summary div { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.assignment-summary div:last-child { border-bottom: 0; }
.assignment-summary span, .assignment-summary strong { display: block; }
.assignment-summary span, .summary-panel span { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.assignment-summary strong { margin-top: 5px; }
.assignment-form { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--border); }
.summary-panel { display: flex; flex-direction: column; gap: 16px; }
.summary-panel div { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.summary-panel div:last-child { padding: 0; border: 0; }
.summary-panel strong { display: block; margin-top: 5px; }

.timeline-panel { overflow: hidden; }
.timeline { position: relative; display: flex; flex-direction: column; gap: 14px; padding-left: 21px; }
.timeline::before { content: ""; position: absolute; top: 9px; bottom: 9px; left: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; }
.timeline-marker { position: absolute; top: 17px; left: -20px; z-index: 1; width: 12px; height: 12px; border: 3px solid #fff; border-radius: 50%; background: var(--secondary); box-shadow: 0 0 0 1px var(--border-strong); }
.timeline-card { padding: 15px 17px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.timeline-meta { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 11px; }
.timeline-meta strong, .timeline-meta span { display: block; }
.timeline-meta strong { color: var(--primary); font-size: 12px; }
.timeline-card p { margin: 12px 0; line-height: 1.55; white-space: normal; }
.attachment-card { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: #fff; text-decoration: none; }
.attachment-card > span { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 8px; background: var(--selection); font-size: 18px; }
.attachment-card strong, .attachment-card small { display: block; }
.attachment-card small { margin-top: 2px; color: var(--muted); }
.comment-form { margin-top: 22px; padding: 18px; border-radius: 12px; background: var(--primary); }
.comment-form label { color: #fff; }
.comment-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.file-button { display: inline-flex; min-height: 40px; align-items: center; padding: 9px 13px; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; color: #fff; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.auth-body { background: var(--primary); }
.auth-shell { display: grid; grid-template-columns: minmax(400px, .9fr) minmax(420px, .7fr); min-height: 100vh; }
.auth-brand-panel { position: relative; display: flex; align-items: center; overflow: hidden; padding: clamp(40px, 7vw, 100px); background: linear-gradient(145deg, #102d40, #244f69); color: #fff; }
.auth-brand-copy { position: relative; z-index: 2; max-width: 610px; }
.auth-brand-copy h1 { max-width: 570px; margin: 42px 0 18px; font-size: clamp(42px, 6vw, 78px); line-height: .98; letter-spacing: -.065em; }
.auth-brand-copy p { max-width: 530px; color: rgba(255,255,255,.68); font-size: 18px; line-height: 1.65; }
.auth-orbit { position: absolute; right: -20%; bottom: -35%; width: 600px; height: 600px; border: 1px solid rgba(255,255,255,.1); border-radius: 50%; }
.auth-orbit span { position: absolute; border: 1px solid rgba(242,165,65,.22); border-radius: 50%; }
.auth-orbit span:nth-child(1) { inset: 80px; }
.auth-orbit span:nth-child(2) { inset: 160px; }
.auth-orbit span:nth-child(3) { top: 90px; left: 180px; width: 42px; height: 42px; border: 0; background: var(--accent); box-shadow: 0 0 50px rgba(242,165,65,.5); }
.auth-form-panel { display: grid; place-items: center; padding: 35px; background: #fff; }
.auth-card { width: min(430px, 100%); }
.auth-card h2 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.auth-intro { margin: 9px 0 25px; color: var(--muted); line-height: 1.55; }
.form-hint { margin-top: 18px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.form-hint code { color: var(--primary); }

@media (max-width: 1150px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .view-tabs { align-self: flex-start; }
}

@media (max-width: 920px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 258px; transition: transform .2s ease; }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open::after { content: ""; position: fixed; inset: 0; z-index: 15; background: rgba(8,29,41,.55); }
    .menu-button { display: block; }
    .detail-layout { grid-template-columns: 1fr; }
    .sticky-panel { position: static; }
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand-panel { min-height: 340px; padding: 45px; }
    .auth-brand-copy h1 { margin-top: 25px; font-size: 48px; }
}

@media (max-width: 650px) {
    .content { padding: 22px 14px 45px; }
    .topbar { padding: 12px 14px; }
    .role-chip { display: none; }
    .page-heading, .lead-detail-heading, .hero-card { align-items: stretch; flex-direction: column; }
    .page-heading .button, .hero-card .button { width: 100%; }
    .metric-grid, .form-grid { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: auto; }
    .filter-form, .filter-form label, .filter-form .search-field, .filter-form .button { width: 100%; }
    .view-tabs { width: 100%; overflow-x: auto; }
    .view-tabs a { flex: 1; text-align: center; }
    .modal { padding: 6px; }
    .modal-card { max-height: calc(100vh - 12px); border-radius: 12px; }
    .modal-header, .modal-body, .modal-footer { padding-right: 16px; padding-left: 16px; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer .button { flex: 1; }
    .auth-brand-panel { display: none; }
    .auth-form-panel { min-height: 100vh; padding: 24px; }
    .comment-actions { align-items: stretch; flex-direction: column; }
    .comment-actions > * { width: 100%; }
    .detail-actions { justify-content: stretch; }
    .detail-actions form, .detail-actions .button { width: 100%; }
}
