:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --ink: #161b2e;
  --muted: #6b7287;
  --line: #e4e7ef;
  --side: #121a33;
  --side-ink: #c9cee0;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --good: #0f9d6b;
  --good-soft: #e3f6ee;
  --warn: #c77700;
  --warn-soft: #fff3dc;
  --bad: #d23c3c;
  --bad-soft: #fdeaea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 25, 45, .06), 0 4px 16px rgba(20, 25, 45, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1em; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex-shrink: 0; }
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; margin: 0 auto 12px; }
.brand-name { color: #fff; font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.brand-sub { font-size: 12px; color: #8b92ab; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: var(--side-ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav .ico { width: 20px; display: inline-grid; place-items: center; }
.nav .ico svg { width: 18px; height: 18px; }
.nav-bottom { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 10px; }
.main { flex: 1; padding: 28px 32px 60px; min-width: 0; max-width: 1280px; }
.menu-btn { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ---------- Componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #3a4158; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #d5d9e4; border-radius: 9px; padding: 10px 12px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
textarea { min-height: 80px; resize: vertical; }
.btn { font: inherit; font-weight: 600; border: 1px solid #d5d9e4; background: #fff; color: var(--ink); padding: 9px 16px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f4f5f9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btn:disabled { opacity: .6; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.seg { display: inline-flex; background: #eceef4; border-radius: 10px; padding: 3px; }
.seg button { font: inherit; font-weight: 600; font-size: 14px; border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f5; color: #444b63; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }
.hint { padding: 10px 14px; border-radius: 9px; background: var(--accent-soft); color: #3730a3; font-size: 14px; }
.hint.good { background: var(--good-soft); color: #08704c; }
.hint.warn { background: var(--warn-soft); color: #8a5300; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #eef0f5; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* KPIs */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Barras */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 120px; gap: 12px; align-items: center; font-size: 14px; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.bar-track { height: 12px; background: #eef0f6; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s ease; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-row .v small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 170px; padding-top: 10px; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 4px; position: relative; }
.chart .col .b { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.chart .col:hover .b { opacity: 1; }
.chart .col .tip { display: none; position: absolute; bottom: 100%; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 2; margin-bottom: 4px; }
.chart .col:hover .tip { display: block; }
.chart-x { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Metas */
.goal-hero { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: center; }
.ring { width: 200px; height: 200px; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .pct { font-size: 38px; font-weight: 750; letter-spacing: -.03em; }
.goal-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.goal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.goal-card .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.goal-card .amount { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress { height: 14px; background: #eef0f6; border-radius: 99px; overflow: hidden; margin: 10px 0 8px; }
.progress > div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #6366f1, #4f46e5); transition: width .7s ease; }
.progress.done > div { background: linear-gradient(90deg, #12b886, #0f9d6b); }
.stat-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.stat-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
.goal-input { display: flex; gap: 8px; margin-top: 12px; }
.goal-input input { padding: 7px 10px; }

/* Pipeline */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
/* Las columnas se reparten el ancho para que se vean todas las etapas sin deslizar */
.lane { background: #eceef4; border-radius: var(--radius); flex: 1 1 0; min-width: 150px; display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.lane-head { padding: 12px 14px 8px; display: flex; justify-content: space-between; align-items: center; font-weight: 650; }
.lane-head .sum { font-size: 12px; color: var(--muted); font-weight: 500; }
.lane-body { padding: 4px 8px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; flex: 1; }
.lane.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.lane[data-kind="won"] .lane-head { color: var(--good); }
.lane[data-kind="lost"] .lane-head { color: var(--bad); }
.lead { background: #fff; border-radius: 10px; padding: 10px 12px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); cursor: grab; border: 1px solid transparent; }
.lead:hover { border-color: #c7cbf7; }
.lead.dragging { opacity: .4; }
.lead .n { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.lead .m span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-head { gap: 6px; }
.lane-head > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead .m { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; justify-content: space-between; gap: 6px; }
.lead select { margin-top: 8px; padding: 4px 6px; font-size: 12px; display: none; }

/* Modal y aviso */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.x { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 60; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; padding: 32px; border-radius: 16px; width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }

/* Base de datos */
.drop { border: 2px dashed #c9cde0; border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; transition: background .15s, border-color .15s; }
.drop:hover, .drop.over { background: var(--accent-soft); border-color: var(--accent); }
code.formula { display: block; background: #f3f4f8; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; word-break: break-all; margin: 6px 0; }
.list-edit { display: flex; flex-direction: column; gap: 8px; }
.list-edit .item { display: flex; gap: 8px; align-items: center; }
.list-edit .item input { padding: 7px 10px; }

/* Sugerencias de clientes */
.ac { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); z-index: 10; margin-top: 4px; overflow: hidden; }
.ac-list div { padding: 9px 12px; cursor: pointer; font-size: 14px; font-weight: 400; }
.ac-list div:hover { background: var(--accent-soft); }

/* ---------- Celular ---------- */
@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
  .goal-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .menu-btn { display: block; position: fixed; top: 12px; left: 12px; z-index: 41; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 20px; cursor: pointer; box-shadow: var(--shadow); }
  .main { padding: 70px 16px 40px; }
  .form-grid, .g2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 90px 1fr 92px; gap: 8px; }
  .lead select { display: block; }
  .lane { flex: 0 0 82vw; }
  h1 { font-size: 21px; }
}
