:root {
  /* Enerlink brand palette */
  --brand: #2746c7;          /* Enerlink cobalt */
  --brand-dark: #1d3299;     /* hover / pressed */
  --brand-50: #eef1fc;       /* light tint surfaces */
  --brand-100: #dbe2f8;      /* tint borders */

  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --text: #0f1729;           /* near-black, matches wordmark */
  --muted: #6b7280;
  --line: #e6e8ef;
  --accent: var(--brand);
  --accent-dark: var(--brand-dark);
  --danger: #c0362c;
  --warning: #b45309;
  --ok: #15803d;
  --shadow: 0 8px 30px rgba(16, 29, 71, .08);
  --radius: 14px;
  --radius-sm: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

/* Sidebar — clean white, mirrors the logo lockup (blue mark + black wordmark) */
.sidebar { background: var(--panel); color: var(--text); padding: 22px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.brand-logo { width: 100%; max-width: 200px; height: auto; display: block; }
.brand-fallback { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 44px; color: var(--brand); display: grid; place-items: center; }
.brand-mark svg { width: 40px; height: 40px; display: block; }
.brand-word { font-size: 22px; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.brand-sub { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: .04em; padding-left: 2px; }
.hidden { display: none !important; }
.nav { display: grid; gap: 4px; }
.nav button { border: 0; color: #4b5563; text-align: left; background: transparent; padding: 11px 12px; border-radius: 10px; display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.nav button:hover { background: var(--brand-50); color: var(--brand); }
.nav button.active { background: var(--brand); color: #fff; }
.nav .count { background: var(--brand-50); color: var(--brand); padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.nav button:hover .count { background: #fff; }
.nav button.active .count { background: rgba(255,255,255,.22); color: #fff; }
.sidebar-footer { margin-top: auto; display: grid; gap: 8px; }
.main { min-width: 0; }
.topbar { background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 20px 28px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 25px; letter-spacing: -.01em; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.top-actions { display: flex; gap: 10px; }
.view { padding: 24px 28px 60px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { margin: 0 0 12px; font-size: 17px; }
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.metric { padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 31px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }
.metric .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
button.primary, button.secondary, button.ghost, button.danger { border-radius: 10px; padding: 10px 13px; border: 1px solid transparent; font-weight: 650; }
button.primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(39,70,199,.25); }
button.primary:hover { background: var(--brand-dark); }
button.secondary { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); }
button.secondary:hover { background: var(--brand-100); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); }
button.danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
button.small { padding: 7px 10px; font-size: 13px; }
.icon-btn { border: 0; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { min-width: 180px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 9px; padding: 9px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(39,70,199,.15); }
textarea { min-height: 96px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; font-weight: 650; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
th { background: var(--panel-2); color: #374151; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
tr:hover td { background: var(--brand-50); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warning); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.info { background: var(--brand-50); color: var(--brand); }
.badge.dark { background: var(--text); color: #fff; }
.muted { color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px; font-size: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.timeline { display: grid; gap: 10px; }
.timeline-item { border-left: 3px solid var(--brand-100); padding-left: 12px; }
.timeline-item strong { display: block; }
.timeline-item small { color: var(--muted); }
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.pipe-stage { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-height: 90px; }
.pipe-stage h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.pipe-stage .num { font-size: 24px; font-weight: 800; color: var(--brand); }
.pipe-stage .mw { color: var(--muted); font-size: 12px; }
.empty-state { border: 1px dashed var(--brand-100); border-radius: var(--radius); padding: 36px; text-align: center; color: var(--muted); background: var(--brand-50); }
.empty-state h3 { margin: 0 0 6px; color: var(--text); }
.modal { width: min(1120px, calc(100vw - 32px)); max-height: 92vh; border: 0; border-radius: var(--radius); padding: 0; box-shadow: 0 25px 80px rgba(16,29,71,.30); overflow: hidden; }
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
#modalBody { padding: 18px; max-height: calc(92vh - 65px); overflow-y: auto; overflow-x: hidden; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.split > *, .form-grid > *, .card, .table-wrap { min-width: 0; }
.modal .card { box-shadow: none; }
.modal-section { margin-top: 14px; }
.modal-actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.compact-table table { min-width: 620px; }
.callout { background: var(--brand-50); border: 1px solid var(--brand-100); color: var(--brand-dark); padding: 12px; border-radius: 12px; }
.warning-box { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; padding: 12px; border-radius: 12px; }
.codebox { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; background: var(--text); color: #e5e7eb; padding: 12px; border-radius: 10px; white-space: pre-wrap; overflow: auto; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .split, .form-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 12px; }
}

@media (max-width: 760px) {
  .modal { width: calc(100vw - 16px); max-height: 96vh; }
  #modalBody { max-height: calc(96vh - 64px); padding: 12px; }
  .modal .form-grid { grid-template-columns: 1fr; }
  .modal-head { padding: 12px 14px; }
}

/* ── Login screen ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  width: 360px;
  max-width: calc(100vw - 32px);
}
.login-logo {
  width: 200px;
  height: auto;
  display: block;
  margin: 0 auto 2px;
}
.login-brand-fallback { text-align: center; margin-bottom: 2px; }
.login-brand-word { font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
.login-subtitle { text-align: center; color: var(--muted); font-size: 13px; letter-spacing: .04em; margin: 0 0 22px; }
.login-card .field label { font-size: 12px; font-weight: 650; color: var(--muted); display: block; margin-bottom: 5px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; background: #fee2e2; border-radius: 8px; padding: 8px 10px; text-align: center; }

/* ── Signed-in user chip ─────────────────────────────────────────────────── */
.user-chip { font-size: 11px; color: var(--muted); padding: 4px 2px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all; line-height: 1.4; }

/* v1.4 sortable table headers */
.sort-th {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font: inherit;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  cursor: pointer;
}
.sort-th:hover { color: var(--brand); }
.sort-th.active { color: var(--brand); }
.sort-indicator { font-size: 11px; opacity: .65; }
.sort-th.active .sort-indicator { opacity: 1; }

/* Contact-the-lead action chips (WhatsApp / Viber / Telegram / Call / Email).
   Platform colors are intentional brand cues and kept as-is. */
.contact-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
a.icon-action {
  display: inline-flex; align-items: center; text-decoration: none;
  border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--line); background: #fff; color: #374151; line-height: 1; white-space: nowrap;
}
a.icon-action.small { padding: 5px 8px; font-size: 11px; }
a.icon-action:hover { filter: brightness(.97); transform: translateY(-1px); }
a.icon-action[title="WhatsApp"] { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
a.icon-action[title="Viber"]    { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }
a.icon-action[title="Telegram"] { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
a.icon-action[title="Call"]     { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); }
.icon-action[title="SMS"]       { background: #fef9c3; color: #854d0e; border-color: #fde68a; }

/* Leads: tidy 2-column action grid (Email/WhatsApp/Viber/Telegram/Call/SMS + Open) */
.lead-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; min-width: 188px; }
.lead-actions .icon-action { width: 100%; justify-content: center; box-sizing: border-box; }
.lead-actions button.icon-action {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 8px;
  padding: 5px 8px; font-size: 11px; font-weight: 700; border: 1px solid var(--line);
  background: #fff; color: #374151; line-height: 1; white-space: nowrap; cursor: pointer;
}
.lead-actions button.icon-action:hover { filter: brightness(.97); transform: translateY(-1px); }
.lead-actions .icon-action.chip-email { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); }
.lead-actions .icon-action.chip-open  { grid-column: 1 / -1; }

/* Notifications bell + red badge + dropdown */
.notif-wrap { position: relative; display: inline-flex; }
.notif-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: #374151; cursor: pointer; }
.notif-btn:hover { background: var(--bg); color: var(--brand); }
.notif-badge { position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: #dc2626; color: #fff; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px #fff; }
.notif-panel { position: absolute; top: 48px; right: 0; width: 348px; max-width: 86vw; max-height: 70vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 60; padding: 8px; }
.notif-head { font-weight: 800; font-size: 13px; padding: 8px 10px; color: var(--text); border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.notif-empty { padding: 18px 10px; color: var(--muted); font-size: 13px; text-align: center; }
.notif-item { padding: 9px 10px; border-radius: 8px; border-bottom: 1px solid var(--line); }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--bg); }
.notif-title { font-weight: 700; font-size: 13px; color: var(--text); }
.notif-sub { font-size: 12px; color: #b45309; margin: 2px 0 7px; }
.notif-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.notif-modal-list { max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; }

/* Escalating offer-reminder pills (1st orange · 2nd red · 3rd+ purple) */
.rem-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; margin-top: 5px; }
.rem-pill.lvl-1 { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.rem-pill.lvl-2 { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.rem-pill.lvl-3 { background: #f3e8ff; color: #6b21a8; border: 1px solid #e9d5ff; }
.notif-title .rem-pill { margin-top: 0; margin-left: 4px; vertical-align: middle; }
.notif-item.lvl-1 { border-left: 3px solid #f59e0b; }
.notif-item.lvl-2 { border-left: 3px solid #dc2626; }
.notif-item.lvl-3 { border-left: 3px solid #7c3aed; }
.notif-filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 6px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.notif-filters button { padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 11px; font-weight: 800; cursor: pointer; color: #374151; }
.notif-filters button.active { outline: 2px solid var(--brand); outline-offset: 1px; }
.notif-filters .lvl-1 { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.notif-filters .lvl-2 { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.notif-filters .lvl-3 { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }
.rem-pill.lvl-revise { background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe; }
.notif-item.lvl-revise { border-left: 3px solid #4f46e5; }
.notif-filters .lvl-revise { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }

/* Row selection checkboxes + bulk-action bar */
.sel-col { width: 34px; text-align: center; padding-left: 8px; padding-right: 4px; }
.sel-col input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); }
.sel-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; padding: 9px 14px; background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: 10px; }
.sel-bar .sel-count { font-weight: 800; color: var(--brand); font-size: 13px; }
.sel-bar .bulk-stage { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 12px; font-weight: 650; background: #fff; cursor: pointer; }

/* Clickable pipeline boxes + stage drill-down popup */
.pipe-stage.clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
.pipe-stage.clickable:hover { border-color: var(--brand); box-shadow: var(--shadow); transform: translateY(-1px); }
.stage-modal-list { max-height: 62vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.stage-modal-list table { width: 100%; border-collapse: collapse; }
.stage-modal-list td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.stage-modal-list tr:last-child td { border-bottom: 0; }

/* Leads: fixed column widths (set via <colgroup>) so the layout stays neat */
.leads-table { table-layout: fixed; width: 100%; }
.leads-table td { white-space: normal; word-break: break-word; vertical-align: top; }
.leads-table th { white-space: nowrap; word-break: normal; vertical-align: middle; }
.lead-company-cell strong { font-size: 13px; }
.lead-pv-cell { font-size: 12px; line-height: 1.5; color: var(--text); }
.lead-contact-cell { font-size: 12px; }
.lead-contact-cell .muted { word-break: break-all; }

/* Inline next-follow-up date picker */
.followup-input { width: 100%; max-width: 140px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); font-size: 11px; background: #fff; cursor: pointer; }
.cell-followup { margin-top: 5px; display: flex; flex-direction: column; gap: 2px; max-width: 150px; }
.cell-sub-lbl { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* Quick call-note under the stage */
.cell-comment { margin-top: 5px; display: flex; flex-direction: column; gap: 2px; max-width: 180px; }
.cell-comment .comment-text { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comment-btn { align-self: flex-start; background: none; border: none; padding: 0; color: var(--brand); font-size: 11px; font-weight: 700; cursor: pointer; }
.comment-btn:hover { text-decoration: underline; }

/* Inline lead Owner / "contacted by" dropdown */
.owner-select { width: 100%; max-width: 120px; padding: 5px 7px; border-radius: 8px; border: 1px solid var(--line); font-size: 12px; font-weight: 650; background: #fff; cursor: pointer; }

/* Inline editable lead-stage dropdown */
.lead-stage-select {
  width: 100%; max-width: 150px; padding: 5px 7px; border-radius: 8px;
  border: 1px solid var(--line); font-size: 12px; font-weight: 650; background: #fff; cursor: pointer;
}
.lead-stage-select.stage-won       { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.lead-stage-select.stage-lost      { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.lead-stage-select.stage-hotlead   { background: #ffe4e6; color: #be123c; border-color: #fecdd3; font-weight: 800; }
.lead-stage-select.stage-offersent { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.lead-stage-select.stage-sendrevisedoffer { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }

/* Email template picker popup */
.picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.picker-grid button { width: 100%; text-align: left; }
@media (max-width: 760px) { .picker-grid { grid-template-columns: 1fr; } }
