/* Senarai kerja, Lead and Butiran lead. Built on app.css (the account-book system): the ruled list, the
   pen marks, stamps, the head line, buttons, fields and the ledger all come from there. This file adds
   only what is particular to these three pages — the two-list worklist layout with its phone tabs, the
   register's desktop table and its phone ruled rows, the four-step stage track, and the lead's detail
   head block. No inline style is ever emitted (the CSP is style-src 'self'); every colour is a token. */

/* ======================================================================
   Senarai kerja
   ====================================================================== */

/* The owner's line narrow (staff never see it). */
.work-narrow {
  margin-bottom: 18px;
}
.work-narrow .field-label {
  margin-bottom: 6px;
}
.work-narrow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.work-narrow select {
  flex: 1 1 200px;
  max-width: 320px;
}
.work-narrow .btn {
  flex: none;
  min-height: 48px;
}
.work-narrow-toggle {
  display: none;
}
/* Below 1024px the select is hidden until the filter is opened (a line set, or ?tapis=1); a phone-only
   link toggles it, so the first rows sit high. The desktop always shows the select. */
@media (max-width: 1023.98px) {
  .work-narrow-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    color: var(--pen);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  .work-narrow:not(.is-open) {
    display: none;
  }
}

/* The phone's two link-tabs. Hidden on a desktop, which shows both lists. */
.worklist-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.worklist-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 10px 10px;
  margin-bottom: -1px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 550;
  border-bottom: 2px solid transparent;
}
.worklist-tab:hover {
  color: var(--ink);
}
.worklist-tab.is-current {
  color: var(--ink);
  border-bottom-color: var(--pen);
}
.tab-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: var(--radius-stamp);
  background: var(--pen-wash);
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 650;
  text-align: center;
}
.tab-count.owed {
  background: var(--owed-wash);
  color: var(--owed);
}

/* The two lists. One column on a phone (one list shown at a time); side by side on a desktop. */
.worklists {
  display: grid;
  gap: 22px;
}
.worklist {
  min-width: 0;
}
.worklist .headline {
  color: var(--ink);
  font-weight: 600;
  font-size: 1rem;
  padding: 0 0 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--rule-strong);
}
/* The desktop head line is whole; on a phone the tab already names the list and count, so only the oldest
   wait (hl-short) shows, and an empty list's head line (no wait) is dropped. */
.worklist-headline .hl-short {
  display: none;
}
@media (max-width: 1023.98px) {
  .worklist-headline .hl-long {
    display: none;
  }
  .worklist-headline .hl-short {
    display: inline;
  }
  .worklist-headline.hl-none {
    display: none;
  }
  /* the head line carries the oldest wait on the left and the way into the line filter on the right */
  .worklist-headline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 0 6px;
    margin-bottom: 8px;
  }
  .worklist-headline.hl-none.has-filter {
    display: flex;
    justify-content: flex-end;
  }
}
.hl-filter {
  display: none;
}
@media (max-width: 1023.98px) {
  .hl-filter {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    color: var(--pen);
    font-weight: 500;
    white-space: nowrap;
  }
  /* two actions sit side by side, so a Perlu susul row is no taller than a Belum dijawab row */
  .work-actions {
    flex-wrap: nowrap;
  }
  .work-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 10px;
  }
  .work-actions .btn:only-child {
    flex: 0 0 auto;
    padding: 0 16px;
  }
}
.work-more {
  margin-top: 12px;
}

@media (max-width: 1023.98px) {
  /* A phone shows the active list only; the tabs choose it. */
  .worklist {
    display: none;
  }
  .worklist.is-active {
    display: block;
  }
}
@media (min-width: 1024px) {
  .worklists {
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    align-items: start;
  }
  .worklist-tabs {
    display: none;
  }
}

/* A worklist row: the pen mark in the 44px margin column, then the body. */
.ruled-row.work-row {
  grid-template-columns: 44px minmax(0, 1fr);
}
.work-row .ruled-mark {
  padding-top: 13px;
}
.work-body {
  padding: 12px 16px;
  min-width: 0;
}
.work-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.work-name {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.work-wait {
  flex: none;
  color: var(--ink-2);
  font-weight: 600;
  font-stretch: 90%;
  white-space: nowrap;
}
.work-wait.owed {
  color: var(--owed);
}
.work-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 3px;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.work-phone {
  color: var(--ink-3);
}
.work-labels {
  margin-top: 5px;
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.work-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 11px;
}
.work-actions .btn {
  flex: 0 0 auto;
}
.work-nophone {
  margin-top: 10px;
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-stretch: 90%;
}

/* ======================================================================
   Lead — the register
   ====================================================================== */

.lead-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  margin-bottom: 2px;
}
/* The three narrow-able fields (Talian, Status, Dari iklan). On a desktop the wrapper is transparent to
   the flex row; on a phone it becomes a full-width group that collapses unless the bar is open. */
.lead-filters-extra {
  display: contents;
}
.lead-filters .field {
  flex: 1 1 170px;
  min-width: 0;
  margin-bottom: 0;
}
.lead-filters .lead-cari {
  flex: 2 1 220px;
}
.lead-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  color: var(--ink);
  font-size: 0.9375rem;
  white-space: nowrap;
}
.lead-check input {
  width: 20px;
  height: 20px;
  flex: none;
  margin: 0;
}
.lead-filters-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
/* the filter submit sits in a row with 48px fields, so it is 48px tall at every width */
.lead-filters-actions .btn {
  min-height: 48px;
}
.lead-tapis-toggle {
  display: none;
}

/* Below 1024px only the search and its submit show; the Talian/Status/ad fields collapse unless the bar
   is open, so the first leads sit in the top third. The hidden fields stay in the form, so they submit. */
@media (max-width: 1023.98px) {
  .lead-filters .lead-cari {
    flex: 1 1 100%;
  }
  .lead-filters-extra {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 14px;
    flex: 1 1 100%;
    order: 3;
  }
  .lead-filters:not(.is-open) .lead-filters-extra {
    display: none;
  }
  .lead-filters-extra .field {
    flex: 1 1 160px;
  }
  .lead-check {
    flex: 1 1 auto;
  }
  .lead-filters-actions {
    order: 2;
    flex: 1 1 100%;
    align-items: center;
  }
  .lead-tapis-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    margin-right: auto;
    color: var(--pen);
    font-weight: 500;
    white-space: nowrap;
  }
  /* closed: the search field and its button share one row, and the button says "Cari" */
  .lead-filters:not(.is-open) .lead-cari {
    flex: 1 1 180px;
  }
  .lead-filters:not(.is-open) .lead-filters-actions {
    flex: 0 0 auto;
  }
  .lead-filters:not(.is-open) .lbl-cari {
    display: inline;
  }
  .lead-filters:not(.is-open) .lbl-tapis {
    display: none;
  }
  .lead-headrow .lead-tapis-toggle {
    margin-right: 0;
  }
}
.lbl-cari {
  display: none;
}
.lead-headrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.lead-headrow .headline {
  flex: 1 1 auto;
  min-width: 0;
}

.lead-page .headline {
  padding: 16px 0 12px;
  color: var(--ink-2);
}

/* Desktop: a real table. Phone: the ruled list. Each is shown at one breakpoint only. */
.lead-table-wrap {
  display: none;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.lead-list {
  display: block;
}
@media (min-width: 1024px) {
  .lead-table-wrap {
    display: block;
  }
  .lead-list {
    display: none;
  }
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.lead-table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  font-stretch: 85%;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
}
.lead-table thead th.num {
  text-align: right;
}
.lead-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.lead-table tbody tr:last-child td {
  border-bottom: 0;
}
.lead-table tbody tr:hover {
  background: var(--pen-wash);
}
.lead-table .num {
  text-align: right;
  white-space: nowrap;
  color: var(--ink-2);
}
.lead-table .col-mark {
  width: 37px;
  padding-left: 16px;
  padding-right: 0;
  /* the mark column carries the red margin rule on its right edge, like the ruled rows on a phone */
  border-right: 1px solid var(--margin);
}
.col-mark .pen-mark {
  margin-top: 1px;
}
.lead-name-cell {
  min-width: 0;
}
.lead-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.lead-sub {
  display: block;
  margin-top: 2px;
  color: var(--ink-3);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

/* Phone ruled rows carrying the same, never a tall card. */
.ruled-row.lead-row {
  grid-template-columns: 44px minmax(0, 1fr);
}
.lead-row .ruled-mark {
  padding-top: 13px;
}
.lead-row-body {
  padding: 11px 14px;
  min-width: 0;
}
.lead-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.lead-row-head .lead-name {
  min-width: 0;
}
.lead-last {
  flex: none;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-stretch: 90%;
  white-space: nowrap;
}
.lead-row .lead-sub {
  margin-top: 1px;
}
.lead-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 8px;
}
.lead-line {
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.lead-row .stage-compact {
  margin-top: 10px;
}

.lead-pager {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ======================================================================
   Stage track (Lead table + Butiran)
   ====================================================================== */

.stage-track {
  display: flex;
  align-items: center;
  gap: 5px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.stage-step {
  display: flex;
  align-items: center;
}
.stage-pip {
  display: block;
  width: 22px;
  height: 5px;
  border-radius: 2px;
  background: var(--rule-strong);
}
.stage-step.is-on .stage-pip {
  background: var(--pen);
}
/* The compact track (Lead table + phone rows): the pips with the current stage word beside them, so the
   stage never relies on a tooltip. */
.stage-compact {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.stage-now {
  font-size: 0.8125rem;
  color: var(--ink-2);
  font-stretch: 92%;
}

/* The labelled track on the detail page: four columns, a pip above each stage name. */
.stage-track-full {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: start;
  gap: 10px;
  max-width: 540px;
}
.stage-track-full .stage-step {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.stage-track-full .stage-pip {
  width: 100%;
  height: 6px;
}
.stage-track-full .stage-name {
  font-size: 0.8125rem;
  line-height: 1.25;
  color: var(--ink-3);
  font-stretch: 92%;
  overflow-wrap: anywhere;
}
.stage-track-full .stage-step.is-on .stage-name {
  color: var(--ink);
  font-weight: 600;
}

/* ======================================================================
   Butiran lead — the detail: a focused record, capped to a reading column
   ====================================================================== */

.butiran {
  max-width: 820px;
}
.butiran .back {
  margin-top: 2px;
}
.butiran-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px 24px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 26px;
}
.butiran-id {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}
.butiran-name {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.butiran-line,
.butiran-phone {
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.butiran-id .stamp {
  margin-top: 2px;
}
.butiran-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}
.butiran-block {
  margin-bottom: 24px;
}
.butiran-block:last-child {
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .butiran-actions {
    width: 100%;
  }
  .butiran-actions .btn {
    flex: 1 1 auto;
  }
}
