:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e1e4ea;
  /* Colores de marca gogüeb */
  --brand-orange: #ff4d00;
  --brand-orange-dark: #d94100;
  --brand-orange-tint: #fff0e8;
  --brand-blue: #0047ba;
  --brand-blue-dark: #003a99;
  --brand-blue-tint: #e6eefb;
  /* El azul lleva botones y ligas (mejor contraste con texto); el naranja es el acento */
  --primary: var(--brand-blue);
  --primary-hover: var(--brand-blue-dark);
  --accent: var(--brand-orange);
  --danger: #c0352b;
  --ok-bg: #e7f6ec;
  --ok-text: #14602e;
  --warn-bg: #fff4dd;
  --warn-text: #7a4b00;
  --error-bg: #fdeaea;
  --error-text: #9b1c1c;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0; }

.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }

/* Barra superior */
.topbar { background: var(--surface); border-top: 4px solid var(--accent); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 0.6rem 1rem;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-company { color: var(--accent); font-size: 1.15rem; }
.brand-tag {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; color: var(--brand-blue);
  background: var(--brand-blue-tint); border-radius: 5px; padding: 0.1rem 0.4rem; margin-top: 2px;
}
.topnav { display: flex; gap: 1rem; flex: 1; }
.topnav a { color: var(--muted); padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.topnav a.active { color: var(--brand-blue); font-weight: 600; border-bottom-color: var(--accent); }
.topnav a:hover { text-decoration: none; color: var(--text); }
.logout { display: flex; align-items: center; gap: 0.75rem; margin: 0; }
.user-name { color: var(--muted); font-size: 0.9rem; }

/* Página */
.page { max-width: 1000px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-centered { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem;
}
.card-narrow { max-width: 400px; width: 100%; margin-left: auto; margin-right: auto; }
.card-medium { max-width: 520px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem;
}

.pill {
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.2rem 0.75rem; font-size: 0.9rem;
}
.chip {
  display: inline-block; background: var(--bg); border-radius: 999px;
  padding: 0.1rem 0.6rem; margin: 0.1rem 0.25rem 0.1rem 0; font-size: 0.85rem;
}

/* Formularios */
label { display: block; font-size: 0.9rem; font-weight: 600; }

/* Selector de país del teléfono */
.iti { display: block; margin-top: 0.3rem; font-weight: 400; }
.iti input[type="tel"] { margin-top: 0; }
.field-error[hidden] { display: none; }
input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="date"] {
  display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.7rem;
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid #c9ced8; border-radius: 8px;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
input[aria-invalid="true"] { border-color: var(--danger); }
.hint { display: block; margin-top: 0.25rem; font-size: 0.8rem; font-weight: 400; color: var(--muted); }
.hint[hidden] { display: none; }
.date-warning { color: var(--warn-text); font-weight: 600; }
.field-error { display: block; margin-top: 0.25rem; font-size: 0.8rem; font-weight: 400; color: var(--danger); }

label.check {
  display: flex; align-items: center; gap: 0.4rem; margin-top: 0.4rem;
  font-size: 0.85rem; font-weight: 400; color: var(--muted); cursor: pointer;
}
label.check input { margin: 0; }
input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.chip-unknown { color: var(--muted); font-style: italic; }

.stack > * + * { margin-top: 0.9rem; }

.lead-form {
  display: grid; gap: 0.9rem; align-items: start;
  grid-template-columns: 1fr 1.6fr 0.8fr auto;
}
.lead-form .btn { margin-top: 1.65rem; }
@media (max-width: 760px) {
  .lead-form { grid-template-columns: 1fr; }
  .lead-form .btn { margin-top: 0; }
}

.btn {
  display: inline-block; padding: 0.6rem 1.1rem; font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); padding: 0.35rem 0.8rem; font-weight: 500; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); padding: 0.4rem 0.9rem; }
.btn-danger:hover { background: var(--error-bg); }

.actions { display: flex; gap: 0.75rem; align-items: center; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Mensajes */
.flash { padding: 0.7rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.95rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-warn { background: var(--warn-bg); color: var(--warn-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.row-active td { background: var(--brand-blue-tint); }

/* Navegación secundaria */
.crumbs { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--muted); }
h3 { font-size: 0.95rem; margin: 1.1rem 0 0.5rem; }
h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 0.3rem; }
.small { font-size: 0.82rem; }
.card-wide { max-width: 820px; }
.grid-2 { display: grid; gap: 0.9rem; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 1.25rem; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
label.narrow { max-width: 260px; }

select {
  display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.7rem; font: inherit; font-weight: 400;
  color: var(--text); background: var(--surface); border: 1px solid #c9ced8; border-radius: 8px;
}
select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
select[aria-invalid="true"] { border-color: var(--danger); }

/* Origen del lead */
fieldset.origin { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.origin legend { padding: 0; font-size: 0.9rem; font-weight: 600; }
.radio-row { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; }
.radio-row label.check { margin-top: 0.3rem; color: var(--text); }
[data-origin-panel][hidden] { display: none; }

/* Etapas */
.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: var(--bg); color: var(--muted); }
.badge-seguimiento { background: var(--brand-blue-tint); color: var(--brand-blue); }
.badge-conversacion { background: #e3f4fb; color: #0b5c7a; }
.badge-propuesta { background: var(--brand-orange-tint); color: #b23600; }
.badge-ganado { background: var(--ok-bg); color: var(--ok-text); }
.badge-perdido, .badge-late { background: var(--error-bg); color: var(--error-text); }
.badge-today { background: var(--warn-bg); color: var(--warn-text); }
.filters { display: flex; flex-wrap: wrap; gap: 0.15rem; margin-bottom: 0.75rem; }
.chip-link { color: var(--text); border: 1px solid var(--border); background: var(--surface); }
.chip-link:hover { text-decoration: none; background: var(--bg); }
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-active:hover { background: var(--primary-hover); }

/* Ficha del lead */
.summary { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin: 0 0 1rem; }
.summary dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; }
.action-grid { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: flex-start; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; margin: 0; }
.inline-form label { min-width: 170px; }
.undo { margin: 0.9rem 0 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.link-danger { color: var(--danger); }
.btn-success { background: #1a7f3c; color: #fff; }
.btn-success:hover { background: #14602e; }
.btn-small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.notice { background: var(--warn-bg); color: var(--warn-text); padding: 0.7rem 0.9rem; border-radius: 8px; font-size: 0.95rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.35rem 0; border-bottom: 1px solid var(--border); display: flex; gap: 0.9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .muted { min-width: 8.5rem; }

/* Propuestas */
.proposal { border-top: 1px solid var(--border); padding: 1rem 0; }
.proposal:first-of-type { border-top: 0; padding-top: 0; }
.proposal h3 { margin: 0; font-size: 1.05rem; }
.proposal-cols { display: grid; gap: 1.5rem; grid-template-columns: 1fr 1fr; margin: 0.75rem 0; }
@media (max-width: 760px) { .proposal-cols { grid-template-columns: 1fr; } }
.items-table td { padding: 0.3rem 0.4rem; }
.items-table tfoot td { border-bottom: 0; color: var(--muted); padding: 0.15rem 0.4rem; }
.items-table tfoot tr:first-child td { border-top: 1px solid var(--border); padding-top: 0.4rem; }
.items-table tfoot tr.strong td { color: var(--text); font-weight: 700; }
.proposal .actions { flex-wrap: wrap; }
.proposal .actions form { margin: 0; }

.items-head, .item-row { display: grid; grid-template-columns: 1fr 170px auto; gap: 0.6rem; align-items: start; }
.items-head { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.items-head span:last-child { width: 4.4rem; }
.item-row { margin-bottom: 0.5rem; }
.item-row select, .item-row input { margin-top: 0; }
.item-row input { text-align: right; }
.item-row .btn { padding: 0.6rem 0.8rem; }
.item-error { grid-column: 1 / -1; margin-top: -0.2rem; }
@media (max-width: 600px) { .items-head { display: none; } .item-row { grid-template-columns: 1fr; } }
.totals { margin: 1rem 0 0 auto; max-width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 0.15rem 0; color: var(--muted); }
.totals dd { margin: 0; font-variant-numeric: tabular-nums; }
.totals .totals-total { border-top: 1px solid var(--border); margin-top: 0.3rem; padding-top: 0.4rem; color: var(--text); font-weight: 700; font-size: 1.05rem; }

/* Tablas con acciones */
.row-actions { display: flex; gap: 0.8rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.row-inactive td { color: var(--muted); }

/* Dashboard */
.tiles { display: grid; gap: 0.75rem; grid-template-columns: repeat(4, 1fr); margin-bottom: 0.5rem; }
.tiles-stages { grid-template-columns: repeat(7, 1fr); }
@media (max-width: 900px) { .tiles, .tiles-stages { grid-template-columns: repeat(2, 1fr); } }
.tile { display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 0.9rem; }
.tile-link { color: var(--text); }
.tile-link:hover { text-decoration: none; border-color: var(--primary); }
.tile-value { font-size: 1.7rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile-label { font-size: 0.85rem; color: var(--muted); }
.tile-note { font-size: 0.8rem; margin-top: 0.25rem; }
.tile-won { background: var(--ok-bg); border-color: #bfe5cb; }
.tile-won .tile-value, .tile-won .tile-note { color: var(--ok-text); }
.period-form { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0; }
.period-form input[type="date"] { width: auto; margin-top: 0; padding: 0.3rem 0.5rem; font-size: 0.9rem; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 300px; gap: 0.75rem; align-items: center; padding: 0.3rem 0; }
.funnel-bar { background: var(--bg); border-radius: 6px; height: 1.1rem; overflow: hidden; }
.funnel-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-blue), #2f6fe0); border-radius: 6px; min-width: 2px; }
@media (max-width: 760px) { .funnel-row { grid-template-columns: 1fr; gap: 0.15rem; } }
.big-number { font-size: 1.7rem; font-weight: 700; margin: 0; }
.reason-list { list-style: none; margin: 0; padding: 0; }
.reason-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.reason-list li:last-child { border-bottom: 0; }
.funnel-w-0 { width: 0%; }
.funnel-w-5 { width: 5%; }
.funnel-w-10 { width: 10%; }
.funnel-w-15 { width: 15%; }
.funnel-w-20 { width: 20%; }
.funnel-w-25 { width: 25%; }
.funnel-w-30 { width: 30%; }
.funnel-w-35 { width: 35%; }
.funnel-w-40 { width: 40%; }
.funnel-w-45 { width: 45%; }
.funnel-w-50 { width: 50%; }
.funnel-w-55 { width: 55%; }
.funnel-w-60 { width: 60%; }
.funnel-w-65 { width: 65%; }
.funnel-w-70 { width: 70%; }
.funnel-w-75 { width: 75%; }
.funnel-w-80 { width: 80%; }
.funnel-w-85 { width: 85%; }
.funnel-w-90 { width: 90%; }
.funnel-w-95 { width: 95%; }
.funnel-w-100 { width: 100%; }

/* Próxima acción */
.grid-action { display: grid; gap: 0.9rem; grid-template-columns: 1.4fr 1fr; }
@media (max-width: 600px) { .grid-action { grid-template-columns: 1fr; } }
.next-action > label { margin-top: 0.6rem; }
.respond-form { flex: 1 1 380px; max-width: 520px; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; }
.change-action { margin-top: 0.9rem; }
.change-action summary { cursor: pointer; color: var(--primary); font-size: 0.9rem; }
.change-action form { margin-top: 0.75rem; max-width: 520px; }
.reschedule { display: flex; gap: 0.3rem; align-items: center; }
.reschedule input[type="date"] { width: auto; margin-top: 0; padding: 0.25rem 0.4rem; font-size: 0.85rem; }
#proxima:target { border-color: var(--primary); box-shadow: 0 0 0 3px var(--brand-blue-tint); }

/* Marca gogüeb */
.card-accent { border-top: 3px solid var(--accent); }
.card-login { border-top: 4px solid var(--accent); padding: 1.75rem 1.5rem; box-shadow: 0 10px 30px rgba(0, 71, 186, 0.08); }
.login-logo { display: block; width: 170px; height: auto; margin: 0 auto 1rem; }
.login-title { text-align: center; font-size: 1rem; letter-spacing: 0.12em; color: var(--brand-blue); margin-bottom: 0.25rem; }
.login-sub { text-align: center; margin: 0 0 1rem; }
.btn-block { display: block; width: 100%; }
.page-centered { background: linear-gradient(160deg, var(--brand-blue-tint) 0%, var(--bg) 45%, var(--brand-orange-tint) 100%); max-width: none; }
.tile-value { color: var(--brand-blue); }
.tile-won .tile-value { color: var(--ok-text); }
.pill strong { color: var(--brand-blue); }
h1, h2 { color: #101828; }
.card-head h1 .muted, .card-head h2 .muted { font-weight: 500; }
::selection { background: var(--brand-orange-tint); }
