@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
    --ink-900: #0b1a2b;
    --ink-800: #102a43;
    --ink-700: #243b53;
    --ink-600: #334e68;
    --ink-500: #486581;
    --ink-400: #627d98;
    --ink-300: #9fb3c8;
    --ink-200: #d9e2ec;
    --ink-100: #eef2f7;
    --ink-050: #f6f8fb;

    --brand-700: #075e45;
    --brand-600: #0b6e4f;
    --brand-500: #128a63;
    --brand-400: #25d366;
    --brand-050: #e7f9f0;

    --danger-600: #b42318;
    --danger-050: #fdeceb;
    --warning-600: #b45309;
    --warning-050: #fdf3e3;

    --surface: #ffffff;
    --page: #f4f7fb;

    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px rgba(16, 42, 67, .06), 0 1px 3px rgba(16, 42, 67, .05);
    --shadow: 0 6px 20px rgba(16, 42, 67, .08);
    --shadow-lg: 0 18px 45px rgba(16, 42, 67, .16);

    --sidebar-width: 268px;
    --topbar-height: 68px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--ink-700);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    color: var(--ink-900);
    letter-spacing: -.015em;
    line-height: 1.2;
}

h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 700; }

p { margin: 0; }

a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-500); }

code {
    font-size: .74rem;
    word-break: break-word;
    color: var(--ink-600);
}

pre {
    max-width: 100%;
    overflow: auto;
    margin: .5rem 0;
    padding: .8rem;
    border-radius: var(--radius-sm);
    background: var(--ink-050);
    border: 1px solid var(--ink-200);
    color: var(--ink-700);
    font-size: .76rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.muted { color: var(--ink-400); font-size: .82rem; }

/* ==========================================================================
   Shell
   ========================================================================== */
.crm-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.crm-sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1.25rem 1rem;
    background: linear-gradient(180deg, var(--ink-900) 0%, #0a2118 100%);
    color: #fff;
    overflow-y: auto;
    z-index: 40;
}

.crm-sidebar .brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .35rem .4rem 1.35rem;
    color: #fff;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
    font-size: 1.2rem;
    color: #04180f;
    box-shadow: 0 6px 18px rgba(37, 211, 102, .35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1rem; font-weight: 700; }
.brand-text small { font-size: .7rem; color: var(--ink-300); letter-spacing: .04em; }

.crm-nav { display: flex; flex-direction: column; gap: 1.1rem; flex: 1; }

.nav-group { display: flex; flex-direction: column; gap: .15rem; }

.nav-group-label {
    padding: 0 .6rem .35rem;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #5b7a8c;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .6rem;
    border-radius: var(--radius-sm);
    color: #c6d5e2;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}

.nav-item i { font-size: 1rem; width: 1.15rem; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }

.nav-item.active {
    background: linear-gradient(90deg, rgba(37, 211, 102, .18), rgba(37, 211, 102, .04));
    color: #fff;
    box-shadow: inset 3px 0 0 var(--brand-400);
}

.nav-item.active i { opacity: 1; color: var(--brand-400); }

.sidebar-footer { padding-top: 1rem; }

.module-state {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .7rem;
    border-radius: var(--radius-sm);
    font-size: .78rem;
    font-weight: 600;
    background: rgba(255, 255, 255, .06);
    color: var(--ink-200);
}

.module-state.on { color: #8ff0bd; }
.module-state.off { color: #ffb4ae; }

.crm-backdrop { display: none; }

.crm-main { display: flex; flex-direction: column; min-width: 0; }

.crm-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--topbar-height);
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--ink-200);
}

.topbar-title { flex: 1; min-width: 0; }

.topbar-title .eyebrow {
    display: block;
    font-size: .78rem;
    color: var(--ink-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: .6rem; }

.topbar-user { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.topbar-user .user-name { font-size: .85rem; font-weight: 600; color: var(--ink-800); }
.topbar-user .user-role { font-size: .7rem; color: var(--ink-400); }

.user-avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand-050);
    color: var(--brand-600);
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-600);
    cursor: pointer;
    transition: all .15s ease;
}

.icon-button:hover { background: var(--ink-050); color: var(--ink-900); }

.menu-toggle { display: none; }

.crm-content { padding: 1.75rem; max-width: 1440px; width: 100%; }

/* ==========================================================================
   Page header
   ========================================================================== */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.35rem;
}

.page-head-main { display: flex; align-items: center; gap: .9rem; }

.page-icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--ink-800), var(--brand-600));
    color: #fff;
    font-size: 1.25rem;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.page-head-main p { margin-top: .2rem; font-size: .85rem; color: var(--ink-400); }

.page-head-actions { display: flex; gap: .55rem; flex-wrap: wrap; }

/* ==========================================================================
   Panels, cards and lists
   ========================================================================== */
.crm-panel {
    padding: 1.15rem;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.crm-panel h2 { margin-bottom: .85rem; }

.card-list { display: grid; gap: 1rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: .9rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto auto;
    gap: .1rem .75rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-card::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--ink-300);
}

.stat-card.positive::before { background: var(--brand-400); }
.stat-card.warning::before { background: #f0a52a; }
.stat-card.danger::before { background: var(--danger-600); }

.stat-icon {
    grid-row: 1 / 3;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--ink-050);
    color: var(--ink-500);
    font-size: 1.05rem;
}

.stat-card.positive .stat-icon { background: var(--brand-050); color: var(--brand-600); }
.stat-card.warning .stat-icon { background: var(--warning-050); color: var(--warning-600); }
.stat-card.danger .stat-icon { background: var(--danger-050); color: var(--danger-600); }

.stat-label { font-size: .74rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-400); }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--ink-900); }
.stat-hint { grid-column: 1 / -1; margin-top: .35rem; font-size: .72rem; color: var(--ink-400); }

.list-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: .55rem 0;
}

.list-row.column { flex-direction: column; align-items: stretch; }
.list-row.bordered { padding: .85rem 0; border-top: 1px solid var(--ink-100); }

.list-row-main { display: flex; flex-direction: column; gap: .12rem; min-width: 0; }
.list-row-main strong { color: var(--ink-900); font-size: .95rem; }
.list-row-main span { font-size: .8rem; color: var(--ink-400); }
.list-row-main small { font-size: .78rem; color: var(--ink-500); }

.template-preview { max-width: 680px; white-space: pre-wrap; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    align-items: start;
}

.settings-grid .crm-panel { margin-bottom: 0; }

.flag {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem 0;
    border-bottom: 1px solid var(--ink-100);
    font-size: .875rem;
}

.flag strong { font-size: .78rem; letter-spacing: .06em; }
.on { color: var(--brand-600); }
.off { color: var(--danger-600); }

/* ==========================================================================
   Pills, alerts, empty and loading states
   ========================================================================== */
.crm-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .28rem .6rem;
    border-radius: 999px;
    background: var(--ink-100);
    color: var(--ink-600);
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
    height: max-content;
}

.crm-pill.ok { background: var(--brand-050); color: var(--brand-700); }
.crm-pill.warning { background: var(--warning-050); color: var(--warning-600); }
.crm-pill.danger { background: var(--danger-050); color: var(--danger-600); }

.crm-alert {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .8rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    border: 1px solid transparent;
}

.crm-alert i { font-size: 1rem; line-height: 1.35; }
.crm-alert.error { background: var(--danger-050); border-color: #f6cdc9; color: #8d1c14; }
.crm-alert.success { background: var(--brand-050); border-color: #b8e6d1; color: var(--brand-700); }

.crm-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    padding: 3rem 1.5rem;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--ink-300);
    border-radius: var(--radius);
    color: var(--ink-400);
}

.crm-empty i { font-size: 1.9rem; color: var(--ink-300); }
.crm-empty h2 { color: var(--ink-700); }
.crm-empty.compact { padding: 1.6rem; border: 0; box-shadow: none; background: transparent; }

.crm-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .8rem;
    padding: 3.5rem 1rem;
    color: var(--ink-400);
}

.crm-loading .spinner-border { color: var(--brand-600); }

.crm-hint { font-size: .78rem; color: var(--ink-400); line-height: 1.5; }

.crm-details { margin: .6rem 0; }

.crm-details > summary {
    cursor: pointer;
    color: var(--brand-600);
    font-weight: 600;
    font-size: .85rem;
    padding: .35rem 0;
}

/* ==========================================================================
   Pipelines (Marketing / Atendimento / Comercial)
   ========================================================================== */
.pipeline-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .22rem .5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .01em;
    white-space: nowrap;
    height: max-content;
}

.pipeline-badge i { font-size: .78rem; }

.pipeline-badge.marketing {
    background: #eef2ff;
    border-color: #c9d3fb;
    color: #3730a3;
}

.pipeline-badge.service {
    background: var(--brand-050);
    border-color: #b8e6d1;
    color: var(--brand-700);
}

.pipeline-badge.commercial {
    background: #fff2e0;
    border-color: #f6d9ae;
    color: #92400e;
}

.badge-stack { display: inline-flex; gap: .25rem; flex-wrap: wrap; }

/* The operator's declaration carries the legal weight: give it presence. */
.attestation {
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    padding: .85rem 1rem;
    margin: .5rem 0;
    border: 1px solid #f6d9ae;
    border-left: 3px solid #d97706;
    border-radius: var(--radius-sm);
    background: #fffbf3;
    font-size: .85rem;
    line-height: 1.5;
    color: #7c4a06;
    cursor: pointer;
}

.attestation input { width: auto; margin-top: .2rem; flex-shrink: 0; }

.detail-pills { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.conversation-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .4rem;
}

/* ==========================================================================
   Contacts: stage chips and retention warning
   ========================================================================== */
.stage-chip {
    display: inline-flex;
    align-items: center;
    gap: .32rem;
    padding: .24rem .6rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    white-space: nowrap;
}

.stage-chip.discovered { background: var(--ink-100); border-color: var(--ink-200); color: var(--ink-600); }
.stage-chip.researching { background: #eef2ff; border-color: #c9d3fb; color: #3730a3; }
.stage-chip.qualified { background: var(--brand-050); border-color: #b8e6d1; color: var(--brand-700); }
.stage-chip.promoted { background: #e8f7ee; border-color: #a7e0bd; color: #14603b; }
.stage-chip.discarded { background: var(--ink-050); border-color: var(--ink-200); color: var(--ink-400); }

.contact-card { display: flex; flex-direction: column; gap: .65rem; }

.contact-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.contact-identity { display: flex; align-items: center; gap: .75rem; min-width: 0; }

.contact-avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--ink-100);
    color: var(--ink-500);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.contact-avatar.business { background: #fff2e0; color: #92400e; }

.contact-identity strong { display: block; color: var(--ink-900); font-size: 1rem; }
.contact-sub { font-size: .8rem; color: var(--ink-400); }

.contact-badges { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }

/* Toolbar of icon actions on each contact card */
.contact-toolbar {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    padding: .5rem 0;
    border-top: 1px solid var(--ink-100);
    border-bottom: 1px solid var(--ink-100);
}

.icon-action {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .42rem .7rem;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-600);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
}

.icon-action:hover:not(:disabled) {
    background: var(--ink-050);
    color: var(--ink-900);
    border-color: var(--ink-300);
}

.icon-action:disabled { opacity: .45; cursor: not-allowed; }
.icon-action i { font-size: .9rem; }

.icon-action .count {
    padding: .05rem .38rem;
    border-radius: 999px;
    background: var(--ink-100);
    font-size: .7rem;
}

.metadata-strip {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    padding: .5rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--brand-050);
    border: 1px solid #c6ecd9;
    font-size: .8rem;
    color: var(--brand-700);
}

.metadata-strip small { margin-left: auto; color: var(--ink-400); }
.metadata-strip.suggestion { margin-top: .6rem; }

/* Stage selector, always visible on the card */
.stage-bar {
    display: flex;
    align-items: flex-end;
    gap: .6rem;
    flex-wrap: wrap;
}

.stage-bar .field { margin-bottom: 0; }
.stage-bar .field.grow { flex: 1; min-width: 160px; }

.qualify-hint {
    display: flex;
    align-items: center;
    gap: .4rem;
    color: var(--warning-600);
}

/* Promotion: the two paths side by side */
.promote-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    padding-top: .6rem;
    border-top: 1px solid var(--ink-100);
}

.promote-label {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-400);
}

.crm-button.commercial {
    background: linear-gradient(135deg, #b45309, #d97706);
    color: #fff;
}

.crm-button.commercial:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(180, 83, 9, .28);
}

.crm-button.marketing {
    background: linear-gradient(135deg, #3730a3, #4f46e5);
    color: #fff;
}

.crm-button.marketing:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(55, 48, 163, .28);
}

.crm-button.disabled-link {
    opacity: .45;
    cursor: not-allowed;
    pointer-events: none;
}

.independence-note {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .6rem;
    padding: .6rem .8rem;
    border-radius: var(--radius-sm);
    background: var(--warning-050);
    border: 1px solid #f6d9ae;
    color: var(--warning-600);
    font-size: .82rem;
}

.independence-note.independent {
    background: var(--brand-050);
    border-color: #b8e6d1;
    color: var(--brand-700);
}

/* ==========================================================================
   Groups: policy card
   ========================================================================== */
.group-list { display: grid; gap: 1rem; }

.group-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--ink-200);
    border-left: 3px solid var(--ink-300);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.group-card.active { border-left-color: var(--brand-500); }
.group-card.inactive { border-left-color: var(--ink-300); }

.group-head {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--ink-100);
}

.group-avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--ink-050);
    color: var(--ink-500);
    font-size: 1.05rem;
    flex-shrink: 0;
}

.group-card.active .group-avatar { background: var(--brand-050); color: var(--brand-600); }

.group-title { flex: 1; min-width: 0; }

.group-title h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink-900);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-stats {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: .2rem;
    font-size: .78rem;
    color: var(--ink-400);
    flex-wrap: wrap;
}

.group-stats i { margin-right: .2rem; }

.group-stats code {
    padding: .1rem .35rem;
    border-radius: 5px;
    background: var(--ink-050);
    font-size: .7rem;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-status { display: flex; gap: .35rem; flex-shrink: 0; }

.status-pill {
    padding: .28rem .65rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
}

.status-pill.on { background: var(--brand-050); color: var(--brand-700); }
.status-pill.off { background: var(--danger-050); color: var(--danger-600); }
.status-pill.warn { background: var(--warning-050); color: var(--warning-600); }

/* Three policy blocks side by side, each with its own rhythm */
.group-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.15rem;
    padding: 1.15rem;
}

.policy-block { display: flex; flex-direction: column; gap: .55rem; }

.policy-legend {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ink-400);
}

/* Toggle switch reads as on/off far better than a bare checkbox */
.switch-row {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    cursor: pointer;
}

input.switch {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 36px;
    height: 20px;
    margin: .1rem 0 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--ink-200);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .18s ease;
}

input.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(16, 42, 67, .3);
    transition: transform .18s ease;
}

input.switch:checked { background: var(--brand-500); }
input.switch:checked::after { transform: translateX(16px); }
input.switch:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

.switch-text { display: flex; flex-direction: column; gap: .1rem; line-height: 1.35; }
.switch-text strong { font-size: .85rem; font-weight: 600; color: var(--ink-800); }
.switch-text small { font-size: .75rem; color: var(--ink-400); }

.number-row { display: flex; gap: .6rem; margin-top: .2rem; }
.number-row .field { margin-bottom: 0; flex: 1; }

.suffix-input { position: relative; display: flex; align-items: center; }
.suffix-input input { padding-right: 3rem; }

.suffix-input em {
    position: absolute;
    right: .7rem;
    font-size: .74rem;
    font-style: normal;
    color: var(--ink-400);
    pointer-events: none;
}

.evidence-field {
    margin: 0 1.15rem 1.15rem;
    padding: .8rem;
    border-radius: var(--radius-sm);
    background: var(--warning-050);
    border: 1px solid #f6d9ae;
}

.evidence-field > span { color: #92400e; }

.requirement-list {
    margin: 0 1.15rem 1.15rem;
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--ink-050);
    border: 1px solid var(--ink-200);
}

.requirement-title {
    display: block;
    margin-bottom: .5rem;
    font-size: .78rem;
    font-weight: 600;
    color: var(--ink-600);
}

.requirement-list ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .3rem .9rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.requirement-list li {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    color: var(--ink-500);
}

.requirement-list li i { color: var(--ink-300); font-size: .85rem; }
.requirement-list li.met { color: var(--brand-700); }
.requirement-list li.met i { color: var(--brand-500); }

.group-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .85rem 1.15rem;
    border-top: 1px solid var(--ink-100);
    background: var(--ink-050);
}

.sync-info {
    display: flex;
    align-items: center;
    gap: .9rem;
    flex-wrap: wrap;
    font-size: .78rem;
    color: var(--ink-500);
}

.sync-info i { margin-right: .25rem; color: var(--ink-300); }
.sync-error { color: var(--danger-600); }
.sync-error i { color: var(--danger-600); }

.group-actions { display: flex; gap: .5rem; }

@media (max-width: 720px) {
    .group-head { flex-wrap: wrap; }
    .group-status { width: 100%; }
    .group-foot { flex-direction: column; align-items: stretch; }
    .group-actions { flex-direction: column; }
    .group-actions .crm-button { width: 100%; }
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: rgba(11, 26, 43, .55);
    backdrop-filter: blur(2px);
    overflow-y: auto;
}

.modal-panel {
    display: flex;
    flex-direction: column;
    width: min(560px, 100%);
    max-height: calc(100vh - 3rem);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-panel.wide { width: min(760px, 100%); }
.modal-panel:focus { outline: none; }

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--ink-200);
}

.modal-title { display: flex; align-items: center; gap: .75rem; }
.modal-title h2 { font-size: 1.05rem; }
.modal-title p { margin-top: .15rem; font-size: .82rem; color: var(--ink-400); }

.modal-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--ink-800), var(--brand-600));
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.modal-body { padding: 1.25rem; overflow-y: auto; }

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: .55rem;
    padding: .9rem 1.25rem;
    border-top: 1px solid var(--ink-200);
    background: var(--ink-050);
}

@media (max-width: 720px) {
    .modal-foot { flex-direction: column-reverse; }
    .modal-foot .crm-button { width: 100%; }
    .contact-toolbar { flex-direction: column; align-items: stretch; }
    .icon-action { justify-content: center; }
    .promote-bar .crm-button { flex: 1; }
}

.contact-meta { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; }

.source-list { display: flex; align-items: center; gap: .4rem; color: var(--ink-500); }
.source-list i { color: var(--ink-300); }

.retention-warning {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--warning-050);
    border: 1px solid #f6d9ae;
    color: var(--warning-600);
    font-size: .8rem;
}

.contact-detail {
    padding-top: .8rem;
    margin-top: .3rem;
    border-top: 1px solid var(--ink-100);
}

.contact-detail h3 {
    margin: .9rem 0 .4rem;
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ink-400);
}

.source-timeline { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }

.source-timeline li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
    padding: .55rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--ink-050);
    font-size: .82rem;
}

.source-timeline small { flex-basis: 100%; color: var(--ink-500); }

.pipeline-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .9rem;
}

.pipeline-column {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    padding: .9rem;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-sm);
    background: var(--ink-050);
}

.pipeline-column dl { display: grid; gap: .3rem; margin: 0; }

.pipeline-column dl > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
}

.pipeline-column dt { font-size: .78rem; color: var(--ink-500); }
.pipeline-column dd { margin: 0; font-size: .95rem; font-weight: 700; color: var(--ink-900); }

.pipeline-filter {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.pipeline-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .75rem;
    border: 1px solid var(--ink-200);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-600);
    font-family: inherit;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
}

.pipeline-chip:hover { background: var(--ink-050); }

.pipeline-chip.selected {
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}

.pipeline-chip.selected:not(.marketing):not(.service):not(.commercial) {
    background: var(--ink-800);
    color: #fff;
}

.pipeline-chip.marketing.selected { background: #eef2ff; color: #3730a3; border-color: #c9d3fb; }
.pipeline-chip.service.selected { background: var(--brand-050); color: var(--brand-700); border-color: #b8e6d1; }
.pipeline-chip.commercial.selected { background: #fff2e0; color: #92400e; border-color: #f6d9ae; }

/* ==========================================================================
   Forms and controls
   ========================================================================== */
.crm-toolbar {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.search-input {
    position: relative;
    flex: 1;
    min-width: 220px;
}

.search-input i {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ink-300);
    font-size: .9rem;
}

.search-input input { padding-left: 2.15rem; }

.filter-input { min-width: 200px; }

input, select, textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-800);
    font-family: inherit;
    font-size: .875rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.crm-toolbar select, .crm-toolbar input { width: auto; min-width: 180px; }
.crm-toolbar .search-input, .crm-toolbar .search-input input { width: auto; }
.crm-toolbar .search-input input { width: 100%; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(18, 138, 99, .12);
}

input[readonly], textarea[readonly] { background: var(--ink-050); color: var(--ink-500); }

textarea { resize: vertical; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }

.field > span {
    font-size: .78rem;
    font-weight: 600;
    color: var(--ink-600);
}

.field.check {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
    min-height: 42px;
}

.field.check input { width: auto; }
.field.check span { font-weight: 500; }

.field-input { position: relative; display: flex; align-items: center; }

.field-input i {
    position: absolute;
    left: .8rem;
    color: var(--ink-300);
    font-size: .95rem;
}

.field-input input { padding-left: 2.25rem; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: .25rem .9rem;
    margin: .85rem 0;
}

.form-grid.two { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }

.crm-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; margin: .6rem 0; }

.table-actions { display: flex; gap: .35rem; flex-wrap: wrap; min-width: 140px; }

.crm-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .58rem .95rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--brand-600), var(--brand-500));
    color: #fff;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: transform .12s ease, box-shadow .15s ease, background .15s ease;
}

.crm-button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(11, 110, 79, .28);
}

.crm-button.secondary {
    background: var(--surface);
    border-color: var(--ink-200);
    color: var(--ink-700);
}

.crm-button.secondary:hover:not(:disabled) { background: var(--ink-050); box-shadow: var(--shadow-sm); }

.crm-button.ghost {
    background: transparent;
    border-color: var(--ink-200);
    color: var(--ink-600);
}

.crm-button.ghost:hover:not(:disabled) { background: var(--surface); box-shadow: none; }

.crm-button.danger {
    background: linear-gradient(135deg, #9f1d13, var(--danger-600));
    color: #fff;
}

.crm-button.danger:hover:not(:disabled) { box-shadow: 0 6px 16px rgba(180, 35, 24, .28); }

.crm-button.block { width: 100%; }

.crm-button:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.crm-link {
    padding: .2rem .1rem;
    border: 0;
    background: transparent;
    color: var(--brand-600);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.crm-link:hover:not(:disabled) { text-decoration: underline; }
.crm-link:disabled { opacity: .45; cursor: not-allowed; }
.crm-link.danger-text, .danger-text { color: var(--danger-600); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; padding: .35rem; }

table { width: 100%; border-collapse: collapse; font-size: .85rem; }

th {
    padding: .7rem .8rem;
    text-align: left;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-400);
    border-bottom: 1px solid var(--ink-200);
    white-space: nowrap;
}

td {
    padding: .8rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--ink-100);
}

tbody tr:hover { background: var(--ink-050); }
tbody tr:last-child td { border-bottom: 0; }

td strong { display: block; color: var(--ink-900); }
td small { display: block; margin-top: .15rem; font-size: .74rem; color: var(--ink-400); }

.crm-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: .5rem 0 1.5rem;
    font-size: .82rem;
    color: var(--ink-500);
}

/* ==========================================================================
   Inbox
   ========================================================================== */
.inbox-layout {
    display: grid;
    grid-template-columns: minmax(260px, 34%) 1fr;
    gap: 1rem;
    align-items: start;
}

.conversation-list { padding: .6rem; max-height: 74vh; overflow-y: auto; margin-bottom: 0; }
.conversation-list .crm-toolbar { margin-bottom: .6rem; }

.conversation {
    display: flex;
    flex-direction: column;
    gap: .12rem;
    width: 100%;
    padding: .75rem;
    text-align: left;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    transition: background .15s ease;
}

.conversation:hover { background: var(--ink-050); }
.conversation.selected { background: var(--brand-050); box-shadow: inset 3px 0 0 var(--brand-500); }
.conversation strong { font-size: .9rem; color: var(--ink-900); }
.conversation span { font-size: .74rem; color: var(--ink-400); }

.conversation small {
    font-size: .78rem;
    color: var(--ink-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-detail { max-height: 74vh; overflow-y: auto; margin-bottom: 0; }

.conversation-context { padding-bottom: .75rem; border-bottom: 1px solid var(--ink-100); }
.context-facts { display: grid; gap: .25rem; margin: .5rem 0; font-size: .85rem; }
.composer { display: grid; gap: .5rem; justify-items: start; margin-top: .5rem; }
.composer textarea { width: 100%; }

.message-thread { display: flex; flex-direction: column; gap: .6rem; padding-top: .9rem; }

.message {
    max-width: 78%;
    padding: .7rem .85rem;
    border-radius: var(--radius);
    background: var(--ink-050);
    border: 1px solid var(--ink-100);
}

.message.outbound {
    align-self: flex-end;
    background: var(--brand-050);
    border-color: #c6ecd9;
}

.message p { margin: .3rem 0; font-size: .875rem; }
.message .message-meta, .message time { font-size: .68rem; color: var(--ink-400); }

.reason { margin: .5rem 0; font-size: .9rem; }

/* ==========================================================================
   Authentication
   ========================================================================== */
.auth-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: radial-gradient(1200px 600px at 15% -10%, #123c2c 0%, transparent 60%),
                linear-gradient(135deg, var(--ink-900), #071a12);
}

.auth-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: min(900px, 100%);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-aside {
    display: flex;
    flex-direction: column;
    gap: .9rem;
    padding: 2.5rem 2rem;
    background: linear-gradient(160deg, var(--ink-800), var(--brand-700));
    color: #fff;
}

.auth-aside h2 { color: #fff; font-size: 1.5rem; }
.auth-aside p { font-size: .87rem; color: #cfe6dc; line-height: 1.6; }

.auth-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .12);
    font-size: 1.6rem;
}

.auth-highlights { display: grid; gap: .5rem; margin: .8rem 0 0; padding: 0; list-style: none; }

.auth-highlights li {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-size: .84rem;
    color: #e4f4ec;
}

.auth-highlights i { color: var(--brand-400); }

.auth-form { padding: 2.5rem 2rem; }

.auth-badge {
    display: inline-block;
    padding: .25rem .6rem;
    margin-bottom: .8rem;
    border-radius: 999px;
    background: var(--brand-050);
    color: var(--brand-700);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.auth-lead { margin: .35rem 0 1.4rem; font-size: .875rem; color: var(--ink-400); }

.auth-card.not-found {
    grid-template-columns: 1fr;
    padding: 3rem 2rem;
    text-align: center;
    display: grid;
    justify-items: center;
    gap: .6rem;
}

/* ==========================================================================
   Blazor error UI
   ========================================================================== */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: .8rem 1.25rem;
    background: #fff3cd;
    color: #664d03;
    font-size: .85rem;
    box-shadow: 0 -2px 12px rgba(16, 42, 67, .12);
}

#blazor-error-ui .dismiss { position: absolute; top: .5rem; right: .9rem; cursor: pointer; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
    .form-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

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

    .crm-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform .22s ease;
    }

    .crm-shell.menu-open .crm-sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }

    .crm-shell.menu-open .crm-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgba(11, 26, 43, .45);
    }

    .menu-toggle { display: grid; }
    .crm-content { padding: 1.15rem; }
    .inbox-layout { grid-template-columns: 1fr; }
    .conversation-list, .conversation-detail { max-height: none; }
}

@media (max-width: 720px) {
    .page-head { flex-direction: column; align-items: stretch; }
    .form-grid, .form-grid.two { grid-template-columns: 1fr; }
    .crm-toolbar { flex-direction: column; align-items: stretch; }
    .crm-toolbar select, .crm-toolbar input, .crm-toolbar .search-input { width: 100%; min-width: 0; }
    .crm-actions { flex-direction: column; align-items: stretch; }
    .crm-actions .crm-button { width: 100%; }
    .auth-card { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .topbar-user { display: none; }
    .crm-pagination { flex-direction: column; gap: .6rem; }
    .message { max-width: 92%; }
}
