/* CRM v2 design system foundation (May 2026 redesign).
   9 component primitives. Built on global brand tokens (--color-*).
   Anchored at #2C3E50. Aligned with GWS. */

:root {
    --crm-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --crm-card-radius: 10px;
    --crm-card-padding: 1.1rem;
}

.crm-v2 {
    background: var(--color-background);
    color: var(--color-text-primary);
    font-family: var(--font-family-primary);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.crm-v2 .container,
.crm-v2 .container-fluid { background: transparent; }

/* 1. Page header */
.crm-page-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.25rem 0 1rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
}
.crm-page-header__breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
}
.crm-page-header__breadcrumb a { color: var(--color-text-secondary); text-decoration: none; }
.crm-page-header__breadcrumb a:hover { color: var(--color-brand-primary); }
.crm-page-header__breadcrumb__sep { opacity: 0.4; }
.crm-page-header__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.crm-page-header__title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
    line-height: 1.2;
}
.crm-page-header__subtitle {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin: 0.15rem 0 0;
}
.crm-page-header__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* 2. Card */
.crm-card {
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--crm-card-radius);
    padding: var(--crm-card-padding);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--crm-transition), box-shadow var(--crm-transition), transform var(--crm-transition);
}
.crm-card--clickable { cursor: pointer; }
.crm-card--clickable:hover {
    border-color: var(--color-brand-primary);
    box-shadow: var(--crm-shadow-hover);
    transform: translateY(-1px);
}
.crm-card--flat { box-shadow: none; }
.crm-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: -0.1rem 0 0.75rem;
}
.crm-card__title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
    line-height: 1.3;
}
.crm-card__subtitle {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin: 0.1rem 0 0;
    font-weight: 400;
}
.crm-card--metric { box-shadow: none; padding: 0.85rem 1rem; }
.crm-card--metric .crm-card__label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    margin: 0 0 0.25rem;
}
.crm-card--metric .crm-card__value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.crm-card--metric .crm-card__delta {
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: 0.25rem;
    font-variant-numeric: tabular-nums;
}
.crm-card--metric .crm-card__delta--up { color: var(--color-success); }
.crm-card--metric .crm-card__delta--down { color: var(--color-error); }

/* 3. Table */
.crm-table-wrapper {
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--crm-card-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.crm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin: 0;
}
.crm-table thead th {
    background: var(--color-brand-primary);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.65rem 0.75rem;
    border: none;
    white-space: nowrap;
    text-align: left;
    height: 38px;
    position: sticky;
    top: 0;
    z-index: 2;
}
.crm-table thead th.crm-table__th--right { text-align: right; }
.crm-table thead th.crm-table__th--center { text-align: center; }
.crm-table tbody td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-primary);
    vertical-align: middle;
}
.crm-table tbody td.crm-table__td--right { text-align: right; }
.crm-table tbody td.crm-table__td--center { text-align: center; }
.crm-table tbody td.crm-table__td--num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.crm-table tbody tr:nth-child(even) td { background: var(--crm-row-stripe); }
.crm-table tbody tr:hover td { background: var(--crm-row-hover); }
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table thead th.crm-table__th--sortable { cursor: pointer; user-select: none; }
.crm-table thead th.crm-table__th--sortable:hover { background: #1a2836; }
.crm-table__th__sort-icon { margin-left: 0.4rem; opacity: 0.6; }
.crm-table thead th.crm-table__th--sorted .crm-table__th__sort-icon { opacity: 1; }

/* 4. Tab nav */
.crm-tab-nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.crm-tab-nav__tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    background: #ffffff;
    color: var(--color-brand-primary);
    border: 1.5px solid var(--color-border);
    border-radius: var(--crm-card-radius);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--crm-transition);
    text-decoration: none;
    line-height: 1.2;
}
.crm-tab-nav__tab:hover {
    border-color: var(--color-brand-primary);
    color: var(--color-brand-primary);
}
.crm-tab-nav__tab--active,
.crm-tab-nav__tab.active {
    background: var(--color-brand-primary);
    color: #ffffff;
    border-color: var(--color-brand-primary);
    box-shadow: 0 4px 10px rgba(44, 62, 80, 0.20);
}
.crm-tab-nav__tab__count {
    display: inline-block;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 0.05rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
}
.crm-tab-nav__tab--active .crm-tab-nav__tab__count {
    background: rgba(255, 255, 255, 0.18);
}
.crm-tab-nav--sticky {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--color-background);
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
    margin: 0 -1rem 1.25rem;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* 5. Modal */
.crm-modal .modal-content {
    border: 1px solid var(--color-border);
    border-radius: var(--crm-card-radius);
    box-shadow: var(--shadow-lg);
}
.crm-modal .modal-header {
    background: var(--color-brand-primary);
    color: #ffffff;
    padding: 1rem 1.25rem;
    border-bottom: none;
    border-radius: var(--crm-card-radius) var(--crm-card-radius) 0 0;
}
.crm-modal .modal-title {
    color: #ffffff;
    font-size: 1.0625rem;
    font-weight: 600;
}
.crm-modal .modal-header .btn-close {
    filter: invert(1) brightness(2);
    opacity: 0.85;
}
.crm-modal .modal-header .btn-close:hover { opacity: 1; }
.crm-modal .modal-body {
    padding: 1.25rem;
    color: var(--color-text-primary);
}
.crm-modal .modal-footer {
    padding: 0.85rem 1.25rem;
    background: #fafbfc;
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--crm-card-radius) var(--crm-card-radius);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* 6. Pill */
.crm-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    background: rgba(100, 116, 139, 0.08);
    color: var(--crm-neutral);
}
.crm-pill--success,
.crm-pill--client {
    background: rgba(16, 185, 129, 0.10);
    color: var(--color-success);
}
.crm-pill--warning,
.crm-pill--live-opp {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
}
.crm-pill--error,
.crm-pill--cancelled,
.crm-pill--on-hold {
    background: rgba(239, 68, 68, 0.10);
    color: var(--color-error);
}
.crm-pill--info,
.crm-pill--prospect {
    background: rgba(37, 99, 235, 0.10);
    color: var(--color-info);
}
.crm-pill--neutral,
.crm-pill--lead {
    background: rgba(100, 116, 139, 0.10);
    color: var(--crm-neutral);
}
.crm-pill--lg {
    padding: 0.25rem 0.7rem;
    font-size: 0.8125rem;
    border-radius: 6px;
}
.crm-pill__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* 7. Inputs */
.crm-input,
.crm-select,
.crm-textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1.5px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--color-text-primary);
    background: #ffffff;
    transition: border-color var(--crm-transition), box-shadow var(--crm-transition);
    font-family: inherit;
    line-height: 1.4;
}
.crm-input:focus,
.crm-select:focus,
.crm-textarea:focus {
    outline: none;
    border-color: var(--color-brand-primary);
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.10);
}
.crm-textarea {
    min-height: 5rem;
    resize: vertical;
    line-height: 1.5;
}
.crm-input::placeholder,
.crm-textarea::placeholder { color: #94a3b8; }
.crm-input--with-icon { padding-left: 2.1rem; }
.crm-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.85rem;
}
.crm-field__label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
}
.crm-field__hint { font-size: 0.75rem; color: var(--color-text-secondary); }
.crm-field__error { font-size: 0.75rem; color: var(--color-error); }

/* 8. Empty state */
.crm-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--color-text-secondary);
}
.crm-empty__icon {
    font-size: 2.5rem;
    color: var(--color-text-secondary);
    opacity: 0.3;
    margin-bottom: 0.75rem;
}
.crm-empty__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0 0 0.25rem;
}
.crm-empty__text {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin: 0;
    max-width: 30rem;
}
.crm-empty__action { margin-top: 1rem; }

/* 9. Spinner / loading */
.crm-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-brand-primary);
    border-radius: 50%;
    animation: crm-spin 0.8s linear infinite;
    display: inline-block;
}
.crm-spinner--sm { width: 18px; height: 18px; border-width: 2px; }
.crm-spinner--lg { width: 48px; height: 48px; border-width: 4px; }
@keyframes crm-spin { to { transform: rotate(360deg); } }
.crm-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--color-text-secondary);
    gap: 0.75rem;
}
.crm-loading__text { font-size: 0.875rem; font-weight: 500; }

/* Buttons */
.crm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all var(--crm-transition);
    text-decoration: none;
    line-height: 1.3;
    white-space: nowrap;
    background: #ffffff;
    color: var(--color-text-primary);
    border-color: var(--color-border);
}
.crm-btn:hover { border-color: var(--color-brand-primary); color: var(--color-brand-primary); }
.crm-btn--primary {
    background: var(--color-brand-primary);
    color: #ffffff;
    border-color: var(--color-brand-primary);
}
.crm-btn--primary:hover { background: #1a2836; border-color: #1a2836; color: #ffffff; }
.crm-btn--danger {
    background: #ffffff;
    color: var(--color-error);
    border-color: rgba(239, 68, 68, 0.3);
}
.crm-btn--danger:hover { background: var(--color-error); color: #ffffff; border-color: var(--color-error); }
.crm-btn--sm { padding: 0.35rem 0.65rem; font-size: 0.8125rem; }
.crm-btn--icon-only { padding: 0.45rem; width: 2rem; height: 2rem; justify-content: center; }
.crm-btn:disabled,
.crm-btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* Helpers */
.crm-stack { display: flex; flex-direction: column; }
.crm-stack--xs { gap: 0.25rem; }
.crm-stack--sm { gap: 0.5rem; }
.crm-stack--md { gap: 0.75rem; }
.crm-stack--lg { gap: 1rem; }
.crm-stack--xl { gap: 1.5rem; }
.crm-row { display: flex; align-items: center; }
.crm-row--gap { gap: 0.5rem; }
.crm-row--gap-md { gap: 0.75rem; }
.crm-row--gap-lg { gap: 1rem; }
.crm-row--end { justify-content: flex-end; }
.crm-row--between { justify-content: space-between; }
.crm-row--wrap { flex-wrap: wrap; }
.crm-num { font-variant-numeric: tabular-nums; }
.crm-muted { color: var(--color-text-secondary); }
.crm-text-sm { font-size: 0.8125rem; }
.crm-text-xs { font-size: 0.75rem; }
.crm-text-lg { font-size: 1.0625rem; }
.crm-divider {
    height: 1px;
    background: var(--color-border);
    margin: 0.75rem 0;
    border: none;
}

/* KPI strip */
.crm-kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) {
    .crm-kpi-strip { grid-template-columns: repeat(2, 1fr); }
}

/* Chrome adjustments */
body:has(.crm-v2) { background: var(--color-background) !important; }
body.crm-v2-active { background: var(--color-background) !important; }
