/* ==========================================================================
   LH Sales Toolkit — Components
   Every class here is used by at least one page. Keep it that way.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}

.card--flush { padding: 0; overflow: hidden; }
.card--quiet { background: var(--surface-2); box-shadow: none; }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 14px;
  font-size: var(--fs-13);
  font-weight: 600;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.card__body { padding: 14px; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 18px;
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: background var(--t-fast), border-color var(--t-fast),
    transform var(--t-fast), opacity var(--t-fast);
}

.btn:active { transform: scale(.985); }
.btn svg { width: 18px; height: 18px; }

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  color: var(--primary-ink);
  background: var(--primary);
  border-color: var(--primary);
}
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn--accent {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

/* Call is the single most important P1 action — give it the loudest treatment. */
.btn--call {
  color: var(--text-on-dark);
  background: var(--ok-strong);
  border-color: var(--ok-strong);
}
.btn--call:hover:not(:disabled) {
  background: var(--ok-hover);
  border-color: var(--ok-hover);
}

/* LINE green: only for actions that really are LINE's. */
.btn--line {
  color: var(--text-on-dark);
  background: var(--line-green-fill);
  border-color: var(--line-green-fill);
}
.btn--line:hover:not(:disabled) {
  background: var(--line-green-fill-hover);
  border-color: var(--line-green-fill-hover);
}

.btn--ghost { background: transparent; border-color: var(--border-strong); }
.btn--danger { color: var(--danger-ink); border-color: var(--border-danger); background: var(--danger-soft); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: var(--fs-15); }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: var(--fs-12); border-radius: var(--r-sm); }

.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1 1 0; }

/* --------------------------------------------------------------------------
   Chips / badges
   -------------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--fs-11);
  font-weight: 700;
  white-space: nowrap;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-2);
}

.chip--a { color: var(--grade-a); background: var(--grade-a-soft); }
.chip--b { color: var(--grade-b); background: var(--grade-b-soft); }
.chip--c { color: var(--grade-c); background: var(--grade-c-soft); }
.chip--ok { color: var(--ok-ink); background: var(--ok-soft); }
.chip--warn { color: var(--warn-ink); background: var(--warn-soft); }
.chip--danger { color: var(--danger-ink); background: var(--danger-soft); }
.chip--info { color: var(--info); background: var(--info-soft); }
.chip--accent { color: var(--gold-ink); background: var(--accent-soft); }
.chip--plain { font-weight: 500; color: var(--text-2); background: var(--surface-3); }

/* --------------------------------------------------------------------------
   Avatar
   -------------------------------------------------------------------------- */

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  font-size: var(--fs-15);
  font-weight: 700;
  color: var(--primary-ink);
  background: var(--lh-navy-500);
  border-radius: var(--r-pill);
}

.avatar--lg { width: 52px; height: 52px; font-size: var(--fs-20); }
.avatar--a { background: var(--grade-a); }
.avatar--b { background: var(--grade-b); }
.avatar--c { background: var(--grade-c); }

/* --------------------------------------------------------------------------
   Lead row — the workhorse of every list screen
   -------------------------------------------------------------------------- */

.lead-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  overflow: hidden;
}

.pv-desktop .grid-2 .lead-list { border-radius: var(--r-lg); }

.lead {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}

.lead:last-child { border-bottom: 0; }
.lead:hover { background: var(--surface-2); }
.lead:active { background: var(--surface-3); }
.lead.is-disabled { opacity: .45; cursor: default; }
.lead.is-disabled:hover { background: transparent; }

.lead__body { flex: 1 1 auto; min-width: 0; }

.lead__name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
}

.lead__meta {
  display: block;
  margin-top: 1px;
  font-size: var(--fs-12);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead__note {
  display: block;
  margin-top: 3px;
  font-size: var(--fs-11);
  color: var(--text-3);
}

.lead__side {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.lead__chev { flex: 0 0 auto; color: var(--text-3); }

/* --------------------------------------------------------------------------
   SLA meter
   -------------------------------------------------------------------------- */

.sla {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: var(--fs-12);
  font-weight: 600;
  border-radius: var(--r-md);
  background: var(--info-soft);
  color: var(--info-ink);
}

.sla--warn { background: var(--warn-soft); color: var(--warn-ink); }
.sla--danger { background: var(--danger-soft); color: var(--danger-ink); }
.sla__bar {
  flex: 1 1 auto;
  height: 5px;
  background: rgba(14, 27, 42, .1);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.sla__fill { height: 100%; background: currentColor; border-radius: var(--r-pill); }

/* --------------------------------------------------------------------------
   Definition rows (lead detail, settings)
   -------------------------------------------------------------------------- */

.dl { display: grid; grid-template-columns: 104px 1fr; gap: 6px 12px; }
.dl dt { font-size: var(--fs-12); color: var(--text-3); }
.dl dd { margin: 0; font-size: var(--fs-13); font-weight: 500; }

.kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  font-size: var(--fs-13);
  border-bottom: 1px solid var(--border);
}
.kv:last-child { border-bottom: 0; }
.kv__k { color: var(--text-2); }
.kv__v { font-weight: 600; text-align: right; }

/* --------------------------------------------------------------------------
   Segmented control / filter pills
   -------------------------------------------------------------------------- */

.seg {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 0 2px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }

.seg__item {
  flex: 0 0 auto;
  padding: 7px 13px;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  transition: all var(--t-fast);
}

.seg__item.is-active {
  color: var(--primary-ink);
  background: var(--primary);
  border-color: var(--primary);
}

.seg__item span { opacity: .66; font-weight: 500; }

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */

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

.stat {
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-1);
}

.stat__k {
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-3);
}

.stat__v {
  font-size: var(--fs-26);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.stat__v small { font-size: var(--fs-13); font-weight: 600; color: var(--text-3); }
.stat__foot { font-size: var(--fs-11); color: var(--text-2); }
.stat--accent { background: var(--accent-soft); border-color: var(--lh-gold-200); }
.stat--danger { background: var(--danger-soft); border-color: var(--border-danger); }
.stat--danger .stat__v { color: var(--danger-ink); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field { display: block; }

.field__label {
  display: block;
  margin-bottom: 5px;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-2);
}

.field__input,
.field__select,
.field__textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  font-size: var(--fs-14);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}

.field__textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

.field__input:focus,
.field__select:focus,
.field__textarea:focus {
  outline: 0;
  border-color: var(--lh-navy-500);
  box-shadow: 0 0 0 3px var(--lh-navy-100);
}

.field__select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a6b7d' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 17px;
  padding-right: 36px;
}

.field__hint { margin-top: 5px; font-size: var(--fs-11); color: var(--text-3); }
.field__error { margin-top: 5px; font-size: var(--fs-12); font-weight: 600; color: var(--danger-ink); }
.field__error a { text-decoration: underline; }
.field__req { color: var(--danger-ink); }

.field__input[aria-invalid="true"],
.field__select[aria-invalid="true"] { border-color: var(--danger); }

/* Search row (ลีดของฉัน). The box sits outside the list it filters, so
   typing re-renders the list without taking the keyboard away. */
.searchbar { position: relative; margin-bottom: 10px; }

.searchbar > svg {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 18px;
  height: 18px;
  color: var(--text-3);
  transform: translateY(-50%);
  pointer-events: none;
}

.searchbar .field__input { padding-left: 40px; }
.search-count { margin: -2px 2px 8px; font-size: var(--fs-12); color: var(--text-2); }

/* --------------------------------------------------------------------------
   Notice / empty state
   -------------------------------------------------------------------------- */

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 13px;
  font-size: var(--fs-12);
  line-height: 1.6;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--r-md);
}

.notice b { color: var(--text); }
.notice--info { background: var(--info-soft); border-color: var(--border-info); border-left-color: var(--info); }
.notice--warn { background: var(--warn-soft); border-color: var(--border-warn); border-left-color: var(--warn); }
.notice--danger { background: var(--danger-soft); border-color: var(--border-danger); border-left-color: var(--danger); }

.empty {
  padding: 42px 20px;
  text-align: center;
  color: var(--text-3);
}

.empty__icon { margin: 0 auto 10px; color: var(--border-strong); }
.empty__title { font-size: var(--fs-14); font-weight: 600; color: var(--text-2); }
.empty__text { margin-top: 3px; font-size: var(--fs-12); }

/* --------------------------------------------------------------------------
   Timeline (lead history 4.5)
   -------------------------------------------------------------------------- */

.timeline { position: relative; padding-left: 20px; }

.timeline::before {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 4px;
  width: 2px;
  background: var(--border);
}

.timeline__item { position: relative; padding-bottom: 13px; }
.timeline__item:last-child { padding-bottom: 0; }

.timeline__item::before {
  content: "";
  position: absolute;
  top: 6px;
  left: -20px;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-pill);
}

.timeline__item:first-child::before { border-color: var(--accent); background: var(--accent); }
.timeline__when { font-size: var(--fs-11); font-weight: 600; color: var(--text-3); }
.timeline__what { font-size: var(--fs-13); }

/* --------------------------------------------------------------------------
   Bottom sheet (ui.sheet — hosts the call-outcome stamps)
   -------------------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(14, 27, 42, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}

.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  transform: translateY(100%);
  transition: transform var(--t-base);
}

.sheet-backdrop.is-open .sheet { transform: translateY(0); }

.sheet__grip {
  width: 38px;
  height: 4px;
  margin: 0 auto 12px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
}

.sheet__title { margin-bottom: 12px; font-size: var(--fs-15); font-weight: 700; }

@media (min-width: 768px) {
  .pv-desktop .sheet {
    position: relative;
    inset: auto;
    width: min(460px, 100%);
    margin: 10vh auto;
    border-radius: var(--r-lg);
    transform: translateY(14px) scale(.98);
  }
  .pv-desktop .sheet-backdrop { overflow: auto; }
  .pv-desktop .sheet-backdrop.is-open .sheet { transform: none; }
}

/* --------------------------------------------------------------------------
   Call-outcome stamps — the sheet after โทร (stamp.js)
   -------------------------------------------------------------------------- */

.stamp-sub { margin: -4px 0 12px; font-size: var(--fs-12); color: var(--text-2); }

.stamp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stamp {
  min-height: 52px;
  padding: 10px 12px;
  font-size: var(--fs-15);
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.stamp:active { transform: scale(.985); }
.stamp.is-active { background: var(--surface-2); border-color: var(--primary); }
.stamp.is-done { color: var(--ok-strong); border-color: var(--ok); }
.stamp.is-done.is-active { background: var(--ok-soft); }

.stamp-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.stamp-form .field + .field { margin-top: 10px; }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast-host {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  left: 50%;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 28px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 15px;
  font-size: var(--fs-13);
  font-weight: 500;
  color: var(--text-on-dark);
  background: var(--lh-navy-800);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-3);
  animation: toast-in var(--t-base) both;
}

.toast--ok { background: var(--ok-strong); }
.toast--danger { background: var(--danger-ink); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* --------------------------------------------------------------------------
   Stub page (Phase 2 placeholders)
   -------------------------------------------------------------------------- */

.stub {
  display: grid;
  place-items: center;
  min-height: 56dvh;
  padding: 28px 20px;
  text-align: center;
}

.stub__badge {
  display: inline-block;
  margin-bottom: 14px;
  padding: 4px 12px;
  font-size: var(--fs-11);
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--gold-ink);
  background: var(--accent-soft);
  border-radius: var(--r-pill);
}

.stub__title { font-size: var(--fs-20); font-weight: 700; letter-spacing: -.02em; }
.stub__text {
  max-width: 34ch;
  margin: 8px auto 0;
  font-size: var(--fs-13);
  color: var(--text-2);
}

.stub__list {
  max-width: 34ch;
  margin: 18px auto 0;
  text-align: left;
}

.stub__list li {
  position: relative;
  padding-left: 18px;
  font-size: var(--fs-12);
  color: var(--text-2);
}
.stub__list li + li { margin-top: 5px; }
.stub__list li::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 4px;
  width: 5px;
  height: 5px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
}
