@font-face {
  font-family: 'Talent FS';
  src: url('fonts/Talent_FS-Regular.woff2') format('woff2'), url('fonts/Talent_FS-Regular.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Talent FS';
  src: url('fonts/Talent_FS-Bold.woff2') format('woff2'), url('fonts/Talent_FS-Bold.woff') format('woff');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #1e1b18;
  --muted: #756e65;
  --line: #e4ded3;
  --alert: #b5391b;
  --alert-bg: #fde9e2;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Talent FS', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
#app {
  max-width: 1560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(48px + env(safe-area-inset-bottom));
}

h1, h2, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 15px; margin-bottom: 12px; }
h2 small { font-weight: 400; color: var(--muted); margin-inline-start: 6px; }
.muted { color: var(--muted); font-size: 14px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* כפתורים */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 700; }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.danger { color: var(--alert); }
.link { background: none; border: 0; padding: 8px 0; text-decoration: underline; cursor: pointer; font-size: 14px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* שדות */
input:not([type=radio]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
textarea { resize: vertical; line-height: 1.6; display: block; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 700; }
.field > * { font-weight: 400; font-size: 16px; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field.inline input { width: auto; }

/* ראש העמוד */
.top, .lead-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.demo { background: #fcf0d9; color: #7a4f06; border-radius: 10px; padding: 8px 14px; font-size: 14px; margin-bottom: 16px; }
.back { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--ink); }

/* חיפוש וסינון */
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px; }
.tools #q { flex: 1 1 100%; }
.tools select, .tools input[type=date] { width: auto; flex: 1 1 130px; font-size: 14px; }
.day-filter { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; font-size: 14px; color: var(--muted); white-space: nowrap; }

/* לוח: קבוצות וטבלה */
.group { margin-bottom: 22px; }
.group-head {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 4px;
  background: none; border: 0; cursor: pointer; color: var(--g); font-size: 18px;
}
.group-head .caret { width: 14px; font-size: 13px; }
.group-head .count { color: var(--muted); font-size: 14px; }
.table-wrap { overflow-x: auto; }
.table {
  background: var(--card); border: 1px solid var(--line); border-inline-start: 5px solid var(--g);
  border-radius: 10px; overflow: hidden;
}
.trow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.thead { display: none; }
.c { min-width: 0; display: flex; align-items: center; }
.c-name { grid-column: 1 / -1; flex-direction: column; align-items: flex-start; }
.c-name a { font-weight: 700; font-size: 17px; text-decoration: none; }
.c-name a:hover { text-decoration: underline; }
.c-date { font-weight: 700; font-size: 15px; }
.c-field input.cell-input { font-weight: 700; font-size: 15px; }
.c-fu input.cell-input:not(.due) { background: transparent; color: var(--muted); font-size: 13px; }
.lead-field { font-weight: 700; font-size: 18px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.c-phone { gap: 10px; font-size: 14px; }
.c-phone a { color: inherit; }
.c-phone .wa { color: #17863f; }
.c-note { grid-column: 1 / -1; }

/* תאים לעריכה מהירה */
.cell-select {
  width: 100%; min-height: 40px; padding: 0 8px; border: 0; border-radius: 6px;
  background: var(--solid, #e9e5de); color: #fff; font-weight: 700; font-size: 14px;
  text-align: center; text-align-last: center; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.cell-select:hover { filter: brightness(1.08); }
.cell-select option { background: #fff; color: var(--ink); font-weight: 400; }
.cell-select[data-q=''] { color: var(--muted); font-weight: 400; }
[data-s='new'] { --solid: #2a6fd0; }
[data-s='call_scheduled'] { --solid: #8a4fd0; }
[data-s='zoom_scheduled'] { --solid: #0e7fa8; }
[data-s='quote_sent'] { --solid: #b86200; }
[data-s='followup_done'] { --solid: #0f8a7a; }
[data-s='paid'] { --solid: #17863f; }
[data-s='lost'] { --solid: #7d828a; }
[data-src='landing'] { --solid: #0e7fa8; }
[data-src='instagram'] { --solid: #b72f7b; }
[data-src='facebook'] { --solid: #2a6fd0; }
[data-src='word_of_mouth'] { --solid: #0f8a7a; }
[data-src='campaign'] { --solid: #b86200; }
.cell-select[data-src='manual'], .cell-select[data-src=''] { color: var(--muted); font-weight: 400; }
[data-t='paid'] { --solid: #b86200; }
[data-t='organic'] { --solid: #17863f; }
.cell-select[data-t=''] { color: var(--muted); font-weight: 400; }
[data-q='hot'] { --solid: #d83a52; }
[data-q='cold'] { --solid: #4a5bd4; }
[data-q='bad'] { --solid: #7d828a; }

input.cell-input { min-height: 40px; padding: 6px 10px; border-color: transparent; background: var(--bg); border-radius: 6px; font-size: 14px; }
input.cell-input:hover { border-color: var(--line); }
input.cell-input.due { background: var(--alert-bg); color: var(--alert); font-weight: 700; }

.quick-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; padding: 10px 12px; background: #fbfaf7; }
.quick-add input { min-height: 40px; }
.quick-add .btn { min-height: 40px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* עמוד ליד */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card-due { border-color: var(--alert); }
.lead-grid, .col { display: grid; gap: 12px; align-content: start; min-width: 0; }
.contact { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
blockquote { margin: 14px 0 0; padding: 10px 14px; background: var(--bg); border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }

.fields { display: grid; gap: 12px; }
.frow { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 12px; font-weight: 700; font-size: 14px; }
.fields .muted .link { padding: 0; color: inherit; }

details.card > summary { cursor: pointer; font-weight: 700; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary small { font-weight: 400; color: var(--muted); }
details.card[open] > summary { margin-bottom: 14px; }

#note-form { display: grid; gap: 12px; justify-items: start; }
#note-form textarea { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 999px; font-size: 14px; }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

#notes { display: grid; gap: 10px; }
.notes-title { margin: 8px 4px 0; }
.note header { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.note header b { color: var(--ink); }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.note-body.clamp { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }

/* טפסים */
.form { display: grid; gap: 14px; max-width: 520px; margin: 0 auto; }
.form .btn { margin-top: 6px; }
.auth { margin-top: 12vh; max-width: 380px; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0 16px; }

#toast {
  position: fixed; inset-inline: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); margin: 0 auto; width: fit-content; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px;
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: none; }

@media (min-width: 760px) {
  #app { padding: 32px 24px 64px; }
  h1 { font-size: 30px; }
  .tools #q { flex: 1 1 240px; }
  .table { min-width: 1500px; }
  .trow { grid-template-columns: minmax(140px, 1.2fr) 78px minmax(130px, 1fr) 165px 105px 110px 110px minmax(110px, 0.9fr) 132px 175px minmax(130px, 1fr); gap: 6px; padding: 6px 12px; align-items: center; }
  .thead { display: grid; color: var(--muted); font-size: 13px; padding-block: 8px; }
  .thead > div:not(:first-child) { text-align: center; }
  .c-name, .c-note { grid-column: auto; }
  .quick-add { grid-template-columns: minmax(170px, 320px) 180px auto; justify-content: start; }
  .lead-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* טקסט ארוך לא שובר את הפריסה */
.col > *, .card { min-width: 0; }
h1, .c-name a, .lead-field, .muted { overflow-wrap: anywhere; }
.contact .btn { max-width: 100%; white-space: normal; text-align: center; padding-block: 8px; }
.cell-select:focus-visible, input.cell-input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.group-head:disabled { cursor: default; }
.empty .link { padding: 0 4px; }

/* יעדי מגע בטלפון */
@media (max-width: 759px) {
  .cell-select, input.cell-input, .quick-add input, .quick-add .btn { min-height: 44px; }
  .c-phone a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 6px; white-space: nowrap; }
  .link, details.card > summary { min-height: 44px; display: inline-flex; align-items: center; }
  .seg span { min-height: 44px; }
  .top h1 { white-space: nowrap; font-size: 22px; }
}

/* היררכיה: רק הסטטוס צבוע מלא. איכות, מקור וממומן/אורגני הם תגיות שקטות */
.cell-select:not([data-s]) {
  background: var(--bg); color: var(--solid, var(--muted)); font-size: 13px; min-height: 34px;
}
.cell-select:not([data-s]):hover { filter: none; background: var(--line); }
.c-field input.cell-input { font-weight: 400; font-size: 14px; }

@media (min-width: 760px) {
  .trow { padding-block: 10px; }
}

/* טלפון: כל ליד הוא כרטיס נפרד. שם, תאריך וסטטוס בראש, כל השאר קטן מתחת */
@media (max-width: 759px) {
  .table { display: grid; gap: 14px; background: none; border: 0; border-radius: 0; overflow: visible; }
  .trow {
    grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 16px 14px;
    background: var(--card); border: 1px solid var(--line); border-inline-start: 5px solid var(--g); border-radius: 12px;
  }
  .trow:last-child { border-bottom: 1px solid var(--line); }
  .c-name { grid-column: span 4; }
  .c-name a { font-size: 19px; }
  .c-date { grid-column: span 2; justify-content: flex-end; font-size: 15px; }
  .c-status { grid-column: 1 / -1; margin-block: 2px 4px; }
  .c-field, .c-ad, .c-note { grid-column: 1 / -1; }
  .c-quality, .c-source, .c-traffic { grid-column: span 2; }
  .c-fu, .c-phone { grid-column: span 3; }
  .c-phone { justify-content: flex-end; font-size: 13px; }
  .cell-select:not([data-s]) { min-height: 36px; }
  .trow input.cell-input { min-height: 36px; padding: 4px 8px; background: transparent; font-size: 13px; color: var(--muted); }
  .trow input.cell-input:focus { background: var(--bg); color: var(--ink); }
  .trow .c-field input.cell-input { padding-inline: 0; font-size: 14px; color: var(--ink); min-height: 28px; }
  .trow input.cell-input.due { background: var(--alert-bg); color: var(--alert); }
  .quick-add { border: 1px dashed var(--line); border-radius: 12px; background: var(--card); }
  .group { margin-bottom: 30px; }
}

/* שורת ליד מקופלת (טלפון בלבד): לחיצה פותחת הצצה, והעיפרון מאפשר עריכה */
.summary, .row-tools { display: none; }
.s-status { background: var(--solid); color: #fff; font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }

@media (max-width: 759px) {
  .table { gap: 8px; }
  .trow { padding: 0; gap: 0 8px; overflow: hidden; }
  .summary {
    grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px;
    width: 100%; min-height: 56px; padding: 8px 12px; background: none; border: 0; text-align: start; cursor: pointer;
  }
  .s-main, .s-side { display: grid; gap: 2px; min-width: 0; }
  .s-main b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .s-main small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .s-side { justify-items: end; flex: none; }
  .s-side small { font-weight: 700; font-size: 13px; }

  .trow > .c { display: none; }
  .trow.open { padding: 0 12px 14px; gap: 8px; }
  .trow.open .summary { width: auto; margin-inline: -12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
  .trow.open .s-status { display: none; }
  .trow.open > .c { display: flex; }
  .trow.open > .c-name, .trow.open > .c-date { display: none; }
  .trow.open .row-tools { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; }
  .row-tools .btn { min-height: 40px; flex: 1; }

  /* במצב הצצה השדות לקריאה בלבד */
  .trow.open:not(.editing) select, .trow.open:not(.editing) input { pointer-events: none; }
  .trow.editing input.cell-input { background: var(--bg); color: var(--ink); }
  .trow.editing { border-color: var(--ink); }
}
