/* ============================================================================
   customers.css — Customer Directory tab (public/js/customers.js)
   Flat navy, no gradients; same look as the Dispatch Board. Scoped under
   #tab-customers; table rules carry !important only to beat the CRM's global
   th/td rules (admin.css body.crm-app th/td, crm-theme.css th sticky).
   ========================================================================== */
#tab-customers {
  --cu-navy: #0A2540;
  --cu-navy-2: #13365c;
  --cu-text: #132033;
  --cu-muted: #65758b;
  --cu-line: #dbe5ee;
  --cu-line-soft: #edf2f7;
  --cu-surface: #fff;
  --cu-soft: #f7fafc;
  --cu-bad: #b42318;  --cu-bad-bg: #fef3f2;  --cu-bad-line: #fecdca;
  --cu-warn: #b54708; --cu-warn-bg: #fffaeb; --cu-warn-line: #fedf89;
  --cu-ok: #067647;   --cu-ok-bg: #ecfdf3;   --cu-ok-line: #abefc6;
  --cu-info: #1e3a8a; --cu-info-bg: #eef2fb; --cu-info-line: #c7d4ee;
  color: var(--cu-text);
}
#tab-customers .cu-root { display: flex; flex-direction: column; gap: 14px; }
#tab-customers .cu-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#tab-customers .cu-muted { color: var(--cu-muted); }

/* ── toolbar ── */
#tab-customers .cu-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px; background: var(--cu-surface); border: 1px solid var(--cu-line); border-radius: 10px;
}
#tab-customers .cu-search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; margin: 0;
  border: 1px solid var(--cu-line); border-radius: 8px; background: var(--cu-surface); color: var(--cu-muted); cursor: text;
}
#tab-customers .cu-search:focus-within { border-color: var(--cu-navy); box-shadow: 0 0 0 3px rgba(10, 37, 64, .1); }
#tab-customers .cu-search input {
  flex: 1; min-width: 0; height: 100%; min-height: 0; border: 0 !important; outline: 0; box-shadow: none !important;
  background: transparent; font-size: 13.5px; color: var(--cu-text); padding: 0; margin: 0;
}

/* ── buttons ── */
#tab-customers .cu-btn {
  min-height: 0; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid #cfd9e6; background: var(--cu-surface);
  color: var(--cu-navy); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; box-shadow: none;
}
body.crm-app #tab-customers .cu-btn { font-family: var(--crm-font, inherit) !important; font-size: 13px; line-height: 1; letter-spacing: normal; }
#tab-customers .cu-btn:hover { border-color: var(--cu-navy); background: var(--cu-soft); }
#tab-customers .cu-btn-primary { background: var(--cu-navy); border-color: var(--cu-navy); color: #fff; }
#tab-customers .cu-btn-primary:hover { background: var(--cu-navy-2); border-color: var(--cu-navy-2); }
#tab-customers .cu-btn:disabled { opacity: .45; cursor: not-allowed; }
#tab-customers .cu-btn-primary:disabled { background: var(--cu-navy); }
#tab-customers .cu-btn:not(.cu-btn-primary):disabled { background: var(--cu-surface); border-color: #cfd9e6; }
#tab-customers .cu-link {
  min-height: 0; height: auto; padding: 0; border: 0; background: none; color: var(--cu-navy);
  font-size: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; box-shadow: none;
}
#tab-customers .cu-link.is-bad { color: var(--cu-bad); }
#tab-customers .cu-icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--cu-line); border-radius: 8px; background: var(--cu-surface); color: #475569; text-decoration: none;
}
#tab-customers .cu-icon-btn:hover { border-color: #b8c7da; color: var(--cu-navy); background: var(--cu-soft); }
#tab-customers .cu-btn:focus-visible, #tab-customers .cu-icon-btn:focus-visible, #tab-customers .cu-link:focus-visible,
#tab-customers .cu-x:focus-visible, #tab-customers .cu-hist-row:focus-visible {
  outline: 2px solid var(--cu-navy); outline-offset: 2px;
}

/* ── list panel ── */
#tab-customers .cu-panel { background: var(--cu-surface); border: 1px solid var(--cu-line); border-radius: 10px; overflow: hidden; }
#tab-customers .cu-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 6px 16px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--cu-line-soft);
}
#tab-customers .cu-title { font-size: 15px; font-weight: 600; }
#tab-customers .cu-title span { margin-left: 6px; font-size: 13px; font-weight: 500; color: var(--cu-muted); font-variant-numeric: tabular-nums; }
#tab-customers .cu-note { font-size: 12.5px; color: var(--cu-muted); }
#tab-customers .cu-panel.is-busy .cu-table-wrap { opacity: .55; transition: opacity .15s; }

#tab-customers .cu-table-wrap { overflow-x: auto; }
body.crm-app #tab-customers .cu-table { width: 100% !important; min-width: 0 !important; border-collapse: collapse !important; }
body.crm-app #tab-customers .cu-table th {
  position: static !important; padding: 10px 16px !important; background: var(--cu-soft) !important;
  color: var(--cu-muted) !important; font-size: 11.5px !important; font-weight: 600 !important;
  letter-spacing: .03em !important; text-transform: uppercase !important; white-space: nowrap !important;
  border-bottom: 1px solid var(--cu-line) !important; text-align: left;
}
body.crm-app #tab-customers .cu-table td {
  padding: 11px 16px !important; color: var(--cu-text) !important; font-size: 13px !important;
  vertical-align: middle !important; white-space: normal !important; border-bottom: 1px solid var(--cu-line-soft) !important;
  line-height: 1.4;
}
body.crm-app #tab-customers .cu-table tbody tr.cu-row { cursor: pointer; }
body.crm-app #tab-customers .cu-table tbody tr.cu-row:hover td { background: var(--cu-soft) !important; }
#tab-customers .cu-row:focus-visible { outline: 2px solid var(--cu-navy); outline-offset: -2px; }
body.crm-app #tab-customers .cu-table .cu-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap !important; }
body.crm-app #tab-customers .cu-table .cu-when { white-space: nowrap !important; color: #475569 !important; }
body.crm-app #tab-customers .cu-table .cu-act { text-align: right; white-space: nowrap !important; width: 1%; }
#tab-customers .cu-act-in { display: inline-flex; gap: 6px; }
#tab-customers .cu-name { font-weight: 600; color: var(--cu-navy); font-size: 13.5px; }
#tab-customers .cu-sub { font-size: 12px; color: var(--cu-muted); margin-top: 1px; word-break: break-word; }

#tab-customers .cu-tag {
  display: inline-flex; align-items: center; padding: 0 8px; border-radius: 10px; border: 1px solid;
  font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap; vertical-align: 1px;
}
#tab-customers .cu-tag.is-ok    { color: var(--cu-ok);   background: var(--cu-ok-bg);   border-color: var(--cu-ok-line); }
#tab-customers .cu-tag.is-warn  { color: var(--cu-warn); background: var(--cu-warn-bg); border-color: var(--cu-warn-line); }
#tab-customers .cu-tag.is-bad   { color: var(--cu-bad);  background: var(--cu-bad-bg);  border-color: var(--cu-bad-line); }
#tab-customers .cu-tag.is-info  { color: var(--cu-info); background: var(--cu-info-bg); border-color: var(--cu-info-line); }
#tab-customers .cu-tag.is-muted { color: #475569; background: #f1f5f9; border-color: #e2e8f0; }

#tab-customers .cu-pager {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  padding: 10px 18px; border-top: 1px solid var(--cu-line-soft); font-size: 12.5px; color: var(--cu-muted);
}
#tab-customers .cu-pager-info { font-variant-numeric: tabular-nums; }
#tab-customers .cu-pager-btns { display: inline-flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; color: var(--cu-text); }
#tab-customers .cu-pager .cu-btn { height: 32px; padding: 0 12px; font-size: 12.5px; }

#tab-customers .cu-empty { padding: 36px 18px; text-align: center; color: var(--cu-muted); font-size: 13.5px; }
#tab-customers .cu-empty.is-bad { color: var(--cu-bad); }
#tab-customers .cu-spin {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid #cbd5e1; border-top-color: var(--cu-navy); border-radius: 50%; animation: cu-spin .8s linear infinite;
}
@keyframes cu-spin { to { transform: rotate(360deg); } }

/* ── profile drawer ── */
#tab-customers .cu-drawer { position: fixed; inset: 0; z-index: 1200; }
#tab-customers .cu-drawer[hidden] { display: none; }
#tab-customers .cu-backdrop { position: absolute; inset: 0; background: rgba(10, 37, 64, .35); }
#tab-customers .cu-sheet {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(540px, 100%); display: flex; flex-direction: column;
  background: var(--cu-surface); box-shadow: -12px 0 32px rgba(10, 37, 64, .18); animation: cu-in .18s ease-out;
}
@keyframes cu-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#tab-customers .cu-sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--cu-line-soft);
}
#tab-customers .cu-sheet-head h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--cu-navy); line-height: 1.3; word-break: break-word; }
#tab-customers .cu-sheet-head p { margin: 3px 0 0; font-size: 12.5px; color: var(--cu-muted); }
#tab-customers .cu-x {
  min-height: 0; width: 34px; height: 34px; flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  border: 1px solid var(--cu-line); border-radius: 8px; background: var(--cu-surface); color: #475569; cursor: pointer; box-shadow: none;
}
#tab-customers .cu-x:hover { color: var(--cu-navy); border-color: #b8c7da; }
#tab-customers .cu-sheet-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; display: flex; flex-direction: column; gap: 18px; }

#tab-customers .cu-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#tab-customers .cu-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#tab-customers .cu-stat { padding: 10px 12px; border: 1px solid var(--cu-line); border-radius: 10px; display: flex; flex-direction: column; gap: 2px; }
#tab-customers .cu-stat span { font-size: 11.5px; font-weight: 600; color: var(--cu-muted); }
#tab-customers .cu-stat b { font-size: 20px; font-weight: 600; color: var(--cu-navy); font-variant-numeric: tabular-nums; line-height: 1.2; }
#tab-customers .cu-stat em { font-style: normal; font-size: 11px; color: var(--cu-muted); }

#tab-customers .cu-sec h3 {
  margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--cu-muted); text-transform: uppercase; letter-spacing: .04em;
}
#tab-customers .cu-sec h3 span { margin-left: 4px; color: #94a3b8; font-variant-numeric: tabular-nums; }
#tab-customers .cu-dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
#tab-customers .cu-dl > div { min-width: 0; }
#tab-customers .cu-dl-wide { grid-column: 1 / -1; }
#tab-customers .cu-dl dt { font-size: 11.5px; color: var(--cu-muted); margin: 0 0 2px; }
#tab-customers .cu-dl dd { margin: 0; font-size: 13.5px; word-break: break-word; }
#tab-customers .cu-notes { white-space: pre-wrap; }

#tab-customers .cu-hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#tab-customers .cu-hist-row {
  min-height: 0; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--cu-line); border-radius: 8px; background: var(--cu-surface);
  color: var(--cu-text); font-size: 13px; text-align: left; cursor: pointer; box-shadow: none;
}
#tab-customers .cu-hist-row:hover { border-color: var(--cu-navy); }
#tab-customers .cu-hist-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
#tab-customers .cu-hist-main b { color: var(--cu-navy); font-weight: 600; }
#tab-customers .cu-hist-amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
#tab-customers .cu-hist-meta { font-size: 12px; color: #475569; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tab-customers .cu-hist-when { font-size: 12px; color: var(--cu-muted); text-align: right; white-space: nowrap; }
#tab-customers .cu-hist-meta + .cu-hist-when { grid-column: 2; }
#tab-customers .cu-hist-main + .cu-hist-amt + .cu-hist-when { grid-column: 1 / -1; text-align: left; }
#tab-customers .cu-none { margin: 6px 0 0; font-size: 12.5px; color: var(--cu-muted); }
#tab-customers .cu-danger { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--cu-line-soft); font-size: 12.5px; color: var(--cu-muted); }

/* add / edit form */
#tab-customers .cu-form { display: flex; flex-direction: column; gap: 14px; }
#tab-customers .cu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
#tab-customers .cu-field { display: flex; flex-direction: column; gap: 4px; margin: 0; min-width: 0; }
#tab-customers .cu-field.is-wide { grid-column: 1 / -1; }
#tab-customers .cu-field > span { font-size: 12px; font-weight: 600; color: #475569; }
#tab-customers .cu-field i { color: var(--cu-bad); font-style: normal; }
#tab-customers .cu-field input, #tab-customers .cu-field textarea {
  width: 100%; box-sizing: border-box; min-height: 0; height: 38px; padding: 0 11px; margin: 0;
  border: 1px solid var(--cu-line); border-radius: 8px; background: var(--cu-surface); color: var(--cu-text); font-size: 16px; font-family: inherit;
}
@media (min-width: 761px) { #tab-customers .cu-field input, #tab-customers .cu-field textarea { font-size: 13.5px; } }
#tab-customers .cu-field textarea { height: auto; padding: 9px 11px; resize: vertical; line-height: 1.45; }
#tab-customers .cu-field input:focus, #tab-customers .cu-field textarea:focus { outline: 0; border-color: var(--cu-navy); box-shadow: 0 0 0 3px rgba(10, 37, 64, .1); }
#tab-customers .cu-form-err { margin: 0; padding: 9px 12px; border-radius: 8px; background: var(--cu-bad-bg); border: 1px solid var(--cu-bad-line); color: var(--cu-bad); font-size: 13px; }
#tab-customers .cu-form-err[hidden] { display: none; }
#tab-customers .cu-form-foot { display: flex; justify-content: flex-end; gap: 8px; }

body.cu-drawer-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  #tab-customers .cu-spin { animation: none; }
  #tab-customers .cu-sheet { animation: none; }
  #tab-customers .cu-panel.is-busy .cu-table-wrap { transition: none; }
}

/* ── phones: rows become cards ── */
@media (max-width: 760px) {
  #tab-customers .cu-toolbar { padding: 8px; }
  #tab-customers .cu-toolbar .cu-btn { flex: 1 1 0; }
  #tab-customers .cu-head { padding: 12px 14px; }
  #tab-customers .cu-table thead { display: none; }
  #tab-customers .cu-table, #tab-customers .cu-table tbody { display: block; }
  #tab-customers .cu-table tr.cu-row {
    display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 14px; border-bottom: 1px solid var(--cu-line-soft);
  }
  body.crm-app #tab-customers .cu-table tr.cu-row td { display: block; padding: 0 !important; border: 0 !important; background: none !important; }
  body.crm-app #tab-customers .cu-table tr.cu-row:hover td { background: none !important; }
  #tab-customers .cu-table td[data-label="Customer"] { grid-column: 1; }
  body.crm-app #tab-customers .cu-table td.cu-act { grid-column: 2; grid-row: 1; width: auto; }
  #tab-customers .cu-table td[data-label="Contact"], #tab-customers .cu-table td[data-label="Location"] { grid-column: 1 / -1; }
  body.crm-app #tab-customers .cu-table .cu-num { text-align: left; }
  #tab-customers .cu-table td[data-label="Orders"]::before { content: 'Orders: '; color: var(--cu-muted); }
  #tab-customers .cu-table td[data-label="Location"]:has(.cu-muted) { display: none !important; }
  #tab-customers .cu-pager { padding: 10px 14px; }
  #tab-customers .cu-sheet-head { padding: 14px 16px 12px; }
  #tab-customers .cu-sheet-body { padding: 14px 16px 24px; }
  #tab-customers .cu-stat b { font-size: 17px; }
  #tab-customers .cu-grid, #tab-customers .cu-dl { grid-template-columns: 1fr; }
  #tab-customers .cu-actions .cu-btn { flex: 1 1 auto; }
}

/* Export is admin-only (the server refuses agents too). */
body.agent-mode #cuExportBtn { display: none !important; }
