/* ============================================================================
   CRM v2 — stand-alone contact-centric CRM on the Signal design language.
   Verbatim translation of docs/design/crm2/CRM.dc.html. Namespaced .cr.
   Full-screen takeover (hosted on <body> by index.aspx, like .pm/.dsp).
   Light default + .cr.dark. Tokens copied verbatim from the design's tokens().
   ============================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

.cr {
    /* shared */
    --brand-50: #EEF1FE; --brand-100: #DDE3FD; --brand-200: #C2CCFB; --brand-400: #7B8FF3; --brand-500: #5E76EE;
    --brand-600: #4C63E6; --brand-700: #3D4FC9; --brand-800: #3340A0; --brand-900: #28297A;
    --brand-grad: linear-gradient(135deg, #5E76EE, #8A63E8);
    --success: #15A06B; --danger: #E04646; --warning: #EE8A2E; --gold: #D99B12; --purple: #8B5CF6; --info: #4C6EF5;
    --r-md: 12px; --r-lg: 16px;
    --e1: 0 1px 2px rgba(20,25,55,.06); --e2: 0 2px 8px rgba(20,25,55,.08);
    --ease: cubic-bezier(.2,.8,.2,1);
    /* light (default) */
    --bg: #F5F6FB; --surface: #FFFFFF; --surface-2: #FAFBFE; --border: #E5E8F2; --border-strong: #D2D7E6;
    --text: #1A1D2E; --text-2: #4A4F63; --muted: #767C92; --faint: #A2A7BC;
    --info-bg: #ECEFFB; --info-fg: #3D4FC9; --ok-bg: #E2F6EE; --ok-fg: #0E6B47;
    --warn-bg: #FCEEDD; --warn-fg: #B5651A; --gold-bg: #FBF1D6; --gold-fg: #8A6A0C;
    --bad-bg: #FCE7E7; --bad-fg: #B3262B; --pur-bg: #EFE9FD; --pur-fg: #6D45C9;
    --pink-bg: #FBE9F1; --pink-fg: #A23070; --neutral-bg: #F1F2F6; --neutral-fg: #6B7080;

    /* In-slot: absolute + inset:0 anchors to the shell's position:relative <main> (above the .scrl overflow
       div, so it isn't clipped), filling the content area. No body-park, no viewport units. */
    position: absolute; inset: 0;
    display: flex !important; flex-direction: column; z-index: 1; overflow-y: auto; overflow-x: hidden;
    background: var(--bg); color: var(--text);
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif; -webkit-font-smoothing: antialiased;
    /* Signal design-body baseline. Without these the module INHERITS the app shell's 13px +
       1.5 line-height and every un-sized element renders ~19% small with inflated vertical
       rhythm (the PM3 shrink bug; measured via e2e/worker-profile/font-probe.js). */
    font-size: 16px; line-height: normal;
}
.cr.dark {
    --bg: #0E1430; --surface: #161E3C; --surface-2: #1B2446; --border: #2A335C; --border-strong: #38436F;
    --text: #EEF1FB; --text-2: #B9C2E0; --muted: #8590B5; --faint: #6B7596;
    --info-bg: rgba(94,118,238,.16); --info-fg: #C2CCFB; --ok-bg: rgba(52,211,153,.15); --ok-fg: #5FE3B0;
    --warn-bg: rgba(238,138,46,.16); --warn-fg: #F0A961; --gold-bg: rgba(217,155,18,.16); --gold-fg: #F2C14E;
    --bad-bg: rgba(224,70,70,.16); --bad-fg: #F58A8A; --pur-bg: rgba(139,92,246,.18); --pur-fg: #C3A8FB;
    --pink-bg: rgba(217,87,160,.18); --pink-fg: #E58FC0; --neutral-bg: rgba(255,255,255,.06); --neutral-fg: #8590B5;
}
.cr * { box-sizing: border-box; }
.cr button, .cr input, .cr select, .cr textarea { font-family: inherit; }
.cr a { color: inherit; }

@keyframes cr-fade { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes cr-pop { 0% { transform: translateY(6px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

/* spinner for async states */
.cr-spin { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--brand-600); border-radius: 50%; display: inline-block; animation: cr-rot .7s linear infinite; }
@keyframes cr-rot { to { transform: rotate(360deg); } }
.cr-rowhover:hover { background: var(--brand-50); }
.cr-cardhover:hover { box-shadow: var(--e2); }
.cr .disabled { opacity: .5; pointer-events: none; }

/* Files drop/browse — same dashed control as #dropbox (.dbx-drop), namespaced for CRM v2 */
.cr .cr-drop { border: 2px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface-2); color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 26px; cursor: pointer;
    transition: border-color .15s ease, background .15s ease, color .15s ease; }
.cr .cr-drop:hover, .cr .cr-drop-over { border-color: var(--brand-400); background: var(--brand-50); color: var(--brand-700); }
.cr .cr-drop-title { font-size: 14px; font-weight: 700; color: var(--text); }
.cr .cr-drop-sub { font-size: 12px; }

/* ============================================================================
   MOBILE BREAKPOINT — register Phase 6 / "CRM Mobile - Build Spec" (resolved
   Jul 10): the design's CRM - Mobile.dc.html is the mobile breakpoint of THIS
   module, not a separate app. Same route, data, permissions — a reflow.
   !important is required: the desktop layout is inline-styled.
   ============================================================================ */
@media (max-width: 768px) {
    .cr { overflow-x: hidden; }

    /* header stacks; search goes full-width under the title (design's list header) */
    .cr .cr-m-head { flex-wrap: wrap !important; gap: 10px !important; padding: 12px 0 !important; }
    .cr .cr-m-search { width: 100% !important; order: 3; margin-left: 0 !important; }

    /* KPI tiles 2-up */
    .cr .cr-m-kpis { grid-template-columns: repeat(2, 1fr) !important; }

    /* list view: the column header disappears and each row becomes a stacked contact
       card (avatar + name line, then the stage/owner/status chips wrap into a footer) */
    .cr .cr-m-listhead { display: none !important; }
    .cr .cr-m-listrow {
        display: flex !important; flex-wrap: wrap; align-items: center;
        gap: 8px 10px !important; margin: 0 10px 10px; padding: 13px 14px !important;
        border: 1px solid var(--border) !important; border-radius: 16px;
        background: var(--surface); box-shadow: var(--e1);
    }
    .cr .cr-m-listrow > :first-child { flex: none; }
    .cr .cr-m-listrow > :nth-child(2) { flex: 1 1 60%; min-width: 0; }
    .cr .cr-m-listrow > :nth-child(n+3) { flex: 0 1 auto; }

    /* detail: main column + 340px sidebar stack full-width */
    .cr .cr-m-detail { grid-template-columns: 1fr !important; }

    /* field grids collapse (4-up/3-up -> 2-up; 2-up -> single column) */
    .cr .cr-m-g4, .cr .cr-m-g3 { grid-template-columns: 1fr 1fr !important; }
    .cr .cr-m-g2, .cr .cr-m-form { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
    .cr .cr-m-g4, .cr .cr-m-g3 { grid-template-columns: 1fr !important; }
}
