/*
 * Atlas · Customers.
 *
 * Tokens, buttons, tables, forms, badges, modals and the header/nav strip all
 * come from css/admin-shell.css and the dashboard's own chrome — this file
 * holds only what is specific to a list-and-record layout, which the
 * tab-and-table dashboard has no equivalent of.
 *
 * The page header is the dashboard's `.header` + `.nav-tabs`, not a bespoke
 * one, so moving between the surfaces does not feel like changing application.
 */

/* The nav tabs are links here rather than buttons; the dashboard styles them
   as buttons, so restate only what an anchor does not inherit. */
.nav-tabs a.nav-tab {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.crm-auth-notice { padding: 60px 24px; }

/* Two panes on a desktop, stacked on a phone. */
.crm-shell {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 20px;
    padding: 20px 24px 48px;
    align-items: start;
}

/* The pane sits below the sticky staff bar, whose measured height
   admin-shell.js sets in --admin-header-height. The pane never grows past the
   viewport, and the list takes the height that is left, so the last rows
   stay reachable. 68px = the 20px gap above the pane + the 48px padding
   under the shell, so at the end of the page the pane does not go under the
   staff bar. */
.crm-list-pane {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--admin-header-height, 61px) - 68px);
    overflow: hidden;
    position: sticky;
    top: calc(var(--admin-header-height, 61px) + 20px);
}

.crm-list-pane > * { flex: none; }

.crm-list-controls { padding: 12px; border-bottom: 1px solid var(--border-color); }

.crm-list-controls input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
}

.crm-conflict-banner {
    margin: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 193, 7, 0.4);
    background: rgba(255, 193, 7, 0.12);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.45;
}
.crm-conflict-banner summary { cursor: pointer; }
.crm-conflict-list { margin-top: 10px; max-height: 360px; overflow-y: auto; }
.crm-conflict-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.crm-conflict-actions select { min-width: min(280px, 100%); }


.crm-list-pane > .crm-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

.crm-list-empty { padding: 24px 16px; color: var(--text-muted); font-size: 14px; text-align: center; }

.crm-list-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
}

.crm-list-item:hover { background: var(--bg-tertiary); }
.crm-list-item.active { background: var(--bg-tertiary); box-shadow: inset 3px 0 0 var(--accent-blue); }
.crm-list-item-name { font-weight: 600; display: block; }
.crm-list-item-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; display: block; }
.crm-list-item.is-inactive .crm-list-item-name { color: var(--text-secondary); }

.crm-record-pane { min-width: 0; }

.crm-record-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.crm-record-header h2 { font-size: 22px; font-weight: 700; }

/* Linked: this customer in the other tools, each row with Open. */
.crm-linked {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
}
.crm-linked-title {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding: 10px 14px 2px;
}
.crm-linked-rows {
    list-style: none;
}
.crm-linked-row {
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    min-height: 48px;
    padding: 6px 14px;
}
.crm-linked-row:last-child {
    border-bottom: 0;
}
.crm-linked-icon {
    color: var(--text-secondary);
}
.crm-linked-icon svg {
    height: 20px;
    width: 20px;
}
.crm-linked-text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}
.crm-linked-label {
    font-size: 14px;
    font-weight: 500;
}
.crm-linked-detail {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crm-linked-row .staff-chip {
    margin-left: 0;
}
.crm-linked-open {
    flex: none;
    min-height: 36px;
}

.crm-stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.crm-stat {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
}

/* One stat card style in Atlas: the record stats and the Prospects
   acquisition summary. Sentence-case labels, as on the admin dashboard. */
.crm-stat-value { font-size: 22px; font-weight: 700; }
.crm-stat-label { font-size: 13px; color: var(--text-secondary); }

.crm-tabs { margin-bottom: 16px; }
.crm-tab-panel { min-width: 0; }

.crm-filter-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }

.crm-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
}

.crm-filter input { accent-color: var(--accent-blue); }

/* A refresh failed and the page is showing the last data that arrived. */
.crm-stale::after {
    content: ' · not refreshed';
    color: var(--status-warning-text);
}

.crm-skipped {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 107, 53, 0.4);
    background: rgba(255, 107, 53, 0.12);
    font-size: 13px;
}

.crm-timeline { list-style: none; margin: 0; padding: 0; }

.crm-timeline-item {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr);
    gap: 14px;
    padding: 0 0 18px;
    position: relative;
}

/* The rail is drawn on the marker rather than the row so the last item does not
   trail a line into empty space. */
.crm-timeline-item::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 16px;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.crm-timeline-item:last-child::before { display: none; }

.crm-timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 4px;
    background: var(--accent-grey);
    position: relative;
    z-index: 1;
}

.crm-timeline-item[data-kind="note"] .crm-timeline-dot { background: var(--accent-yellow); }
.crm-timeline-item[data-kind="activity"] .crm-timeline-dot { background: var(--accent-blue); }
.crm-timeline-item[data-kind="call"] .crm-timeline-dot { background: var(--accent-green); }
.crm-timeline-item[data-kind="invoice"] .crm-timeline-dot { background: var(--accent-purple); }
.crm-timeline-item[data-kind="payment"] .crm-timeline-dot { background: var(--accent-indigo); }

.crm-timeline-body { min-width: 0; }
.crm-timeline-title { font-weight: 600; font-size: 14px; }
.crm-timeline-detail { color: var(--text-secondary); font-size: 13px; margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-timeline-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.crm-timeline-footer { display: flex; align-items: center; gap: 12px; padding-top: 8px; }

.crm-note-form {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 16px;
}

.crm-note-form textarea {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 16px;
    resize: vertical;
}

.crm-note-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.crm-pin-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }

.crm-note {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}

.crm-note.is-pinned { border-color: rgba(255, 193, 7, 0.5); }
.crm-note-body { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-note-meta { color: var(--text-muted); font-size: 12px; margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.crm-note-meta button { background: none; border: none; color: var(--accent-blue); cursor: pointer; font-size: 12px; padding: 0; }
.crm-note-meta button.danger { color: var(--accent-red); }

.crm-record-conflicts { margin-top: 18px; }

.crm-conflict {
    border: 1px solid rgba(255, 193, 7, 0.35);
    background: rgba(255, 193, 7, 0.08);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 13px;
}


@media (max-width: 900px) {
    .crm-shell { grid-template-columns: minmax(0, 1fr); padding: 16px; }
    .crm-list-pane { max-height: none; position: static; }
    .crm-list { max-height: 320px; }
    .crm-header { padding: 12px 16px; flex-wrap: wrap; }
}

.crm-record-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.crm-pending-operations {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid var(--status-warning-border, var(--border-color));
    border-radius: 9px;
    background: var(--status-warning-bg, var(--bg-secondary));
    color: var(--text-secondary);
    font-size: 13px;
}
.crm-pending-operation { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Atlas acquisition dashboard and sales activity. The stat cards and the
   pipeline detail sit above the list and the record, not in the list pane. */
.crm-acquisition-dashboard { padding: 20px 24px 0; }
.crm-acquisition-dashboard:empty { display: none; }
.crm-acquisition-dashboard .crm-stat-row { margin-bottom: 12px; }
.crm-dashboard-detail {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 10px 14px;
}
.crm-dashboard-detail summary { cursor: pointer; color: var(--text-primary); font-weight: 600; }
.crm-dashboard-sections {
    display: grid;
    gap: 0 24px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.crm-dashboard-section { margin-top: 12px; min-width: 0; }
.crm-dashboard-section ul { margin: 6px 0 0; padding: 0; list-style: none; }
.crm-dashboard-section li,
.crm-dashboard-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 5px; }
.crm-dashboard-section time { white-space: nowrap; color: var(--text-muted); }
.crm-dashboard-link {
    min-width: 0;
    border: 0;
    padding: 0;
    background: none;
    color: var(--accent-blue);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.crm-dashboard-link:hover { text-decoration: underline; }
.crm-dashboard-section li > span:last-child { flex: 0 0 auto; color: var(--text-muted); text-align: right; }
.crm-source-row { display: grid; grid-template-columns: minmax(70px, 1fr) 1.2fr auto; gap: 7px; align-items: center; margin-top: 6px; }
.crm-source-bar { height: 5px; overflow: hidden; border-radius: 99px; background: var(--border-color); }
.crm-source-bar i { display: block; height: 100%; border-radius: inherit; background: var(--status-info); }
.crm-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.crm-import-preview { max-height: 300px; overflow-y: auto; margin-top: 12px; }
.crm-import-duplicate { opacity: 0.58; }
.crm-activity-section + .crm-activity-section { margin-top: 22px; }
.crm-activity-section h3 { margin: 0 0 10px; font-size: 15px; }
.crm-sales-event { border-left: 3px solid var(--accent-blue); padding: 8px 10px; margin-bottom: 8px; background: var(--bg-secondary); border-radius: 0 8px 8px 0; }
.crm-sales-event.is-blocked { border-left-color: var(--accent-red); }
.crm-sequence-list { display: grid; gap: 10px; }
.crm-sequence-card { border: 1px solid var(--border-color); border-radius: 10px; padding: 12px; background: var(--bg-secondary); }
.crm-sequence-card h3 { margin: 0 0 5px; font-size: 15px; }
.crm-sequence-steps { margin: 8px 0; padding-left: 20px; color: var(--text-secondary); }
.crm-sequence-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.crm-form-stack { display: grid; gap: 12px; }
.crm-form-stack label { display: grid; gap: 6px; color: var(--text-secondary); }
.crm-form-stack input, .crm-form-stack select, .crm-form-stack textarea { min-height: 44px; }

@media (max-width: 900px) {
    .crm-acquisition-dashboard { padding: 16px 16px 0; }
}

@media (max-width: 600px) {
    .crm-form-grid { grid-template-columns: 1fr; }
}

/* Hand-off out of the record and into the surface that acts on the thing. */
.crm-timeline-link {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-blue);
    text-decoration: none;
    margin-left: 8px;
}

.crm-timeline-link:hover { text-decoration: underline; }

/* ── Health ───────────────────────────────────────────────────────────────
   Band colours run cool-to-warm rather than red/green alone: "cooling" is a
   prompt, not a failure, and painting it red teaches operators to ignore it. */

.crm-band-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.crm-band-chip {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.crm-band-chip:hover { color: var(--text-primary); }
.crm-band-chip.active { background: var(--accent-blue); border-color: var(--accent-blue); color: var(--color-action-primary-text); }

/* The band and the prospect stage are the shared .status-badge with the tone
   from vrs-status-tokens.js (healthBandToneClass, statusToneClass). In a list
   row the badge is shorter, so the rows stay dense. */
.crm-list-item .status-badge {
    margin-top: 6px;
    padding: 3px 10px;
}

.crm-health-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.crm-health-panel:empty { display: none; }
.crm-health-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.crm-health-reasons { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-secondary); }
.crm-health-reasons li { margin-bottom: 2px; }

.crm-timeline-item[data-kind="touchpoint"] .crm-timeline-dot { background: var(--accent-orange); }

/* ── Tasks ────────────────────────────────────────────────────────────── */

.crm-note-form input[type="text"],
.crm-note-form input:not([type="checkbox"]):not([type="date"]) {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 16px;
}

.crm-note-form input[type="date"] {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 8px 10px;
    font-size: 14px;
    /* The date picker follows the Light or Dark appearance on the root. */
    color-scheme: inherit;
}

.crm-task {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}

/* Closed tasks stay visible but recede: the record is the history of what was
   done as much as what is outstanding. */
.crm-task.is-closed { opacity: 0.55; }
.crm-task.is-closed .crm-task-title { text-decoration: line-through; }

.crm-task-main { min-width: 0; }
.crm-task-title { font-size: 14px; font-weight: 600; }
.crm-task-detail { font-size: 13px; color: var(--text-secondary); margin-top: 3px; overflow-wrap: anywhere; }
.crm-task-meta { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.crm-task-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Tells a reader a rule wrote this, not a colleague. */
.crm-task-auto {
    color: var(--accent-blue);
    font-weight: 600;
}

/* ── AI-generated text ────────────────────────────────────────────────────
   Visually distinct from everything else on the record, because everything
   else is something a person did or a system observed. */

.crm-brief {
    background: rgba(124, 124, 240, 0.08);
    border: 1px solid rgba(124, 124, 240, 0.35);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.crm-brief:empty { display: none; }

.crm-brief-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

.crm-ai-tag {
    background: var(--status-indigo-soft);
    color: var(--status-indigo-text);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.crm-brief-body { font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-brief-empty { color: var(--text-muted); }
.crm-brief-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.crm-draft {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(124, 124, 240, 0.25);
}

.crm-draft-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.crm-draft .crm-brief-meta { margin-top: 0; }
.crm-draft .crm-task-actions { margin-top: 10px; }

/* Not a worse "dormant" — a different claim entirely. Neutral, so it does not
   read as a warning about the customer when it is a gap in our own records.
   The tone is the shared grey; the dashed edge tells it apart from Dormant. */
.status-badge.crm-health-unlinked {
    border: 1px dashed var(--color-control-border);
}

/* Persistent action/read feedback uses the shared admin semantic palette. */
.crm-feedback { margin: 12px; color: var(--text-secondary); overflow-wrap: anywhere; }
.crm-feedback[data-tone="error"] { color: var(--status-danger-text); }
.crm-feedback[data-tone="success"] { color: var(--status-success-text); }
.crm-note-form > label { font-weight: 600; color: var(--text-primary); }
.crm-note-form button, .crm-note-form input, .crm-task-actions button,
.crm-note-meta button, .crm-record-header-actions .btn, .crm-brief-head button,
#crmOwnerChoice, #crmOwnerSave { min-height: 44px; }

.crm-note-meta button { min-width: 44px; }
.crm-record-header > div { min-width: 0; }
.crm-record-header h2 { overflow-wrap: anywhere; }
@media (max-width: 767px) {
    .crm-record-header { flex-direction: column; align-items: stretch; }
}

/* Keep linked identity and its source action together on phone-sized screens. */
.crm-people-help { font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
#crmPeopleBody td { overflow-wrap: anywhere; }
#crmPeopleBody .btn { display: inline-flex; align-items: center; min-height: 44px; }
@media (max-width: 767.98px) {
    #crmPanel-people table { width: 100%; table-layout: fixed; }
    #crmPanel-people thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
    #crmPeopleBody tr { display: grid; grid-template-columns: minmax(0, 1fr); padding: 12px; border-bottom: 1px solid var(--border-color); }
    #crmPeopleBody td { display: block; min-width: 0; padding: 6px 0; border: 0; }
    #crmPeopleBody td:first-child { font-weight: 600; }
}
