:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #111827;
  --muted: #64748b;
  --line: #dbe3ea;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --orange: #f45b2a;
  --orange-soft: #fff2eb;
  --green: #20815f;
  --amber: #b06b12;
  --red: #b42318;
  --blue: #2f6690;
  --shadow: 0 10px 26px rgba(24, 35, 31, 0.07);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 36px;
  padding: 0 13px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button.secondary,
.secondary,
.quotes-table button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

button.secondary:hover,
.secondary:hover,
.quotes-table button:hover {
  background: var(--surface-soft);
}

button.primary-action {
  min-height: 44px;
  font-weight: 800;
}

.action-grid .primary-action:first-child {
  background: var(--orange);
  border-color: var(--orange);
}

.action-grid .primary-action:first-child:hover {
  background: #df4515;
  border-color: #df4515;
}

input,
select,
textarea {
  width: 100%;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 78px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.credentials-screen .topbar {
  padding-left: 304px;
}

.topbar-copy {
  display: grid;
  gap: 8px;
}

.topbar h1,
.panel h2,
.lead-rail h2 {
  margin: 0;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 26px;
}

.topbar-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.icon-link {
  text-decoration: none;
}

.system-pill,
.rail-source {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border: 1px solid #bde6d1;
  border-radius: 999px;
  background: #f0fbf5;
  color: #087443;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.rail-source {
  border-color: #ffd1bd;
  background: var(--orange-soft);
  color: #cf3f12;
}

button.rail-source {
  min-height: 28px;
  border-radius: 999px;
  cursor: pointer;
}

button.rail-source:hover {
  background: #ffe4d6;
  border-color: #ffb99c;
  color: #b7370e;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 19px;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 270px minmax(236px, 258px) minmax(500px, 1fr) minmax(370px, 410px);
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.main-panel .app-shell > .topbar {
  display: none;
}

.app-shell > .workspace {
  min-height: 100vh;
}

.module-nav {
  width: 270px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: fixed;
  top: 10px;
  left: 10px;
  height: calc(100vh - 20px);
  max-height: calc(100vh - 20px);
  padding: 18px 18px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 3;
}

.sidebar-brand {
  display: block;
  margin-bottom: 18px;
  text-decoration: none;
}

.sidebar-brand-logo {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
}

.module-button {
  min-height: 46px;
  text-decoration: none;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.module-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

.module-button strong {
  font-size: 14px;
  line-height: 1.15;
}

.module-button.is-active {
  border-color: #ffd1bd;
  background: var(--orange-soft);
  color: var(--orange);
}

.module-button.is-active .module-icon {
  background: var(--orange);
  color: #fff;
}

.sidebar-spacer {
  flex: 1 1 auto;
  min-height: 18px;
}

.sidebar-status {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid #ffd1bd;
  border-radius: 10px;
  background: var(--orange-soft);
}

.sidebar-status .system-pill {
  width: fit-content;
}

.sidebar-status p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.sidebar-online {
  width: fit-content;
  padding: 3px 7px;
  border: 1px solid #bde6d1;
  border-radius: 999px;
  background: #f0fbf5;
  color: #087443;
  font-size: 10px;
  font-weight: 900;
}

.sidebar-tools {
  display: flex;
  gap: 8px;
}

.sidebar-tools .icon-button {
  flex: 1;
  width: auto;
}

.lead-rail,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.pipeline-area {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.pipeline-header {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.pipeline-header p:last-child {
  margin: 0;
  color: var(--muted);
}

.pipeline-board {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  overflow: visible;
}

.pipeline-column {
  min-height: 360px;
  max-height: 360px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  transition: border-color 0.18s ease, background 0.18s ease;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.pipeline-column.is-drop-target,
.pipeline-card-list.is-drop-target {
  border-color: var(--accent);
  background: #eefaf7;
}

.pipeline-column header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 6px;
}

.pipeline-column h3 {
  margin: 0;
  font-size: 11px;
  line-height: 1.15;
}

.pipeline-column header span {
  min-width: 20px;
  min-height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
  font-size: 10px;
}

.pipeline-card-list {
  display: grid;
  gap: 4px;
  min-height: 0;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.pipeline-card {
  display: grid;
  gap: 1px;
  min-height: 62px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.03);
}

.pipeline-card.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--orange), 0 0 0 2px rgba(15, 118, 110, 0.08);
}

.pipeline-card.is-dragging {
  opacity: 0.55;
}

.pipeline-card strong,
.pipeline-card span,
.pipeline-card small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-card strong {
  font-size: 12px;
  line-height: 1.15;
  font-weight: 900;
}

.pipeline-card span,
.pipeline-card small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

.pipeline-empty {
  margin: 0;
  padding: 10px 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.credentials-area {
  display: grid;
  gap: 14px;
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.settings-tab {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.settings-tab.is-active {
  border-color: #ffc8b2;
  background: #fff2ec;
  color: var(--accent-dark);
}

.settings-section[hidden] { display: none !important; }

.message-settings-form { display: grid; gap: 14px; }
.message-signature { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.message-editor-toolbar { display: grid; grid-template-columns: minmax(180px, 240px) minmax(0, 1fr); gap: 10px; align-items: end; }
.message-editor-toolbar.has-variants { grid-template-columns: minmax(180px, 240px) minmax(130px, 180px) minmax(110px, 150px) minmax(135px, 170px) minmax(0, 1fr); }
.message-greeting-schedule { display: grid; grid-template-columns: minmax(220px, 1.3fr) minmax(130px, 1fr) minmax(130px, 1fr); gap: 10px; }
.message-variable-palette { display: flex; flex-wrap: wrap; gap: 6px; min-height: 38px; align-items: center; }
.message-variable { padding: 6px 8px; border: 1px solid #ffd0bf; border-radius: 7px; background: #fff5f0; color: var(--accent-dark); font-size: 11px; font-weight: 800; cursor: grab; white-space: nowrap; }
.message-variable:active { cursor: grabbing; }
.message-editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.message-editor-grid fieldset { min-width: 0; }
.message-preview-data { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.message-preview-data label { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: capitalize; }
.message-preview-data input { width: 100%; margin-top: 3px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 11px; }
.message-preview { min-height: 260px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); white-space: pre-wrap; line-height: 1.45; }
.message-editor-actions { display: flex; gap: 8px; margin-top: 10px; }

/* The previous grouped form stays compatible with old local data but is no longer shown in other screens. */
.credentials-area[data-settings-section="credentials"] fieldset[data-settings-group="messages"],
.credentials-area[data-settings-section="credentials"] fieldset[data-settings-group="leads"] { display: none; }

.credentials-form textarea {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  font: inherit;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.credentials-status {
  padding: 7px 10px;
  border: 1px solid #bfe8da;
  border-radius: 999px;
  background: #eefaf7;
  color: #006b5f;
  font-weight: 800;
  font-size: 12px;
}

.credentials-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.credentials-form fieldset {
  margin: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.credentials-form legend {
  padding: 0 6px;
  color: var(--ink);
  font-weight: 900;
}

.credentials-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.credentials-form .full-span {
  grid-column: 1 / -1;
}

.credentials-form input {
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.credentials-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.catalog-area {
  gap: 16px;
}

.catalog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.catalog-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.catalog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}

.catalog-actions button,
.catalog-remove {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.catalog-actions .primary {
  border-color: var(--orange);
  background: var(--orange);
  color: #fff;
}

.catalog-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr);
  gap: 12px;
}

.catalog-panel {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.catalog-panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.catalog-panel-heading h3 {
  margin: 0;
  font-size: 16px;
}

.catalog-panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.company-catalog,
.plan-catalog {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 3px;
}

.company-card,
.plan-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.company-card {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.company-card-preview {
  display: grid;
  place-items: center;
  min-height: 58px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: #fff;
}

.company-card-preview img {
  display: block;
  max-width: 74px;
  max-height: 42px;
  object-fit: contain;
}

.company-card-fields,
.plan-card-fields {
  display: grid;
  gap: 8px;
}

.catalog-label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.catalog-label input[type="text"],
.catalog-label input[type="url"] {
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.catalog-file {
  width: 100%;
  color: var(--muted);
  font-size: 11px;
}

.catalog-plan-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  padding-top: 2px;
}

.catalog-plan-grid label,
.catalog-all-plans {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.catalog-remove {
  align-self: start;
  padding: 0 8px;
  color: #bd3c22;
}

.plan-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.plan-card small {
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 900px) {
  .catalog-layout {
    grid-template-columns: 1fr;
  }

  .catalog-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

.credentials-page {
  grid-template-columns: 270px minmax(0, 1fr);
}

.credentials-page-content {
  grid-column: 2;
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}

.remote-access-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.remote-access-grid article {
  min-width: 0;
  padding: 12px;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.remote-access-grid strong {
  color: var(--ink);
}

.remote-access-grid span {
  color: var(--muted);
  line-height: 1.35;
}

.logs-content {
  align-content: start;
}

.logs-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logs-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 160px 160px auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.logs-filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.logs-filters input,
.logs-filters select {
  min-height: 38px;
  padding: 0 10px;
}

.logs-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.logs-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.logs-table th,
.logs-table td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

.logs-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  text-transform: uppercase;
}

.logs-table tr:last-child td {
  border-bottom: 0;
}

.logs-table time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.log-level {
  display: inline-flex;
  min-width: 34px;
  justify-content: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
}

.log-level.is-info {
  background: #e7f5ed;
  color: var(--green);
}

.log-level.is-error {
  background: #fff0ee;
  color: var(--red);
}

.log-message {
  min-width: 320px;
  color: var(--ink);
  line-height: 1.35;
}

.lead-rail {
  grid-column: 2;
  min-width: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.rail-header,
.panel-title-row,
.message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lead-rail h2,
.panel h2 {
  font-size: 18px;
}

.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-box input {
  min-height: 38px;
  padding: 0 11px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-card {
  min-height: 54px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-card strong {
  font-size: 18px;
}

.status-card span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-list {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  min-width: 0;
}

.lead-row {
  width: 100%;
  min-width: 0;
  min-height: 62px;
  padding: 8px 10px;
  display: grid;
  gap: 1px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.03);
}

.lead-row:hover {
  border-color: #b4c3bc;
  background: var(--surface-soft);
}

.lead-row.is-active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--orange), 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.empty-state {
  padding: 14px;
  border: 1px dashed #c7d3dd;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.lead-name {
  min-width: 0;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-meta,
.lead-id {
  min-width: 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-area,
.side-area {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 14px;
}

.detail-area {
  grid-column: 3;
}

.side-area {
  grid-column: 4;
}

.panel {
  min-width: 0;
  padding: 13px;
}

.panel-title-row select {
  max-width: 190px;
  min-height: 38px;
  padding: 0 10px;
}

.lead-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

button.danger {
  color: var(--red);
}

button.danger:hover {
  background: #fff0ee;
  border-color: #f3b8af;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stage-line {
  margin: 10px 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.stage {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 5px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.stage.is-done {
  background: #e7f5ed;
  color: var(--green);
  border-color: #b7dfc8;
}

.stage.is-current {
  background: #e8f3f1;
  color: var(--accent-dark);
  border-color: #94d2cb;
}

.lead-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.lead-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.lead-form label:has(input[name="quoteNumber"]) {
  display: none;
}

.lead-form label:has(input[name="firstName"]) { order: 1; }
.lead-form label:has(input[name="lastName"]) { order: 2; }
.lead-form label:has(input[name="rut"]) { order: 3; }
.lead-form label:has(input[name="zohoId"]) { order: 4; }
.lead-form label:has(input[name="birthDate"]) { order: 5; }
.lead-form label:has(input[name="comuna"]) { order: 6; }
.lead-form label:has(input[name="email"]) { order: 7; }
.lead-form label:has(input[name="phone"]) { order: 8; }
.lead-form label:has(input[name="brand"]) { order: 9; }
.lead-form label:has(input[name="model"]) { order: 10; }
.lead-form label:has(input[name="year"]) { order: 11; }
.lead-form label:has(input[name="plate"]) { order: 12; }

.lead-form input {
  min-height: 34px;
  padding: 0 10px;
}

.button-group,
.action-grid {
  display: flex;
  gap: 8px;
}

.quote-rule {
  min-height: 38px;
  margin: 12px 0;
  padding: 9px 11px;
  border: 1px solid #d8e8e4;
  border-radius: 8px;
  background: #f2fbf8;
  color: var(--accent-dark);
  font-size: 13px;
}

.quotes-panel {
  position: relative;
}

.fidens-layout {
  display: grid;
  grid-template-columns: 152px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.offer-filters {
  min-height: 360px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.filter-section + .filter-section {
  margin-top: 14px;
}

.filter-section p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.filter-check {
  min-height: 22px;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: start;
  gap: 6px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

.filter-check input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.fidens-offers {
  min-width: 0;
  max-height: 650px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.fidens-offer-head,
.offer-row {
  display: grid;
  grid-template-columns: minmax(82px, 0.92fr) repeat(4, minmax(62px, 1fr));
  align-items: stretch;
}

.optional-cell {
  display: none;
}

.fidens-offer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--orange);
  color: #fff;
  border-bottom: 1px solid #df4515;
}

.fidens-offer-head > * {
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 6px 4px;
  font-size: 10px;
  font-weight: 800;
}

.offer-row {
  position: relative;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.offer-row:last-child {
  border-bottom: 0;
}

.plan-strip {
  position: absolute;
  top: 0;
  left: 0;
  width: 86px;
  height: 12px;
  display: grid;
  place-items: center;
  background: #ffd600;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
}

.plan-exclusive .plan-strip {
  background: #ff7a00;
}

.plan-premium .plan-strip {
  background: #009b2f;
}

.plan-bonificacion .plan-strip,
.plan-bonificacia3n .plan-strip {
  background: #6fa3e8;
}

.company-cell {
  min-height: 82px;
  padding: 18px 8px 8px;
  display: grid;
  place-items: center;
}

.company-cell img {
  width: 94px;
  height: 42px;
  object-fit: contain;
}

.company-cell img[alt="FID"],
.company-cell img[alt="HDI"] {
  transform: scale(1.16);
}

.optional-cell {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #315da8;
  border-left: 1px solid #eef2f6;
}

.offer-row .optional-cell {
  display: none;
}

.icon-mini {
  width: 28px;
  min-height: 28px;
  padding: 0;
  background: #eef5ff;
  color: #315da8;
  border-color: #d4e4fb;
}

.offer-price {
  min-height: 82px;
  padding: 9px 4px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  border: 0;
  border-left: 1px solid #eef2f6;
  border-radius: 0;
  background: #fff;
  color: #30405f;
  text-align: center;
}

.offer-price:hover {
  background: #f7fbff;
  color: #30405f;
}

.offer-price.is-selected {
  background: #eef9f6;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.offer-price.is-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #fafbfc;
}

.offer-price strong {
  font-size: 15px;
  line-height: 1;
}

.offer-price small,
.offer-price em {
  font-size: 10px;
  font-style: normal;
}

.radio-dot {
  width: 14px;
  height: 14px;
  border: 2px solid #9ca3af;
  border-radius: 999px;
}

.offer-price.is-selected .radio-dot {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px #fff;
  background: var(--accent);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quotes-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.quotes-table th,
.quotes-table td {
  height: 46px;
  padding: 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

.quotes-table th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quotes-table tr:last-child td {
  border-bottom: 0;
}

.quotes-table tr.is-selected td {
  background: #f2fbf8;
}

.quotes-table input,
.quotes-table select {
  min-height: 34px;
  padding: 0 8px;
}

.quotes-table .money,
.quotes-table .number {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pdf-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.actions-panel {
  padding-bottom: 12px;
  order: 1;
}

.bot-mode-select {
  max-width: 180px;
  min-height: 38px;
  padding: 0 12px;
  color: var(--ink);
  font-size: 16px;
}

.action-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 54px;
  align-items: stretch;
}

.action-grid-compact button {
  min-height: 44px;
  font-size: 14px;
  font-weight: 800;
}

.stop-action {
  min-width: 54px;
  padding: 0;
  display: grid;
  place-items: center;
  border-color: #fecaca;
  background: #fff1f2;
  color: #be123c;
}

.stop-action::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 3px solid currentColor;
  background:
    linear-gradient(currentColor, currentColor) center / 11px 11px no-repeat;
  transform: rotate(45deg);
}

.stop-action span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.stop-action:hover {
  border-color: #fb7185;
  background: #ffe4e6;
  color: #9f1239;
}

.bot-status {
  margin-top: 12px;
  padding: 10px;
  display: grid;
  gap: 7px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.bot-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
}

.bot-step.is-done {
  color: var(--ink);
}

.bot-step.is-warn {
  color: var(--amber);
}

.bot-step strong {
  color: var(--ink);
}

.bot-dot {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e8f3f1;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
}

.bot-step.is-done .bot-dot {
  background: #e7f5ed;
  color: var(--green);
}

.bot-step.is-current .bot-dot {
  background: var(--orange-soft);
  color: var(--orange);
}

.bot-step.is-warn .bot-dot {
  background: #fff2da;
  color: var(--amber);
}

.bot-status.is-running .bot-step:last-child:not(.is-warn) .bot-dot {
  color: transparent;
  border: 3px solid #d8e8e6;
  border-top-color: var(--accent);
  background: #fff;
  animation: bot-spin 750ms linear infinite;
}

.bot-step.is-warn .bot-dot {
  background: #fff0f0;
  color: var(--red);
  border: 1px solid #f3b5b5;
  font-size: 0;
}

.bot-step.is-warn .bot-dot::after {
  content: "×";
  font-size: 16px;
}

.quote-process-overlay {
  display: none;
  position: absolute;
  inset: 150px 12px 20px 172px;
  z-index: 4;
  place-items: center;
  pointer-events: none;
}

.quote-process-overlay.is-visible {
  display: grid;
}

.zecka-loader {
  position: relative;
  width: 210px;
  height: 210px;
  display: grid;
  place-items: center;
}

.checkseg-loader-mark {
  position: relative;
  z-index: 2;
  width: 138px;
  height: 138px;
  overflow: hidden;
  display: block;
  border-radius: 50%;
  background: transparent;
  filter: drop-shadow(0 10px 18px rgba(245, 82, 35, .18));
}

.checkseg-loader-mark img {
  position: absolute;
  max-width: none;
  height: auto;
  left: 50%;
  top: 50%;
  width: 118px;
  transform: translate(-50%, -50%);
}

.zecka-loader span,
.zecka-loader::before,
.zecka-loader::after {
  position: absolute;
  content: "";
  width: 170px;
  height: 170px;
  border-radius: 50%;
  border: 12px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  opacity: .95;
  animation: bot-spin 1100ms linear infinite;
  z-index: 1;
}

.zecka-loader::before {
  width: 132px;
  height: 132px;
  border-width: 10px;
  border-top-color: transparent;
  border-right-color: var(--accent-dark);
  border-bottom-color: var(--accent-dark);
  animation-duration: 1500ms;
  animation-direction: reverse;
  opacity: .82;
}

.zecka-loader::after {
  width: 204px;
  height: 204px;
  border-width: 6px;
  border-left-color: #cce5e1;
  border-bottom-color: #cce5e1;
  animation-duration: 1900ms;
  opacity: .7;
}

@keyframes bot-spin {
  to { transform: rotate(360deg); }
}

[data-action].is-running {
  opacity: .82;
}

[data-action]:disabled,
#openWhatsapp:disabled {
  cursor: wait;
}

.message-panel {
  display: grid;
  gap: 12px;
  order: 2;
}

.message-panel textarea {
  width: 100%;
  min-height: 368px;
  height: 368px;
  max-height: 368px;
  resize: none;
  padding: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.message-footer {
  justify-content: stretch;
}

.message-footer button {
  flex: 1;
  min-height: 42px;
}

.faq-select {
  min-height: 42px;
  font-weight: 700;
}

.activity-log {
  max-height: 210px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.activity-log li {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.activity-log li:last-child {
  border-bottom: 0;
}

.activity-log time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.activity-log span {
  min-width: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 29, 25, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16, 24, 20, 0.22);
}

.modal-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal textarea {
  min-height: 300px;
  padding: 12px;
  line-height: 1.35;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 232px minmax(250px, 280px) minmax(0, 1fr);
  }

  .credentials-page {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .module-nav {
    width: 232px;
  }

  .credentials-screen .topbar {
    padding-left: 266px;
  }

  .credentials-page-content {
    grid-column: 2;
  }

  .detail-area {
    grid-column: 3;
  }

  .side-area {
    grid-column: 2 / -1;
    grid-template-columns: 1fr;
  }

  .pipeline-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
  }

  .workspace,
  .side-area {
    grid-template-columns: 1fr;
  }

  .module-nav {
    position: static;
    width: auto;
    min-width: 0;
    top: auto;
    left: auto;
    height: auto;
    max-height: none;
    flex-direction: row;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .credentials-screen .topbar {
    padding-left: 24px;
  }

  .lead-rail,
  .credentials-page-content,
  .detail-area,
  .side-area {
    grid-column: auto;
  }

  .sidebar-brand {
    margin: 0 8px 0 0;
    flex: 0 0 auto;
  }

  .sidebar-brand-logo {
    max-width: 120px;
  }

  .side-area {
    grid-column: 1 / -1;
  }

  .pipeline-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .credentials-form,
  .credentials-form fieldset {
    grid-template-columns: 1fr;
  }

  .logs-filters {
    grid-template-columns: 1fr 1fr;
  }

  .lead-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-line {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar,
  .workspace {
    padding: 10px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .lead-form,
  .stage-line,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .logs-filters {
    grid-template-columns: 1fr;
  }

  .panel-title-row,
  .rail-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-title-row select,
  .lead-tools,
  .button-group {
    width: 100%;
  }

  .lead-tools,
  .button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
