:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --glass: rgba(255, 255, 255, 0.88);
  --ink: #1b2733;
  --muted: #5f6d7b;
  --line: #e3e8ee;
  --line-strong: #cfd7e0;
  --accent: #ff6a3d;
  --accent-ink: #ffffff;
  --accent-soft: #fff0ea;
  --danger: #d83a3a;
  --ok: #1f9d6b;
  --happy: #2fc58a;
  --neutral: #b7c0c9;
  --sad: #5fa0e6;
  --angry: #ef4f4f;
  --shadow: 0 8px 28px rgba(20, 40, 70, 0.14);
  --radius: 12px;
  --nav-w: 208px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161d;
    --surface: #18202a;
    --surface-2: #1d2631;
    --glass: rgba(24, 32, 42, 0.9);
    --ink: #e6edf4;
    --muted: #97a6b5;
    --line: #2a3542;
    --line-strong: #364353;
    --accent-soft: #3a2219;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #11161d;
  --surface: #18202a;
  --surface-2: #1d2631;
  --glass: rgba(24, 32, 42, 0.9);
  --ink: #e6edf4;
  --muted: #97a6b5;
  --line: #2a3542;
  --line-strong: #364353;
  --accent-soft: #3a2219;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Botones y controles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon {
  border: 0;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
}
.icon:hover { background: var(--line); }
input[type="text"], input[type="email"], input[type="search"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input:not([type]), select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}
label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { font-weight: 400; color: var(--ink); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); font-weight: 500; }
.check input { width: auto; }

.card {
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.chips { display: inline-flex; gap: 2px; background: var(--line); padding: 2px; border-radius: 999px; }
.chips button { border: 0; background: transparent; padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.chips button.on { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 700; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  margin-left: auto;
}

/* Estructura */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; height: 100vh; height: 100dvh; }
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  color: var(--muted);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--ink); }
.nav .ico { width: 22px; text-align: center; }
.nav .brand { color: var(--ink); font-size: 18px; font-weight: 800; margin-bottom: 12px; letter-spacing: -0.01em; }
.nav .brand .logo { font-size: 22px; }
.nav-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.nav-foot b { display: block; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.top h1 { font-size: 18px; margin: 0; white-space: nowrap; }
#q { max-width: 340px; margin-left: auto; border-radius: 999px; background: var(--surface-2); }
.view { flex: 1; min-height: 0; position: relative; }
.view.scroll { overflow: auto; padding: 16px; }

/* Parque */
.park-view { overflow: hidden; background: #bfe3f7; }
#park { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.park-tools { position: absolute; top: 12px; left: 12px; right: 330px; display: flex; gap: 10px; align-items: flex-start; pointer-events: none; }
.park-tools > * { pointer-events: auto; }
.park-tools .chips { background: var(--glass); box-shadow: var(--shadow); border: 1px solid var(--line); }
.zoom { display: flex; gap: 4px; }
.zoom button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  font-size: 16px;
  font-weight: 700;
}
.feed {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 300px;
  max-height: calc(100% - 120px);
  display: flex;
  flex-direction: column;
}
.feed h2 {
  margin: 0;
  padding: 9px 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.feed.collapsed ol { display: none; }
.feed ol { list-style: none; margin: 0; padding: 0 6px 6px; overflow-y: auto; }
.feed li { display: flex; gap: 8px; padding: 6px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.feed li:hover { background: var(--line); }
.feed li time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.feed li.new { animation: pop 0.35s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.funnel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 4px;
  padding: 5px;
  overflow-x: auto;
}
.funnel button {
  flex: 1 0 104px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 9px;
  padding: 5px 9px;
  text-align: left;
}
.funnel button:hover, .funnel button.on { background: var(--surface); border-color: var(--line); }
.funnel .lbl { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.funnel .num { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.moodbar { display: flex; height: 6px; border-radius: 999px; overflow: hidden; background: var(--line); }
.moodbar span { display: block; height: 100%; }
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 9px;
  padding: 5px 9px;
  font-size: 13px;
  z-index: 50;
  white-space: nowrap;
}

/* Pipeline */
.kanban { display: flex; gap: 12px; align-items: flex-start; min-height: 100%; }
.column {
  flex: 0 0 260px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 110px);
}
.column header { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.column header .row { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.column header .sum { color: var(--muted); font-size: 12px; margin-top: 2px; }
.column .cards { padding: 8px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 60px; }
.column.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.kcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: grab;
}
.kcard:hover { border-color: var(--line-strong); }
.kcard .name { font-weight: 700; display: flex; gap: 6px; }
.kcard .meta { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 6px; margin-top: 2px; }
.kcard.dragging { opacity: 0.4; }

/* Tabla de contactos */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select { width: auto; }
.toolbar .grow { flex: 1; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 700; cursor: pointer; user-select: none; background: var(--surface-2); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.more { text-align: center; padding: 12px; }

/* Tareas */
.task-group { margin-bottom: 18px; }
.task-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px; }
.task {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 6px;
}
.task input { margin-top: 3px; width: 16px; height: 16px; flex: none; }
.task .body { flex: 1; min-width: 0; }
.task .who { color: var(--muted); font-size: 12px; cursor: pointer; }
.task .who:hover { text-decoration: underline; }
.due.late { color: var(--danger); font-weight: 700; }

/* Ajustes */
.settings { display: grid; gap: 16px; max-width: 760px; }
.settings h2 { font-size: 16px; margin: 0 0 12px; }
.stage-row { display: grid; grid-template-columns: 26px 1fr 54px; gap: 8px; align-items: center; margin-bottom: 6px; }
.stage-row input[type="color"] { width: 54px; height: 36px; padding: 2px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.user-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); gap: 8px; }

/* Ficha de contacto */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-y: auto;
  z-index: 20;
  animation: slide 0.18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.drawer-head .row { display: flex; gap: 10px; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.drawer-head .mood { font-size: 30px; }
.drawer-head .sub { color: var(--muted); margin: 2px 0 10px; }
.drawer-head .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.drawer section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 16px; }
.stat span { font-size: 12px; color: var(--muted); }
.reasons { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.deal { display: grid; grid-template-columns: 1fr 96px 92px 28px; gap: 6px; align-items: center; margin-bottom: 6px; }
.deal input, .deal select { padding: 6px 8px; }
.composer { display: grid; gap: 8px; }
.composer .types { display: flex; gap: 4px; flex-wrap: wrap; }
.composer .types button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.composer .types button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.composer .row { display: flex; gap: 8px; }
.timeline { list-style: none; padding: 0; margin: 12px 0 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.timeline .ico { width: 22px; text-align: center; flex: none; }
.timeline .body { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.timeline .when { color: var(--muted); font-size: 12px; }
.timeline .done { text-decoration: line-through; color: var(--muted); }

/* Modal y avisos */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 20, 30, 0.45); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 60;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; overflow: auto; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #ffe3d6, transparent 40%), radial-gradient(circle at 80% 90%, #d6ecff, transparent 45%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 800; }
.login-brand .logo { font-size: 30px; }
.error { color: var(--danger); margin: 0; font-weight: 600; }

/* Móvil */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .nav {
    order: 2;
    flex-direction: row;
    justify-content: space-around;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .nav a { flex-direction: column; gap: 0; padding: 4px 6px; font-size: 11px; }
  .nav .ico { font-size: 18px; }
  .nav .brand, .nav-foot { display: none; }
  .nav .badge { position: absolute; margin: -2px 0 0 18px; }
  .nav a[data-view="tasks"] { position: relative; }
  .top { padding: 8px 10px; gap: 8px; }
  .top h1 { display: none; }
  #q { max-width: none; margin-left: 0; }
  .hide-sm { display: none; }
  .park-tools { right: 12px; flex-wrap: wrap; }
  .feed { top: auto; bottom: 86px; left: 12px; right: 12px; width: auto; max-height: 40%; }
  .view.scroll { padding: 10px; }
  .column { flex-basis: 78vw; max-height: none; }
  .form-grid, .grid2 { grid-template-columns: 1fr; }
  .deal { grid-template-columns: 1fr 80px 84px 28px; }
}

/* Tour de bienvenida */
.tour-shade { position: fixed; inset: 0; background: rgba(10, 20, 30, 0.55); z-index: 80; }
.tour-spot {
  position: fixed;
  z-index: 81;
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(10, 20, 30, 0.55), 0 0 0 3px var(--accent);
  pointer-events: none;
  transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
}
.tour-card {
  position: fixed;
  z-index: 82;
  width: min(360px, calc(100vw - 24px));
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  padding: 16px 18px 14px;
  transition: left 0.25s ease, top 0.25s ease;
}
.tour-card h3 { margin: 2px 0 6px; font-size: 17px; }
.tour-card p { margin: 0 0 12px; color: var(--muted); }
.tour-card p b { color: var(--ink); }
.tour-card kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 12px; }
.tour-count { font-size: 12px; font-weight: 700; color: var(--accent); }
.tour-dots { display: flex; gap: 4px; margin-bottom: 12px; }
.tour-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); }
.tour-dots span.on { background: var(--accent); width: 16px; border-radius: 3px; }
.tour-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tour-actions .grow { flex: 1; }
