:root {
  --bg: #f6f8f6;
  --panel: #ffffff;
  --border: #e7ebe8;
  --text: #16241c;
  --muted: #6b7a71;
  --accent: #1b4332;
  --accent-hover: #143024;
  --accent-soft: #e3f3ea;
  --accent-system: #1b4332;
  --accent-system-hover: #143024;
  --accent-system-soft: #dcf2e6;
  --accent-mint: #52c785;
  --funnel-1: #cdeadc;
  --funnel-2: #8fd6ae;
  --funnel-3: #52c785;
  --funnel-4: #1b4332;
  --funnel-lost: #b0b0bc;
  --danger: #d9534f;
  --overdue: #ffe2e2;
  --overdue-text: #a3231e;
  --today: #fff4d6;
  --today-text: #8a6300;
  --sidebar-bg: #ffffff;
  --sidebar-text: #6b7a71;
  --sidebar-text-active: #16241c;
  --radius: 16px;
  --shadow-card: 0 1px 2px rgba(22,36,28,0.04), 0 8px 24px -14px rgba(22,36,28,0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a14;
    --panel: #1a2a20;
    --border: #26362c;
    --text: #eaf2ec;
    --muted: #93a89b;
    --accent-soft: #1f3d2b;
    --accent-system-soft: #1f3d2b;
    --accent-mint: #67d99a;
    --funnel-1: #1f3d2b;
    --funnel-2: #2c6b48;
    --funnel-3: #3f9c69;
    --funnel-4: #67d99a;
    --funnel-lost: #55555f;
    --overdue: #3a1f1f;
    --overdue-text: #ff8f8a;
    --today: #3a331a;
    --today-text: #ffd873;
    --sidebar-bg: #14201a;
    --sidebar-text: #93a89b;
    --sidebar-text-active: #ffffff;
    --shadow-card: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px -14px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 360px;
}

.login-brand { justify-content: center; margin-bottom: 12px; }

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.login-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.login-box input {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.user-email-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* ---- sidebar ---- */

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 24px;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}

.nav-item:hover { background: var(--accent-system-soft); }

.nav-item.active {
  background: var(--accent-system-soft);
  border-left-color: var(--accent-mint);
  color: var(--accent-mint);
  font-weight: 600;
}

@media (prefers-color-scheme: light) {
  .nav-item.active { color: var(--accent-system); }
}

.nav-icon { font-size: 14px; width: 16px; text-align: center; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- content ---- */

.content {
  flex: 1;
  padding: 24px 32px 48px;
  min-width: 0;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.content-header h1 {
  font-size: 22px;
  margin: 0;
}

.page.hidden { display: none; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }

.btn.primary {
  background: var(--accent-system);
  border-color: var(--accent-system);
  color: white;
  font-weight: 600;
}

.btn.primary:hover { background: var(--accent-system-hover); }

.sidebar .btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--sidebar-text);
}

.sidebar .btn.ghost:hover { background: var(--accent-system-soft); }

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.file-btn { display: inline-flex; align-items: center; justify-content: center; }

/* ---- dashboard stat cards ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}

.stat-card-featured {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-hover) 100%);
  border-color: transparent;
  color: white;
}

.stat-card-featured .stat-label { color: rgba(255,255,255,0.75); }

.stat-value {
  font-size: 26px;
  font-weight: 700;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- pipeline funnel ---- */

.funnel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.funnel-row {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.funnel-stage-name { color: var(--muted); }

.funnel-bar-track {
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  height: 22px;
}

.funnel-bar-fill {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: white;
  font-size: 11px;
  font-weight: 600;
  min-width: 24px;
  transition: width 0.2s ease;
}

.funnel-value {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- line chart (revenue over time) ---- */

.line-chart-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}

.line-chart svg { width: 100%; height: auto; display: block; }
.line-chart-path { fill: none; stroke: var(--accent-system); stroke-width: 2; }
.line-chart-area { fill: var(--accent-system-soft); stroke: none; }
.line-chart-dot { fill: var(--accent-system); }

/* ---- generic list rows (dashboard + seguimientos page) ---- */

.list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  background: var(--bg);
}

.list-row.overdue { background: var(--overdue); color: var(--overdue-text); border-color: transparent; }
.list-row.today { background: var(--today); color: var(--today-text); border-color: transparent; }

.list-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0;
}

/* ---- formulario web page ---- */

.warning-box {
  background: var(--today);
  color: var(--today-text);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}

.warning-box code {
  background: rgba(0,0,0,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

#formConfigForm label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

#formConfigForm input {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.code-output {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.copy-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.copy-status {
  font-size: 13px;
  color: var(--accent-system);
}

/* ---- lead detail page ---- */

.detail-back { margin-bottom: 12px; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.detail-header h2 { margin: 0; font-size: 20px; }

#detailForm label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

#detailForm input, #detailForm select, #detailForm textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

/* ---- stage tabs (leads page) ---- */

.leads-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.stage-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.search-input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  min-width: 240px;
}

.stage-tab {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.stage-tab.active {
  background: var(--accent-system-soft);
  border-color: var(--accent-system);
  color: var(--accent-system);
  font-weight: 600;
}

/* ---- data table ---- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr:last-child td { border-bottom: none; }

#cfgLogoPreview {
  max-height: 56px;
  max-width: 180px;
}

.team-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
}

.stage-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-system-soft);
  color: var(--accent-system);
}

.followup-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.followup-pill.overdue { background: var(--overdue); color: var(--overdue-text); }
.followup-pill.today { background: var(--today); color: var(--today-text); }

.table-empty {
  padding: 24px 16px;
  color: var(--muted);
  text-align: center;
}

/* ---- modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 { margin-top: 0; font-size: 18px; }

.modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.modal label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.modal label.checkbox-label input { width: auto; }

.modal input, .modal select, .modal textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.activity-section {
  margin-bottom: 12px;
}

.activity-title {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.activity-log {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
}

.activity-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg);
}

.activity-date {
  color: var(--muted);
  flex-shrink: 0;
}

.activity-empty {
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 0;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.modal-actions-right {
  display: flex;
  gap: 8px;
}

.hidden { display: none !important; }

/* ---- planificador (tablero) ---- */

.board-filter {
  max-width: 220px;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.board-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
  min-height: 140px;
}

.board-column.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.board-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.board-column-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.board-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 8px;
}

.task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 9px;
  cursor: pointer;
}

.task-card:hover {
  border-color: var(--accent);
}

.task-card-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: 7px;
}

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.task-chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
}

.task-chip.area { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.task-chip.overdue { background: var(--overdue); border-color: transparent; color: var(--overdue-text); }

@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .panel-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .board { grid-template-columns: 1fr; }
}
