@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Montserrat:wght@600;700;800&display=swap');

/* ===== Tokens ===== */
:root {
  --brand: #1A6FFF;
  --brand-600: #155fe0;
  --brand-soft: rgba(26, 111, 255, 0.12);
  --on-brand: #ffffff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e6e9f0;
  --text: #0e1525;
  --muted: #667085;
  --ok: #16a34a; --ok-soft: rgba(22,163,74,.12);
  --warn: #d97706; --warn-soft: rgba(217,119,6,.12);
  --danger: #dc2626; --danger-soft: rgba(220,38,38,.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --sidebar: 248px;
  --ff: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --ff-head: 'Montserrat', var(--ff);
}
html[data-theme="dark"] {
  --bg: #0b0f1a;
  --surface: #121826;
  --surface-2: #0f1521;
  --line: #1e2a3d;
  --text: #e8edf6;
  --muted: #93a0b5;
  --brand-soft: rgba(26,111,255,.18);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ff);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--ff-head); margin: 0; letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
.ico { vertical-align: -2px; }
.logo-vertex { color: var(--brand); }

/* ===== Layout app ===== */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand b { font-family: var(--ff-head); font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; letter-spacing: .02em; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-link .ico { flex: none; }
.sidebar .spacer { flex: 1; }

/* topbar + content */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; }
.topbar .grow { flex: 1; }
.content { padding: 26px; max-width: 1320px; width: 100%; }

/* ===== Botones ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  cursor: pointer; font-family: var(--ff); transition: .12s; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 8px; }

/* ===== Inputs ===== */
.field { display: flex; flex-direction: column; gap: 5px; }
label.lbl { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font-family: var(--ff); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 76px; }
select.tenant-select { max-width: 230px; }

/* ===== Cards / grid ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .hd { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .hd h3 { font-size: 15px; }
.card .bd { padding: 18px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* KPI */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .val { font-family: var(--ff-head); font-weight: 800; font-size: 28px; margin-top: 8px; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ===== Tabla ===== */
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface-2); }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* fuentes lead */
.src { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; text-transform: capitalize; }
.src-portalinmobiliario { background: #e6efff; color: #0a4bd1; }
.src-toctoc { background: #e0f7f4; color: #0c8074; }
.src-referido { background: #efe6ff; color: #6b2fc7; }
.src-mercadolibre { background: #fff3cd; color: #8a6d00; }
.src-yapo { background: #ffe3d1; color: #b4470f; }
.src-web { background: var(--brand-soft); color: var(--brand); }
.src-instagram { background: #fde2f3; color: #b3247e; }
.src-facebook { background: #e0eaff; color: #1d4ed8; }
.src-whatsapp { background: #d8f5e0; color: #128c4a; }
.src-manual { background: var(--surface-2); color: var(--muted); }

/* ===== Kanban ===== */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kanban .col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 120px; }
.kanban .col > .hd { padding: 12px 14px; font-weight: 700; font-size: 13px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; }
.kanban .col .list { padding: 0 10px 12px; display: flex; flex-direction: column; gap: 9px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; cursor: pointer; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.kcard:hover { border-color: var(--brand); }
.kcard .t { font-weight: 600; font-size: 13.5px; }
.kcard .m { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kcard .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

/* avatar */
.av { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }

/* ===== Modal ===== */
.modal-back { position: fixed; inset: 0; background: rgba(10,15,26,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 18px; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 540px; box-shadow: var(--shadow); max-height: 92vh; overflow: auto; }
.modal .hd { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .hd h3 { flex: 1; font-size: 16px; }
.modal .bd { padding: 20px; display: grid; gap: 14px; }
.modal .ft { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Toast ===== */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow); min-width: 240px; animation: slidein .18s ease; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Misc ===== */
.muted { color: var(--muted); }
.empty { text-align: center; padding: 48px 18px; color: var(--muted); }
.empty .ico { opacity: .5; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 0 0 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.thumb { width: 64px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.hide { display: none !important; }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, var(--brand-soft), transparent), var(--bg); padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); width: 100%; max-width: 390px; padding: 32px 30px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card h2 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; margin-top: 10px; }
.login-demo { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; font-size: 12px; color: var(--muted); }
.login-demo code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }

/* ===== Responsive ===== */
.menu-btn { display: none; }
@media (max-width: 960px) {
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3 { grid-template-columns: 1fr; }
  .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .modal .bd { grid-template-columns: 1fr !important; }
  .modal .bd .field[style*="span 2"] { grid-column: auto !important; }
  .grid[style*="repeat(5"], .grid[style*="repeat(6"] { grid-template-columns: repeat(2, 1fr) !important; }
  .content { max-width: 100%; }
  #gsearch { display: none; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; width: 260px; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 18px; }
  .topbar { padding: 12px 16px; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
}
