/* CRM / customer-accounts screen — faithful to the SDOS Workspace handoff
   (lines 1522-1684). All non-color geometry copied from the handoff inline
   styles; every color maps onto a theme token so dark mode keeps working.
   Classes are namespaced .crm-* to avoid collisions. */
@layer screens {

  /* ---- pill-style tab buttons (handoff lines 1526-1532) ---- */
  .crm-tabs { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
  .crm-tab {
    display: inline-flex; align-items: center; gap: 7px;
    border-radius: 999px; padding: 7px 14px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    border: 1px solid var(--line-strong);
    background: var(--surface); color: var(--text-2);
    text-decoration: none;
  }
  .crm-tab:hover { background: var(--surface-2); text-decoration: none; }
  .crm-tab.is-active {
    border-color: var(--primary); background: var(--primary); color: #fff;
  }
  .crm-tab.is-active:hover { background: var(--primary); filter: brightness(1.05); }
  .crm-tab-count {
    font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 1px 7px;
    background: var(--warn-bg); color: var(--warn-fg);
  }
  .crm-tab.is-active .crm-tab-count { background: rgba(255, 255, 255, 0.22); color: #fff; }

  /* ---- accounts master list (handoff sidebar cards, lines 1539-1554) ---- */
  .crm-acct-list {
    display: flex; flex-direction: column; gap: 10px;
    max-width: 720px;
  }
  .crm-acct-card {
    background: var(--surface); border: 1.5px solid var(--line);
    border-radius: 12px; padding: 12px 14px;
    display: flex; flex-direction: column; gap: 6px;
    text-decoration: none; color: var(--text);
  }
  .crm-acct-card:hover {
    border-color: var(--primary-border);
    box-shadow: 0 2px 12px rgba(20, 35, 60, 0.07);
    text-decoration: none;
  }
  .crm-acct-top { display: flex; align-items: center; gap: 8px; }
  .crm-acct-name {
    font-size: 14px; font-weight: 700; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .crm-acct-row {
    display: flex; gap: 10px; font-size: 12px; align-items: baseline;
    color: var(--muted);
  }
  .crm-acct-row .crm-ellip {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .crm-acct-row .crm-nowrap { white-space: nowrap; }
  .crm-acct-ltv { flex: 1; color: var(--text-2); font-weight: 600; }

  /* ---- shared mini status chip (square, handoff stBg/stColor) ---- */
  .crm-chip {
    border-radius: 6px; padding: 2px 8px;
    font-size: 11px; font-weight: 700; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
  }
  .crm-chip.crm-ok { background: var(--ok-bg); color: var(--ok-fg); }
  .crm-chip.crm-soon { background: var(--warn-bg); color: var(--warn-fg); }
  .crm-chip.crm-overdue { background: var(--danger-bg); color: var(--danger-fg); }
  .crm-chip.crm-call { background: var(--primary-soft); color: var(--primary); }
  .crm-chip.crm-line { background: var(--ok-bg); color: var(--ok-fg); }
  .crm-chip.crm-none { background: var(--surface-3); color: var(--muted); }

  /* ---- detail layout (handoff main column, lines 1557-1659) ---- */
  .crm-detail {
    display: flex; flex-direction: column; gap: 14px;
    max-width: 880px;
  }
  .crm-back { font-size: 13px; color: var(--text-2); text-decoration: none; }
  .crm-back:hover { color: var(--text); }

  .crm-panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 13px; padding: 16px 18px;
    display: flex; flex-direction: column; gap: 12px;
    box-shadow: var(--shadow-card);
  }
  .crm-panel.crm-gap10 { gap: 10px; }
  .crm-panel.crm-gap8 { gap: 8px; }

  /* header card */
  .crm-head-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .crm-head-name { font-size: 18px; font-weight: 700; }
  .crm-chip-md {
    border-radius: 6px; padding: 2px 9px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap;
    background: var(--surface-3); color: var(--text-2);
  }
  .crm-chip-md.crm-ok { background: var(--ok-bg); color: var(--ok-fg); }
  .crm-chip-md.crm-soon { background: var(--warn-bg); color: var(--warn-fg); }
  .crm-chip-md.crm-overdue { background: var(--danger-bg); color: var(--danger-fg); }
  .crm-chip-md.crm-none { background: var(--surface-3); color: var(--muted); }
  .crm-spacer { flex: 1; }
  .crm-branch-pill {
    border-radius: 999px; padding: 2px 9px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: var(--primary-soft); color: var(--primary);
  }
  .crm-form-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px;
  }
  .crm-field-label {
    display: block; font-size: 12px; font-weight: 600;
    color: var(--text-2); margin-bottom: 6px;
  }
  .crm-input, .crm-select {
    width: 100%; box-sizing: border-box;
    border: 1px solid var(--line-strong); border-radius: 9px;
    padding: 9px 8px; font-size: 14px;
    background: var(--surface-2); outline: none; color: var(--text);
    font-family: inherit;
  }
  .crm-input:focus, .crm-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
  }
  .crm-meta-line { font-size: 12.5px; color: var(--text-2); }

  /* KPI tile row (handoff lines 1589-1607) */
  .crm-kpis {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
  }
  .crm-kpi {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 11px; padding: 11px 13px;
    display: flex; flex-direction: column; gap: 3px;
    box-shadow: var(--shadow-card);
  }
  .crm-kpi-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--muted);
  }
  .crm-kpi-value { font-size: 16.5px; font-weight: 700; }
  .crm-kpi-chip {
    display: inline-flex; align-self: flex-start;
    border-radius: 6px; padding: 2px 8px;
    font-size: 11px; font-weight: 700;
    background: var(--surface-3); color: var(--text-2);
  }
  .crm-kpi-chip.crm-ok { background: var(--ok-bg); color: var(--ok-fg); }
  .crm-kpi-chip.crm-soon { background: var(--warn-bg); color: var(--warn-fg); }
  .crm-kpi-chip.crm-overdue { background: var(--danger-bg); color: var(--danger-fg); }

  /* section heading (uppercase eyebrow) */
  .crm-section-head { display: flex; align-items: center; gap: 10px; }
  .crm-eyebrow {
    font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--muted);
  }
  .crm-ghost-btn {
    border: 1px solid var(--line-strong); cursor: pointer;
    background: var(--surface); color: var(--primary);
    border-radius: 8px; padding: 6px 11px;
    font-size: 12px; font-weight: 600; text-decoration: none;
    font-family: inherit;
  }
  .crm-ghost-btn:hover { background: var(--surface-2); text-decoration: none; }

  /* tasks (handoff lines 1615-1625) */
  .crm-task {
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--line); background: var(--surface-2);
    border-radius: 10px; padding: 8px 11px;
  }
  .crm-task-check {
    width: 22px; height: 22px; flex-shrink: 0;
    border-radius: 6px; border: 1.5px solid var(--line-strong);
    background: var(--surface); color: #fff; cursor: pointer;
    font-size: 13px; line-height: 1;
    display: flex; align-items: center; justify-content: center; padding: 0;
  }
  .crm-task-check.is-done { border-color: var(--ok); background: var(--ok); }
  .crm-task-label { flex: 1; min-width: 0; font-size: 13.5px; color: var(--text); }
  .crm-task-label.is-done { text-decoration: line-through; color: var(--muted); }
  .crm-task-due { font-size: 12px; color: var(--muted); white-space: nowrap; }
  .crm-task-due.crm-overdue { color: var(--danger-fg); font-weight: 600; }

  /* inline add-row (input + button), handoff lines 1622-1624 / 1630-1638 */
  .crm-addrow { display: flex; gap: 8px; align-items: center; }
  .crm-addrow .crm-input { flex: 1; padding: 9px 11px; font-size: 13.5px; }
  .crm-addrow .crm-select {
    width: 92px; flex-shrink: 0; padding: 9px 6px; font-size: 13px;
  }
  .crm-addrow .crm-date {
    flex-shrink: 0; width: auto;
    border: 1px solid var(--line-strong); border-radius: 9px;
    padding: 9px 8px; font-size: 13.5px;
    background: var(--surface-2); outline: none; color: var(--text);
    font-family: inherit;
  }
  .crm-primary-btn {
    border: none; cursor: pointer;
    background: var(--primary); color: #fff;
    border-radius: 9px; padding: 9px 14px;
    font-size: 13px; font-weight: 600; white-space: nowrap;
    font-family: inherit;
  }
  .crm-primary-btn:hover { background: var(--primary); filter: brightness(1.07); }

  /* activity list (handoff lines 1639-1645) */
  .crm-act {
    display: flex; align-items: baseline; gap: 10px;
    border-bottom: 1px solid var(--line); padding: 8px 2px;
  }
  .crm-act-text { flex: 1; min-width: 0; font-size: 13.5px; color: var(--text); line-height: 1.5; }
  .crm-act-meta { flex-shrink: 0; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

  /* contacts grid (handoff lines 1650-1655) */
  .crm-contact {
    display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px;
    padding: 7px 2px; border-bottom: 1px solid var(--line);
    font-size: 13px; align-items: baseline;
  }
  .crm-contact span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .crm-contact .crm-c-branch { font-weight: 600; }
  .crm-contact .crm-c-contact { color: var(--text-2); }
  .crm-contact .crm-c-phone {
    color: var(--text-2); font-family: var(--font-mono); font-size: 12px;
  }

  /* delivery-history table reuse inside a panel */
  .crm-mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .crm-mini-table th {
    text-align: left; font-size: 11px; font-weight: 700;
    letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
    padding: 4px 6px; border-bottom: 1px solid var(--line);
  }
  .crm-mini-table td { padding: 6px 6px; border-bottom: 1px solid var(--line); }
  .crm-mini-table .crm-mono { font-family: var(--font-mono); }

  /* map inside detail */
  .crm-map { height: 220px; }

  /* tasks-tab groups (handoff lines 1666-1678) */
  .crm-task-groups { display: flex; flex-direction: column; gap: 18px; }
  .crm-task-group { display: flex; flex-direction: column; gap: 8px; max-width: 860px; }
  .crm-task-group .crm-eyebrow.crm-overdue-h { color: var(--danger-fg); }
  .crm-task-group .crm-eyebrow.crm-soon-h { color: var(--warn-fg); }
  .crm-task-row {
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--line); background: var(--surface);
    border-radius: 11px; padding: 10px 13px;
    box-shadow: var(--shadow-card);
  }
  .crm-task-brand {
    border-radius: 6px; padding: 2px 9px;
    font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: var(--primary-soft); color: var(--primary);
    text-decoration: none;
  }
  .crm-task-brand:hover { text-decoration: none; filter: brightness(0.97); }

  .crm-empty { font-size: 13.5px; color: var(--muted); padding: 6px 2px; }

  /* unmanaged customers list (app-only data, styled to match) */
  .crm-unmanaged-head {
    font-size: 13px; font-weight: 700; margin: 4px 0 0;
  }
  .crm-unmanaged {
    display: flex; align-items: center; gap: 10px;
    border: 1px dashed var(--line-strong); background: var(--surface);
    border-radius: 11px; padding: 9px 13px;
  }
  .crm-unmanaged .crm-um-name { font-size: 13.5px; font-weight: 600; flex-shrink: 0; }
  .crm-unmanaged .crm-um-addr {
    flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
}
