:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #EEF1F5;
  --ink: #141A2E;
  --ink-2: #3D4559;
  --muted: #6A7286;
  --line: #DCE1E8;
  --brand: #0B5D75;
  --brand-ink: #FFFFFF;
  --brand-soft: #E3F0F4;
  --accent: #D2962A;
  --danger: #C2412D;
  --danger-soft: #FBEAE6;
  --ok: #1F7A4D;
  --ok-soft: #E4F3EA;
  --warn-soft: #FFF5E0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 26, 46, .06), 0 4px 16px rgba(20, 26, 46, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1426; --surface: #161E35; --surface-2: #1D2742; --ink: #E9EDF5; --ink-2: #C3CADA;
    --muted: #8D97AE; --line: #2A3452; --brand: #5BBFD9; --brand-ink: #0E1426; --brand-soft: #16354A;
    --danger: #F08A76; --danger-soft: #3A1F1E; --ok: #6FD3A0; --ok-soft: #173326; --warn-soft: #3A2E15;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1426; --surface: #161E35; --surface-2: #1D2742; --ink: #E9EDF5; --ink-2: #C3CADA;
  --muted: #8D97AE; --line: #2A3452; --brand: #5BBFD9; --brand-ink: #0E1426; --brand-soft: #16354A;
  --danger: #F08A76; --danger-soft: #3A1F1E; --ok: #6FD3A0; --ok-soft: #173326; --warn-soft: #3A2E15;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Hanken Grotesk', system-ui, sans-serif; font-size: 15px; line-height: 1.5;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: 'Bricolage Grotesque', system-ui, sans-serif; letter-spacing: -.01em; line-height: 1.15; margin: 0; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 800; }
h3 { font-size: 15px; font-weight: 700; font-family: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 4px 0 0; font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* Botones y campos */
.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (hover: hover) {
  .btn:hover { border-color: var(--brand); }
  .btn.primary:hover { filter: brightness(1.08); }
}
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
label { font-weight: 600; font-size: 14px; display: block; margin: 12px 0 6px; }
textarea { min-height: 80px; resize: vertical; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: 18px; }
.logo { width: 26px; height: 26px; background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M10 8V32M20 8V36M30 8V28' stroke='%235BBFD9' stroke-width='2.6' stroke-linecap='round' fill='none'/%3E%3Ccircle cx='10' cy='18' r='3' fill='%235BBFD9'/%3E%3Ccircle cx='10' cy='26' r='3' fill='%23D2962A'/%3E%3Ccircle cx='20' cy='16' r='3' fill='%235BBFD9'/%3E%3Ccircle cx='20' cy='30' r='3' fill='%235BBFD9'/%3E%3Ccircle cx='30' cy='20' r='3' fill='%23D2962A'/%3E%3Cpath d='M4 8H36' stroke='%230B5D75' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E"); }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; }
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 600; }
.nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
@media (hover: hover) { .nav a:hover:not([aria-current="page"]) { background: var(--surface-2); } }
.logout { margin-top: auto; align-self: flex-start; }
.main { min-width: 0; }
.banner { background: var(--warn-soft); border-bottom: 1px solid var(--line); padding: 10px 28px; font-size: 14px; }
.view { padding: 28px; max-width: 1280px; outline: none; }
.view-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.view-head p { margin: 4px 0 0; }
.view-head select { width: auto; min-width: 240px; max-width: 100%; }

/* Tarjetas y KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi small { color: var(--muted); font-weight: 600; font-size: 13px; }
.kpi b { display: block; font-family: 'Bricolage Grotesque', sans-serif; font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--muted); }
.panels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.count { font-family: 'Hanken Grotesk', sans-serif; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); padding: 10px 0; display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.list li:first-child { border-top: 0; }
.list .who { font-weight: 600; background: none; border: 0; padding: 0; color: var(--ink); cursor: pointer; text-align: left; font: inherit; font-weight: 600; }
.list .who:hover { color: var(--brand); }
.list .sub { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 2px 9px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.brand { background: var(--brand-soft); color: var(--brand); }

/* Embudo */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; overscroll-behavior-x: contain; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 320px; display: flex; flex-direction: column; gap: 8px; transition: background-color .15s ease; }
.col.drop { background: var(--brand-soft); }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 6px 6px; gap: 8px; }
.col-head h3 { font-size: 14px; }
.col-head small { color: var(--muted); font-weight: 600; white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: grab; box-shadow: 0 1px 2px rgba(20,26,46,.05); touch-action: manipulation; }
.card.dragging { opacity: .5; }
.card b { display: block; font-weight: 700; overflow-wrap: anywhere; }
.card .meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted); align-items: center; }
.card .move { margin-top: 8px; font-size: 13px; padding: 5px 8px; }

/* Tablas */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tbody tr { cursor: pointer; }
@media (hover: hover) { tbody tr:hover { background: var(--surface-2); } }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 340px; }
.toolbar select { width: auto; }

/* Ficha */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(14, 20, 38, .35); z-index: 20; animation: fade .2s ease; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg); z-index: 21; overflow-y: auto; overscroll-behavior: contain; box-shadow: -8px 0 32px rgba(0,0,0,.18); animation: slide .25s cubic-bezier(.32,.72,0,1); }
@keyframes slide { from { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }
.drawer-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 18px 20px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; z-index: 1; }
.drawer-head h2 { font-size: 20px; overflow-wrap: anywhere; }
.drawer-body { padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 14px; }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.section h3 { margin: 0 0 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.services { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.services label { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; margin: 0; font-size: 14px; cursor: pointer; }
.services input { width: auto; margin-top: 3px; accent-color: var(--brand); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { border-top: 1px solid var(--line); padding: 10px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note small { display: block; color: var(--muted); margin-top: 4px; }
.task { display: flex; gap: 10px; align-items: flex-start; border-top: 1px solid var(--line); padding: 10px 0; }
.task input { width: auto; margin-top: 4px; accent-color: var(--brand); }
.task.done span { text-decoration: line-through; color: var(--muted); }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-size: 22px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }

/* Cotizador */
.quote { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.catalog { display: flex; flex-direction: column; gap: 8px; }
.catalog h2 { margin: 12px 0 2px; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; transition: border-color .15s ease, background-color .15s ease; }
.item input { width: auto; accent-color: var(--brand); }
.item.on { border-color: var(--brand); background: var(--brand-soft); }
.item .price { text-align: right; font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item .price small { display: block; color: var(--muted); }
.item .desc { font-size: 13px; color: var(--muted); }
.summary { position: sticky; top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.summary .tot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.summary .tot div { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.summary .tot b { display: block; font-family: 'Bricolage Grotesque', sans-serif; font-size: 22px; font-variant-numeric: tabular-nums; }
.summary .lines { font-size: 14px; color: var(--ink-2); margin: 0; padding-left: 18px; }
.hint { font-size: 13px; color: var(--muted); }

/* Login: elegir persona */
.who-pick { border: 0; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.who-pick legend { font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.who-pick .who { margin: 0; position: relative; }
.who-pick input { position: absolute; opacity: 0; pointer-events: none; }
.who-pick span { display: block; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-weight: 600; cursor: pointer; transition: border-color .15s ease, background-color .15s ease; }
.who-pick input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.who-pick input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.panel-hint { margin: -4px 0 8px; }

/* Ficha: acciones grandes, negocios y mensajes */
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.quick-btn { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-decoration: none; color: var(--ink); font: inherit; cursor: pointer; text-align: left; min-width: 0; transition: border-color .15s ease, transform .1s ease; }
.quick-btn:active { transform: scale(.97); }
.quick-btn b { font-weight: 700; }
.quick-btn small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.quick-btn.wa { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.quick-btn.wa small { color: inherit; opacity: .85; }
.quick-btn.off { opacity: .6; cursor: default; }
@media (hover: hover) { .quick-btn:hover:not(.off) { border-color: var(--brand); } }
.deal { border-top: 1px solid var(--line); padding: 12px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.deal:first-of-type { border-top: 0; padding-top: 0; }
.btn.win { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
details.section summary { cursor: pointer; list-style: none; }
details.section summary::-webkit-details-marker { display: none; }
details.section summary::before { content: '▸'; display: inline-block; margin-right: 6px; transition: transform .2s ease; color: var(--muted); }
details.section[open] summary::before { transform: rotate(90deg); }
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; overscroll-behavior: contain; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: var(--brand-soft); }
.bubble small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 40; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Responsive */
@media (max-width: 1100px) {
  .panels { grid-template-columns: 1fr 1fr; }
  .quote { grid-template-columns: 1fr; }
  .summary { position: static; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 10; gap: 0; }
  .sidebar .brand, .logout { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .main { padding-bottom: 76px; }
  .view { padding: 20px 16px; }
  .banner { padding: 10px 16px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .panels { grid-template-columns: 1fr; }
  .services, .row2 { grid-template-columns: 1fr; }
  .quick { grid-template-columns: 1fr 1fr; }
  .view-head .btn { width: 100%; justify-content: center; }
  h1 { font-size: 24px; }
}
