/* CRM of Gestu (crm.gestu.dev). Same flat navy as gestu.dev, with the brand
   blue as the single accent. Mobile first: it's used on the street. */

:root {
  --bg: #05061f;
  --surface: #0a0c33;
  --surface-2: #11143f;
  --navy: #060731;
  --accent: #0575f7;
  --accent-hover: #2a8bff;
  --ink: #f2f3fb;
  --ink-soft: #c3c6e0;
  --muted: #8f93b8;
  --line: rgb(255 255 255 / 0.1);
  --line-strong: rgb(255 255 255 / 0.2);
  --danger: #ff8a8a;
  --danger-strong: #ff3333;
  --warning: #ffc66b;
  --success: #5ef0c1;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter Tight", "Segoe UI", system-ui, sans-serif;
  --radius-control: 8px;
  --radius-panel: 12px;
  --gutter: 16px;
  --topbar-h: 56px;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.count { color: var(--muted); font-weight: 400; }

/* Buttons and controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: var(--radius-control);
  border: 1px solid transparent; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn--sm { min-height: 38px; padding: 8px 14px; font-size: 0.92rem; }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ink-soft); }
.btn--danger { background: var(--danger-strong); color: #fff; }
.btn--ghost-danger { background: transparent; border-color: rgb(255 138 138 / 0.4); color: var(--danger); }
.link-button { background: none; border: 0; padding: 8px 0; color: var(--accent-hover); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.icon-button { flex: none; width: 44px; height: 44px; border-radius: var(--radius-control); border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 1.1rem; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 0.85rem; color: var(--ink-soft); }
.field input, .field select, .field textarea, .log-contact textarea, .stage-select {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-control);
  border: 1px solid var(--line-strong); background: var(--navy); color: var(--ink);
  font-size: 1rem; /* 16px avoids zoom on iOS */
}
.field textarea, .log-contact textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .log-contact textarea:focus { border-color: var(--accent); outline: none; }
.field-error { color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.field--inline { display: flex; align-items: center; gap: 10px; }
.field--inline .stage-select { width: auto; }

/* Boot, login, denied */
.boot { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }
.login, .denied { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.login-card img { width: 96px; height: auto; }
.login-card h1 { font-size: 1.6rem; }
.password { position: relative; display: block; }
.password input { padding-right: 52px; }
.password-toggle {
  position: absolute; top: 0; right: 0; width: 48px; height: 100%;
  display: grid; place-items: center; background: none; border: 0; color: var(--ink-soft); cursor: pointer;
}
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.password-toggle .icon-eye-off, .password-toggle[aria-pressed="true"] .icon-eye { display: none; }
.password-toggle[aria-pressed="true"] .icon-eye-off { display: block; }
.form-message { font-size: 0.92rem; color: var(--danger); }
.form-message[data-tone="info"] { color: var(--ink-soft); }

/* Workspace */
.topbar {
  position: sticky; top: 0; z-index: 20; min-height: var(--topbar-h);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px var(--gutter);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }
.project-picker { flex: 1 1 140px; min-width: 0; max-width: 320px; margin-right: auto; }
.project-picker select {
  width: 100%; min-height: 40px; padding: 6px 32px 6px 12px; border-radius: var(--radius-control);
  border: 1px solid var(--line-strong); background: var(--navy); color: var(--ink); font-size: 1rem; font-weight: 600;
  text-overflow: ellipsis;
}
.project-picker select:focus { border-color: var(--accent); outline: none; }
.topbar-user { color: var(--ink-soft); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

/* Sections: Prospectos, Equipo, Proyectos */
.sections { display: flex; gap: 4px; overflow-x: auto; padding: 0 var(--gutter); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.section-link {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px;
  color: var(--ink-soft); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.section-link:hover { color: var(--ink); }
.section-link[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.page { padding: 20px var(--gutter) 40px; max-width: 880px; }
.page > h1 { font-size: 1.4rem; margin-bottom: 16px; }
.empty-project { padding: 24px var(--gutter); }
.sync { position: fixed; left: 0; right: 0; top: var(--topbar-h); z-index: 19; padding: 6px var(--gutter); background: var(--warning); color: var(--navy); font-size: 0.85rem; text-align: center; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px var(--gutter) 6px; }
.toolbar [data-add-lead] { margin-left: auto; }
.assignee-filter { flex: 1 1 160px; max-width: 260px; }
.assignee-filter select { min-height: 40px; padding: 6px 12px; }
.tabs { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-control); padding: 3px; gap: 3px; }
.tab { min-height: 36px; padding: 6px 14px; border: 0; border-radius: 6px; background: none; color: var(--ink-soft); cursor: pointer; font-weight: 600; }
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--ink); }

/* Follow-ups */
.followups { margin: 10px var(--gutter) 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--surface); }
.followups h2 { font-size: 1rem; margin-bottom: 8px; }
.followup-list { list-style: none; margin: 0; padding: 0; display: grid; }
.followup { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.followup:first-child { border-top: 0; }
.followup-open { flex: 1 1 100%; min-width: 0; display: grid; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.followup-name { font-weight: 600; }
.followup-step { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 6px 0; list-style: none; }

/* Badges */
.prio, .due { display: inline-block; font-size: 0.75rem; font-weight: 600; line-height: 1; padding: 4px 7px; border-radius: 5px; white-space: nowrap; }
.prio--alta { background: var(--accent); color: #fff; }
.prio--media { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line-strong); }
.prio--baja, .prio--none { color: var(--muted); border: 1px solid var(--line); }
.due--late { background: rgb(255 51 51 / 0.16); color: var(--danger); }
.due--today { background: rgb(255 198 107 / 0.16); color: var(--warning); }
.due--later { color: var(--muted); padding-inline: 0; }
.owner { display: inline-block; max-width: 100%; font-size: 0.78rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.owner::before { content: "● "; color: var(--accent); font-size: 0.6rem; vertical-align: 2px; }
.owner--none { color: var(--muted); }
.owner--none::before { color: var(--muted); }
.row-stage .owner { display: block; }

/* Board: columns scroll sideways and snap on phones */
.stage-jump { display: flex; gap: 6px; overflow-x: auto; padding: 0 var(--gutter) 10px; scrollbar-width: none; }
.chip { flex: none; min-height: 34px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: none; color: var(--ink-soft); font-size: 0.85rem; cursor: pointer; }
.chip::after { content: " " attr(data-count); color: var(--muted); }
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: 86%; gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory; padding: 0 var(--gutter) 24px; scroll-padding-inline: var(--gutter);
  align-items: start;
}
.column { scroll-snap-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); min-height: 160px; }
.column.is-over { border-color: var(--accent); background: var(--surface-2); }
.column--closed .column-head h2 { color: var(--ink-soft); }
.column-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 12px 14px 8px; }
.column-head h2 { font-size: 0.95rem; }
.column-body { display: grid; gap: 8px; padding: 0 10px 12px; }
.column-empty { color: var(--muted); font-size: 0.88rem; padding: 6px 4px; }

.card { background: var(--navy); border: 1px solid var(--line); border-radius: 10px; display: grid; }
.card:hover { border-color: var(--line-strong); }
.card.is-dragging { opacity: 0.5; }
.card-open { display: grid; gap: 4px; padding: 12px 12px 10px; text-align: left; background: none; border: 0; cursor: pointer; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 2px; }
.card-name { font-weight: 600; line-height: 1.3; }
.card-meta, .card-next { font-size: 0.85rem; color: var(--muted); }
.card-next { color: var(--ink-soft); }
.card-stage { min-height: 38px; margin: 0 10px 10px; width: auto; padding: 6px 10px; font-size: 0.92rem; }

/* List */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 var(--gutter); }
.field--search { grid-column: 1 / -1; }
.list-count { padding: 10px var(--gutter) 6px; font-size: 0.88rem; }
.lead-rows { list-style: none; margin: 0; padding: 0 var(--gutter) 32px; display: grid; gap: 8px; }
.row {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.row:hover { border-color: var(--line-strong); }
.row small { display: block; color: var(--muted); font-size: 0.85rem; }
.row-name { font-weight: 600; }
.row-stage { font-size: 0.85rem; color: var(--ink-soft); grid-column: 1; }
.row-prio { grid-row: 1; grid-column: 2; }
.row-next { grid-column: 1 / -1; font-size: 0.9rem; color: var(--ink-soft); }
.row-last { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); }

/* Lead sheet: full screen on phones, side panel on desktop */
.sheet {
  width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0;
  border: 0; background: var(--bg); color: var(--ink);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgb(2 3 20 / 0.7); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px var(--gutter) 8px; }
.sheet-head h2 { font-size: 1.3rem; line-height: 1.25; }
.sheet-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 0 var(--gutter) 12px; border-bottom: 1px solid var(--line); }
.sheet-meta small { flex-basis: 100%; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 var(--gutter) 24px; overscroll-behavior: contain; }
.sheet-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.sheet-section h3 { font-size: 0.95rem; margin-bottom: 10px; }
.sheet-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg);
}
.dirty-note { margin-right: auto; font-size: 0.85rem; }
.notice { margin-bottom: 12px; padding: 10px 12px; border-radius: var(--radius-control); background: rgb(255 198 107 / 0.12); color: var(--warning); font-size: 0.9rem; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.action {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border-radius: var(--radius-control);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink); text-decoration: none; font-size: 0.92rem; font-weight: 600; cursor: pointer;
}
.action:hover { border-color: var(--ink-soft); color: var(--ink); }
.action--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.action--primary:hover { background: var(--accent-hover); color: #fff; }
.action--sm { min-height: 34px; padding: 6px 10px; font-size: 0.82rem; }

.log-contact { display: grid; gap: 8px; margin-bottom: 14px; }
.log-contact .btn { justify-self: start; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.history li { padding-left: 12px; border-left: 2px solid var(--line-strong); }
.history p { white-space: pre-wrap; }

.lead-form { display: grid; gap: 8px; }
.form-section { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.form-section legend { padding: 0; margin-bottom: 10px; font-weight: 600; color: var(--ink-soft); font-size: 0.9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .field { grid-column: 1 / -1; }
.form-grid .field--half { grid-column: auto; }
.danger-zone { border-bottom: 0; }
.danger-zone p { margin-bottom: 10px; color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: var(--radius-control);
  background: var(--ink); color: var(--navy); font-weight: 600; font-size: 0.92rem;
}
.toast[data-tone="error"] { background: var(--danger-strong); color: #fff; }

.field--inline .stage-select { max-width: 100%; }

@media (max-width: 480px) {
  .topbar-user { display: none; }
  .sheet-meta .field--inline { flex: 1 1 100%; }
  .sheet-meta .field--inline .stage-select { flex: 1; min-width: 0; }
}

@media (min-width: 768px) {
  :root { --gutter: 24px; }
  .board { grid-auto-columns: minmax(180px, 1fr); scroll-snap-type: none; }
  .stage-jump { display: none; }
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .field--search { grid-column: auto; }
  .row { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto minmax(0, 2fr) minmax(0, 1.2fr); gap: 12px; }
  .row-stage, .row-prio, .row-next, .row-last { grid-column: auto; grid-row: auto; }
  .sheet { width: min(600px, 100%); margin: 0 0 0 auto; border-left: 1px solid var(--line); }
  .followup { flex-wrap: nowrap; }
  .followup-open { flex-basis: 0; }
}

/* Drag and drop works with a mouse; touch screens move cards with the selector. */
@media (hover: hover) and (pointer: fine) and (min-width: 768px) {
  .card-stage { display: none; }
  .card { cursor: grab; }
}

/* Long addresses and notes stay short on cards; the sheet shows them whole. */
.card-meta, .card-next { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }

.loading { padding: 24px var(--gutter); }
.workspace:not([data-is-loading]) .loading,
.workspace[data-is-loading] .followups,
.workspace[data-is-loading] .board-view,
.workspace[data-is-loading] .list-view,
.workspace[data-no-project] .leads-section > :not([data-no-project]) { display: none; }
.sheet .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
