@font-face { font-family: Inter; src: url(fonts/Inter_400Regular.ttf); font-weight: 400; }
[hidden] { display: none !important; }
@font-face { font-family: Inter; src: url(fonts/Inter_500Medium.ttf); font-weight: 500; }
@font-face { font-family: Inter; src: url(fonts/Inter_600SemiBold.ttf); font-weight: 600; }
@font-face { font-family: Inter; src: url(fonts/Inter_700Bold.ttf); font-weight: 700; }
@font-face { font-family: Bricolage; src: url(fonts/BricolageGrotesque_800ExtraBold.ttf); font-weight: 800; }

:root {
  --purple: #7B3EFF;
  --purple-ink: #5A22D6;
  --purple-soft: #F3EEFF;
  --ink: #1B1B1B;
  --muted: #6B6878;
  --line: #E6E3EE;
  --bg: #F7F6FB;
  --card: #FFFFFF;
  --ok: #138A5B;
  --warn: #B26A00;
  --bad: #C2304B;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--purple-ink); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h1 { font-family: Bricolage, Inter, sans-serif; font-weight: 800; font-size: 30px; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
.brand img { height: 28px; }
.brand span { padding-left: 10px; border-left: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a.on, .nav a:hover { background: var(--purple-soft); color: var(--purple-ink); }
.me { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.me-name { color: var(--ink); text-decoration: none; font-weight: 500; }
.me form { margin: 0; }

main.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
main.guest { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfc9dd; }
.btn-primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-ink); border-color: var(--purple-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #fff; border-color: var(--line); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
button.link:hover { color: var(--ink); text-decoration: underline; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font: inherit; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(123, 62, 255, .25); border-color: var(--purple); }
textarea { resize: vertical; min-height: 64px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; margin: 0; }
.check input { width: 16px; height: 16px; accent-color: var(--purple); }
.field { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.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)); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; }
.flash-ok { background: #E8F7F0; color: var(--ok); }
.flash-error { background: #FDECEF; color: var(--bad); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.row-link:hover td { background: #FBFAFE; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table a.strong { color: var(--ink); font-weight: 600; text-decoration: none; }
.table a.strong:hover { color: var(--purple-ink); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--muted); }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.st-borrador { background: #EFEDF4; color: #5B5770; }
.st-enviada { background: #FFF4E0; color: var(--warn); }
.st-aprobada { background: #E8F7F0; color: var(--ok); }
.st-rechazada { background: #FDECEF; color: var(--bad); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--purple-soft); color: var(--purple-ink); font-size: 12px; font-weight: 600; }
.tag-gray { background: #EFEDF4; color: #5B5770; }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { max-width: 320px; }
.filters select { max-width: 180px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* Auth */
.auth { width: 100%; max-width: 400px; }
.auth .logo { display: block; height: 44px; margin: 0 auto 26px; }
.auth .card { padding: 28px; }
.auth h1 { font-size: 24px; text-align: center; }
.auth p { text-align: center; }

/* Quote editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.editor-side { position: sticky; top: 78px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 12px; background: #fff; margin-bottom: 12px; }
.item.is-sf { border-left: 4px solid var(--purple); }
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.item-head .tag { flex: none; }
.item-head input.title { font-weight: 700; border-color: transparent; padding-left: 4px; font-size: 16px; }
.item-head input.title:hover { border-color: var(--line); }
.item-tools { display: flex; gap: 2px; margin-left: auto; }
.icon-btn { width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.del:hover { color: var(--bad); background: #FDECEF; }
.item-row { display: grid; grid-template-columns: 1.2fr 90px 1fr 130px 130px; gap: 10px; align-items: end; }
.item-row .line-total { text-align: right; font-weight: 700; padding-bottom: 9px; font-variant-numeric: tabular-nums; }
.item textarea { min-height: 54px; }
.benefits { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.benefit { display: grid; grid-template-columns: 22px 200px 1fr 30px; gap: 8px; align-items: center; margin-bottom: 6px; }
.benefit .n { color: var(--purple); font-weight: 700; font-size: 13px; }
.benefit input { padding: 7px 9px; font-size: 14px; }
.add-bar { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px; border: 1px dashed #cfc6e8; border-radius: 12px; background: #FBFAFE; }
.add-bar select { flex: 1 1 220px; }

.totals { font-variant-numeric: tabular-nums; }
.totals .line { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.totals .line.big { font-size: 22px; font-weight: 800; color: var(--purple-ink); padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); font-family: Bricolage, Inter, sans-serif; }
.totals .group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-top: 12px; }
.totals .contract { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--purple-soft); color: var(--purple-ink); font-weight: 600; display: flex; justify-content: space-between; }

.library { display: none; margin-top: 8px; padding: 10px; border-radius: 10px; background: var(--bg); }
.library.open { display: block; }
.library label.check { padding: 4px 0; }

@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .line-total { grid-column: span 2; text-align: left; padding: 0; }
  .benefit { grid-template-columns: 22px 1fr 30px; }
  .benefit input.bd { grid-column: 2 / 3; }
  .g3, .g4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .brand span { display: none; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  main.wrap { padding: 20px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .table .hide-sm { display: none; }
  .item-head { flex-wrap: wrap; }
  .item-head input.title { order: 3; flex-basis: 100%; padding-left: 0; }
  h1 { font-size: 24px; }
}

/* ===== Ciclo comercial ===== */
.flash { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.nav { overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-family: Bricolage, Inter, sans-serif; font-weight: 800; font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.kpi.bad .v { color: var(--bad); }
.kpi.good .v { color: var(--ok); }
.cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols .card + .card { margin-top: 0; }
.task { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: start; }
.task:last-child { border-bottom: 0; }
.task .bar { align-self: stretch; border-radius: 4px; background: var(--line); }
.task.late .bar { background: var(--bad); }
.task.today .bar { background: var(--purple); }
.task .t { font-weight: 600; }
.task .t a { color: var(--ink); text-decoration: none; }
.task .t a:hover { color: var(--purple-ink); }
.task .m { font-size: 12.5px; color: var(--muted); }
.task .when { font-size: 12px; font-weight: 600; white-space: nowrap; text-align: right; }
.task.late .when { color: var(--bad); }
.task.today .when { color: var(--purple-ink); }
.amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.mini-empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

.stage { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.stage-prospecto { background: #EFEDF4; color: #5B5770; }
.stage-reunion { background: #E7F0FF; color: #2456B8; }
.stage-cotizacion { background: #FFF4E0; color: var(--warn); }
.stage-cliente { background: #E8F7F0; color: var(--ok); }
.stage-perdido { background: #F6F1F2; color: #9A6B73; }
.bs { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.bs-por_facturar { background: #EFEDF4; color: #5B5770; }
.bs-atrasado { background: #FFF4E0; color: var(--warn); }
.bs-facturado { background: #E7F0FF; color: #2456B8; }
.bs-vencido { background: #FDECEF; color: var(--bad); }
.bs-pagado { background: #E8F7F0; color: var(--ok); }

.pipeline { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.pipeline a { display: flex; gap: 6px; align-items: center; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--ink); font-size: 13px; font-weight: 500; }
.pipeline a.on { border-color: var(--purple); background: var(--purple-soft); color: var(--purple-ink); }
.pipeline a b { font-variant-numeric: tabular-nums; }

.client-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.client-side { display: grid; gap: 16px; }
.client-side .card + .card { margin-top: 0; }
.timeline { display: grid; }
.tl { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tl:last-child { border-bottom: 0; }
.tl .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--line); }
.tl.pend .dot { background: var(--purple); box-shadow: 0 0 0 3px var(--purple-soft); }
.tl.late .dot { background: var(--bad); box-shadow: 0 0 0 3px #FDECEF; }
.tl.done { color: var(--muted); }
.tl .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.tl .head b { color: var(--ink); }
.tl.done .head b { color: var(--muted); font-weight: 600; }
.tl .res { font-size: 13px; margin-top: 2px; }
.tl .row-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

details.inline { margin-top: 8px; }
details.inline > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline[open] > summary { margin-bottom: 10px; }
.subform { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 10px; }
.subform .grid { gap: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg label { flex: 1; margin: 0; text-align: center; padding: 8px 6px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--purple-soft); color: var(--purple-ink); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--purple); outline-offset: -2px; }
.plan-preview { font-size: 13px; color: var(--purple-ink); background: var(--purple-soft); padding: 9px 11px; border-radius: 8px; font-weight: 500; }
.gcal-state { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.gcal-state .ok { color: var(--ok); font-weight: 700; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.steps code, .copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }

@media (max-width: 1060px) {
  .cols { grid-template-columns: 1fr; }
  .client-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .kpis { grid-template-columns: 1fr 1fr; }
}

.bill-actions { justify-content: flex-end; flex-wrap: nowrap; text-align: left; }
.bill-actions:has(details[open]) { flex-wrap: wrap; justify-content: flex-start; }
.bill-actions details[open] { flex-basis: 100%; }
.subform label { display: grid; gap: 4px; margin: 0; }
.subform .grid > label { min-width: 0; }

.dot-brand { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.bchip { display: inline-block; margin: 0 4px 3px 0; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; color: var(--bc); background: color-mix(in srgb, var(--bc) 10%, #fff); border: 1px solid color-mix(in srgb, var(--bc) 22%, #fff); white-space: nowrap; }
.filters select { max-width: 220px; }
.table .code, table.list .code { white-space: nowrap; }

.thumb { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; background: var(--bg); display: grid; place-items: center; max-width: 100%; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.intro-item { display: grid; gap: 6px; margin: 0; font-weight: 500; color: var(--ink); }
.intro-item img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.item.is-section { background: var(--bg); border-style: dashed; }
.item.is-section input.title { font-size: 15px; }
.item.is-optional { border-style: dashed; background: #FCFBFF; }
.item.is-optional .line-total b, .item.is-optional [data-out=total] { opacity: .6; }

/* Selector de clientes en la cotización */
.cwrap { position: relative; }
.cmenu { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(30, 20, 60, .14); max-height: 320px; overflow-y: auto; padding: 4px; }
.cm-i { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 1px; }
.cm-i b { font-weight: 600; font-size: 14px; }
.cm-i span { color: var(--muted); font-size: 12.5px; }
.cm-i:hover, .cm-i.on { background: var(--purple-soft); }
.cp-ok { color: var(--ok); font-weight: 600; }
.cp-new { color: var(--purple-ink); font-weight: 600; }

/* Mes en filtros */
input[type=month] { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }

/* ===== App en el teléfono (PWA) ===== */
.tabbar { display: none; }
@media (max-width: 720px) {
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, .96); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 4px 0; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; border-radius: 10px; -webkit-tap-highlight-color: transparent; }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.on { color: var(--purple-ink); }
  .tabbar a.on svg { stroke-width: 2.2; }
  body.is-auth main.wrap { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
}
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; overscroll-behavior-y: none; }
  input, textarea, select, [contenteditable], .table, p, td { -webkit-user-select: text; user-select: text; }
}
@media (max-width: 720px) {
  .nav a.nm { display: none; }
  .nav { justify-content: flex-start; }
}
.client-grid > * { min-width: 0; }
.pay-tabs a { flex: 1; text-align: center; padding: 9px 6px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; border-right: 1px solid var(--line); }
.pay-tabs a:last-child { border-right: 0; }
.pay-tabs a.on { background: var(--purple-soft); color: var(--purple-ink); }

/* Acceso seguro */
.btn-google { background: #fff; border: 1px solid var(--line); color: var(--ink); font-weight: 600; display: inline-flex; justify-content: center; align-items: center; gap: 10px; }
.btn-google:hover { background: #F8F8FB; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.otp { font-size: 26px !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { width: 200px; height: 200px; margin: 6px auto 4px; background: #fff; padding: 6px; border-radius: 12px; border: 1px solid var(--line); }
.qr svg { width: 100%; height: 100%; display: block; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes code, code.sec { font: 600 15px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; letter-spacing: .04em; }
code.sec { display: inline-block; padding: 4px 8px; font-size: 13px; }
.sess { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sess:last-child { border-bottom: 0; }
@media print { body * { visibility: hidden; } .codes, .codes * { visibility: visible; } .codes { position: absolute; top: 0; left: 0; } }
