/* style.css - LRDLR (Lead Router for Dealers)
   Theme: a vegetable market. The sidebar is the stall-keeper's chalkboard,
   the page is banana-leaf green, dealers are "stalls" with price-tag
   pincode prefixes. One loud moment: the stall that lights up while you
   type a pincode. Everything else stays quiet. */

:root {
  --slate: #23312b;      /* chalkboard */
  --slate-2: #2e4038;
  --chalk: #f1efe4;      /* text on the board */
  --chalk-dim: #b9c2b4;
  --leaf-bg: #e7efdf;    /* page background, pale banana leaf */
  --paper: #ffffff;
  --ink: #1c2420;
  --muted: #5a675f;
  --line: #d3ddca;

  --turmeric: #eaa922;   /* primary action + live match */
  --turmeric-dark: #c78c0e;
  --turmeric-tint: #fdf2d6;
  --brinjal: #6a3a7a;    /* New */
  --mango: #b97606;      /* Contacted */
  --leaf: #2f7a3d;       /* Converted */
  --stone: #7b766a;      /* Lost */
  --chilli: #b83a26;     /* errors */

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Public Sans", "Segoe UI", system-ui, sans-serif;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--leaf-bg);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--turmeric);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }

/* ---------- Shell: chalkboard sidebar + page ---------- */

.shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr); /* minmax(0,…) stops the wide table stretching the page */
  min-height: 100vh;
}

.board {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 32px 24px;
  background: var(--slate);
  color: var(--chalk);
  border-right: 6px solid #8a6a3e; /* the wooden frame of the board */
}

.brand { text-decoration: none; color: var(--chalk); }

.brand-name {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 34px;
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand-sub {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--chalk-dim);
}

.board-nav { display: flex; flex-direction: column; gap: 4px; }

.board-nav a {
  color: var(--chalk-dim);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--r-sm);
}

.board-nav a:hover { color: var(--chalk); background: var(--slate-2); }

.board-nav a[aria-current="page"] {
  color: var(--chalk);
  background: var(--slate-2);
  box-shadow: inset 3px 0 0 var(--turmeric);
}

.board-note {
  margin: auto 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--chalk-dim);
}

/* ---------- Page ---------- */

.page {
  padding: 40px 48px 56px;
  max-width: 1120px;
  width: 100%;
}

.page-wide { max-width: 1280px; }

.page-head { margin-bottom: 28px; }

h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 40px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.page-head p { margin: 0; max-width: 62ch; }

h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  margin: 0 0 4px;
}

.section-title { font-size: 18px; margin: 0 0 14px; }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
}

/* ---------- New lead: form + stalls ---------- */

.lead-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 6px;
}

form > label:first-child { margin-top: 0; }

input,
select {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: #fbfcf8;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

input:hover, select:hover { border-color: #b7c5ab; }
input:focus, select:focus { border-color: var(--slate); background: #fff; }

#pincode {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.08em;
}

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

.error-text {
  color: var(--chilli);
  font-size: 13px;
  margin-top: 4px;
  min-height: 4px;
}

/* ---------- Smart paste (AI) ---------- */

.ai-paste {
  margin-bottom: 22px;
  padding: 16px;
  background: #f6f9f2;
  border: 1px dashed #b7c5ab;
  border-radius: var(--r-md);
}

.ai-paste label { margin-top: 0; }
.ai-paste .optional { font-weight: 400; font-size: 13px; margin-left: 4px; }

textarea {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  resize: vertical;
}

textarea:focus { border-color: var(--slate); outline: none; }
textarea:focus-visible { outline: 3px solid var(--turmeric); outline-offset: 2px; }

.ai-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 10px;
}

.ai-button {
  padding: 9px 18px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--chalk);
  background: var(--slate);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.ai-button:hover { background: var(--slate-2); }
.ai-button:disabled { opacity: 0.7; cursor: progress; }

.ai-status { flex: 1 1 220px; font-size: 13px; color: var(--muted); }
.ai-status.ok { color: var(--leaf); font-weight: 600; }
.ai-status.warn { color: var(--mango); font-weight: 600; }
.ai-status.error { color: var(--chilli); font-weight: 600; }

/* dashboard AI briefing */
.ai-summary { margin-bottom: 24px; border-style: dashed; border-color: #b7c5ab; background: #fbfdf8; }

.ai-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.ai-summary-head .section-title { margin: 0; }
.ai-summary-text { margin: 0; max-width: 75ch; font-size: 15px; line-height: 1.6; }
.ai-summary-text.error { color: var(--chilli); font-weight: 600; }

/* a box the AI filled, until the person edits it */
input.ai-filled,
select.ai-filled {
  background: var(--turmeric-tint);
  border-color: var(--turmeric);
}

/* the little chalk strip under the pincode box */
.route-preview {
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--muted);
  background: #f2f5ee;
  border: 1px dashed var(--line);
}

.route-preview.is-set {
  color: var(--chalk);
  background: var(--slate);
  border: 1px solid var(--slate);
  font-weight: 600;
}

button.primary {
  margin-top: 26px;
  width: 100%;
  padding: 14px 20px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  background: var(--turmeric);
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
}

button.primary:hover { background: var(--turmeric-dark); }
button.primary:disabled { background: #efd9a4; color: var(--muted); cursor: not-allowed; }

#form-status { margin-top: 14px; font-size: 14px; font-weight: 600; }
#form-status:not(:empty) { padding: 12px 14px; border-radius: var(--r-md); }
#form-status.success { color: #1f5a2a; background: #e3f1df; border: 1px solid #bcdcb4; }
#form-status.error { color: var(--chilli); background: #fbe9e5; border: 1px solid #efc3ba; }

/* dealer stalls */
.stalls {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.stall {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}

.stall-emoji {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 24px;
  background: var(--leaf-bg);
  border-radius: 50%;
}

.stall-name { font-weight: 600; line-height: 1.25; }

.stall-city {
  display: block;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

.stall-tags { display: flex; gap: 6px; }

/* "Try 560034" - fills the pincode box with a real example */
.try-pin {
  padding: 0 2px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--leaf);
  background: none;
  border: none;
  border-bottom: 1px dashed currentColor;
  cursor: pointer;
}

.try-pin:hover { color: var(--slate); }
.stall.is-match .try-pin { color: var(--ink); }

/* price-tag shape: notched left edge with a punched hole */
.tag {
  position: relative;
  padding: 3px 9px 3px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: #f4ead2;
  clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%);
}

.tag::before {
  content: "";
  position: absolute;
  left: 7px; top: 50%;
  width: 4px; height: 4px;
  margin-top: -2px;
  border-radius: 50%;
  background: var(--paper);
}

.tag-any { font-weight: 500; color: var(--muted); }

.stall.is-match {
  background: var(--turmeric-tint);
  border-color: var(--turmeric);
}

.stall.is-match .stall-emoji { background: var(--turmeric); animation: pop 0.35s ease-out; }
.stall.is-match .tag { background: var(--turmeric); }

@keyframes pop {
  0% { transform: scale(0.8); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------- Dashboard ---------- */

/* status as one ledger strip, not five separate cards */
.status-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  margin-bottom: 24px;
  overflow: hidden;
}

.status-tile {
  padding: 18px 22px;
  border-left: 1px solid var(--line);
}

.status-tile:first-child { border-left: none; }

.status-tile .num {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 38px;
  line-height: 1;
}

.status-tile .label {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.status-tile.status-new .num { color: var(--brinjal); }
.status-tile.status-contacted .num { color: var(--mango); }
.status-tile.status-converted .num { color: var(--leaf); }
.status-tile.status-lost .num { color: var(--stone); }
.status-tile.status-repeat { background: #f6f9f2; }

.page-wide .panel + .panel { margin-top: 24px; }

.dealer-bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.dealer-bar {
  display: grid;
  grid-template-columns: 230px 1fr 36px;
  align-items: center;
  gap: 14px;
}

.dealer-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar-track {
  height: 12px;
  background: #eef2e9;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  background: var(--leaf);
  border-radius: 999px;
}

.dealer-count {
  text-align: right;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}

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

.table-head .section-title { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; }
.filters select { width: auto; min-width: 170px; }

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

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

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: #f4f7f0;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafcf7; }

.cell-name { font-weight: 600; }

/* product names are the longest column; let them wrap so Status fits */
#leads-table td:nth-child(4) { white-space: normal; min-width: 130px; }

.repeat-badge {
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #7a4f00;
  background: var(--turmeric-tint);
  border: 1px solid #f0d58f;
  border-radius: 999px;
}

/* status dropdown as a coloured pill */
.status-select {
  width: auto;
  min-width: 118px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
}

.status-select.status-new { color: var(--brinjal); background: #f1e9f4; border-color: #dccbe3; }
.status-select.status-contacted { color: var(--mango); background: #fcf1dc; border-color: #f0d9a8; }
.status-select.status-converted { color: var(--leaf); background: #e5f2e3; border-color: #bcdcb4; }
.status-select.status-lost { color: var(--stone); background: #f0eee9; border-color: #dbd7cd; }

/* ---------- Import CSV ---------- */

.pick-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px 28px;
  margin-bottom: 24px;
}

.file-button {
  display: inline-block;
  margin: 0;
  padding: 14px 26px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--chalk);
  background: var(--slate);
  border-radius: var(--r-md);
  cursor: pointer;
}

.file-button:hover { background: var(--slate-2); }

/* the real <input type=file> is hidden; show its focus on the label */
.pick-panel:has(#csv-file:focus-visible) .file-button { outline: 3px solid var(--turmeric); outline-offset: 2px; }

.pick-help { flex: 1 1 320px; }
.pick-help p { margin: 0 0 4px; max-width: 70ch; }
.pick-help a { color: var(--leaf); font-weight: 600; }
.pick-panel .error-text { flex-basis: 100%; }
.pick-panel .error-text:empty { display: none; }

.file-name { font-family: var(--font-body); font-weight: 400; font-size: 15px; }

.summary { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 4px 12px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 999px;
}

.chip-ready, .result-ready { color: var(--leaf); background: #e5f2e3; }
.chip-fixed, .result-fixed { color: var(--mango); background: #fcf1dc; }
.chip-repeat, .result-repeat { color: var(--brinjal); background: #f1e9f4; }
.chip-rejected, .result-rejected { color: var(--chilli); background: #fbe9e5; }

.result {
  display: inline-block;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
}

.result-reason {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  white-space: normal;
  max-width: 260px;
}

#preview-table td:last-child { white-space: normal; min-width: 230px; }
/* let the long text columns wrap so the Result column (with AI buttons) fits */
#preview-table td:nth-child(5),
#preview-table td:nth-child(6),
#preview-table td:nth-child(7) { white-space: normal; min-width: 110px; }

/* AI fix inside the Result cell */
.ai-mini {
  margin-top: 6px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--chalk);
  background: var(--slate);
  border: 1px solid var(--slate);
  border-radius: 999px;
  cursor: pointer;
}

.ai-mini:hover { background: var(--slate-2); }
.ai-mini.ghost { color: var(--ink); background: transparent; border-color: var(--line); }
.ai-mini.ghost:hover { background: #f4f7f0; }

.ai-note {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink);
  max-width: 260px;
}

.ai-note.error { color: var(--chilli); display: inline; }
.ai-choice { display: flex; gap: 6px; flex-wrap: wrap; }
.row-rejected td { color: var(--muted); }
.row-rejected .cell-name { text-decoration: line-through; text-decoration-color: #d9b2aa; }

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.import-actions button.primary { width: auto; margin-top: 0; padding: 14px 28px; }

button.secondary {
  padding: 14px 24px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
}

button.secondary:hover { background: #f4f7f0; }
button.secondary:disabled { color: var(--muted); cursor: not-allowed; }

#form-status a { color: inherit; font-weight: 700; }

/* ---------- Small screens: board becomes a top bar ---------- */

@media (max-width: 960px) {
  .lead-layout { grid-template-columns: 1fr; }
  .status-row { grid-template-columns: repeat(3, 1fr); }
  .status-tile:nth-child(4) { border-left: none; }
  .status-tile:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .dealer-bar { grid-template-columns: 170px 1fr 32px; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .filters select { min-width: 0; flex: 1 1 140px; }

  .board {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-right: none;
    border-bottom: 6px solid #8a6a3e;
  }

  .brand-name { font-size: 26px; }
  .board-nav { flex-direction: row; }
  .board-note { display: none; }

  .page { padding: 24px 16px 40px; }
  h1 { font-size: 32px; }
  .panel { padding: 20px; }
  .two-col { grid-template-columns: 1fr; gap: 0; }
  .status-row { grid-template-columns: repeat(2, 1fr); }
  .status-tile { border-left: none; border-top: 1px solid var(--line); }
  .status-tile:nth-child(-n + 2) { border-top: none; }
  .status-tile:nth-child(even) { border-left: 1px solid var(--line); }
  .status-tile.status-repeat { grid-column: 1 / -1; }
  .dealer-bar { grid-template-columns: 1fr 32px; }
  .dealer-bar .bar-track { grid-column: 1 / -1; grid-row: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .stall, .stall.is-match .stall-emoji { transition: none; animation: none; }
}
