/* ═══════════════════════════════════════════════════════════════
   MDGRUPPE CRM — Stylesheet
   Phase 1: Pipeline, Customers, Scorecard, Quick Log
   Extends brand.css design tokens
   ═══════════════════════════════════════════════════════════════ */

/* ── CRM Navigation ──────────────────────────────────────────── */
.crm-nav {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 40px;
}

.crm-nav-item {
    padding: 12px 24px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.crm-nav-item:hover {
    color: var(--color-text);
    background: rgba(0,0,0,0.02);
}

.crm-nav-item.active {
    color: var(--color-group);
    border-bottom-color: var(--color-group);
}

/* ── Sections ────────────────────────────────────────────────── */
.section {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r-lg);
    padding: 24px 28px;
    margin-bottom: 24px;
}

.section-gold {
    border-color: var(--color-group-border);
    background: var(--color-group-faint);
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--color-text);
    letter-spacing: -0.2px;
}

.section-subtitle {
    font-size: 13px;
    color: var(--color-muted);
}

/* ── Pipeline Strip (CRM Home) ───────────────────────────────── */
.pipeline-strip {
    display: flex;
    gap: 12px;
}

.pipeline-col {
    flex: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    padding: 16px;
    text-align: center;
}

.pipeline-col-header {
    padding-top: 10px;
    margin-bottom: 8px;
}

.pipeline-stage-name {
    font-size: var(--type-xs);
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
}

.pipeline-count {
    font-size: 32px;
    font-weight: 500;
    color: var(--color-text);
}

.pipeline-value {
    font-size: 12px;
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
}

/* ── Follow-up List (CRM Home) ───────────────────────────────── */
.followup-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.followup-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    cursor: pointer;
    transition: border-color 0.2s;
}

.followup-row:hover {
    border-color: var(--color-group);
}

.followup-customer {
    font-weight: 500;
    font-size: 14px;
    min-width: 200px;
}

.followup-title {
    flex: 1;
    font-size: 13px;
    color: var(--color-text-secondary);
}

.followup-value {
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* ── Scorecard Mini (CRM Home) ───────────────────────────────── */
.scorecard-mini { }

.sc-mini-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}

.sc-mini-card {
    text-align: center;
    padding: 12px 8px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
}

.sc-mini-label {
    font-size: var(--type-xs);
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.sc-mini-value {
    font-size: var(--type-xl);
    font-weight: 500;
    color: var(--color-text);
}

.sc-mini-value.sc-green { color: var(--color-green); }
.sc-mini-value.sc-red { color: var(--color-red); }
.sc-mini-value.gold { color: var(--color-group); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: var(--type-xs);
    font-weight: 500;
    border-radius: 3px;
    letter-spacing: 0.3px;
}

.badge-type {
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.tier-badge {
    display: inline-block;
    padding: 2px 10px;
    font-size: var(--type-xs);
    font-weight: 500;
    border: 1px solid;
    border-radius: 3px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tier-badge-lg {
    font-size: 13px;
    padding: 4px 14px;
}

.risk-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* ── Notifications ───────────────────────────────────────────── */
.notif-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notif-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
}

.notif-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-group);
    flex-shrink: 0;
}

.notif-title {
    font-weight: 500;
    font-size: 13px;
}

.notif-body {
    font-size: 13px;
    color: var(--color-text-secondary);
}

/* ── CRM Toolbar (Filters / Search) ─────────────────────────── */
.crm-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.crm-search {
    flex: 1;
    min-width: 200px;
    padding: 10px 14px;
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    background: var(--color-bg);
    outline: none;
    transition: border-color 0.2s;
}

.crm-search:focus {
    border-color: var(--color-group);
}

.crm-search::placeholder {
    color: var(--warm-300);
}

.crm-select {
    padding: 10px 14px;
    font-family: var(--font-primary);
    font-size: 13px;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    background: var(--color-bg);
    outline: none;
    cursor: pointer;
    min-width: 120px;
}

.crm-select:focus {
    border-color: var(--color-group);
}

/* ── Customer Table ──────────────────────────────────────────── */
.crm-table-wrap {
    overflow-x: auto;
}

.crm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.crm-table thead th {
    padding: 10px 14px;
    font-size: var(--type-xs);
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.crm-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.crm-table tbody tr:last-child td {
    border-bottom: none;
}

.cust-row {
    cursor: pointer;
    transition: background 0.15s;
}

.cust-row:hover {
    background: var(--color-group-faint);
}

.text-muted {
    color: var(--color-muted);
    font-size: 12px;
}

.text-right {
    text-align: right;
    font-family: var(--font-mono);
}

/* ── Dedup Banner ────────────────────────────────────────────── */
.dedup-banner {
    padding: 12px 16px;
    background: rgba(201, 146, 14, 0.08);
    border: 1px solid var(--color-group-border);
    border-radius: var(--r);
    font-size: 13px;
    color: var(--color-text);
    margin-bottom: 16px;
}

/* ── Pagination ──────────────────────────────────────────────── */
.crm-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
}

.pag-btn {
    padding: 6px 12px;
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.15s;
}

.pag-btn:hover {
    border-color: var(--color-group);
    color: var(--color-group);
}

.pag-btn.active {
    background: var(--color-group);
    color: #fff;
    border-color: var(--color-group);
}

/* ── Customer Detail ─────────────────────────────────────────── */
.detail-header {
    margin-bottom: 24px;
}

.detail-title-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 4px;
}

.detail-name {
    font-size: var(--type-xl);
    font-weight: 500;
    letter-spacing: -0.3px;
}

.detail-code {
    font-size: 13px;
    color: var(--color-muted);
    font-family: var(--font-mono);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    margin-bottom: 24px;
}

.detail-info {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r-lg);
    padding: 20px 24px;
}

.detail-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 140px;
    flex-shrink: 0;
}

.info-value {
    font-size: 14px;
    color: var(--color-text);
}

.metric-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    padding: 16px 20px;
    text-align: center;
}

.metric-label {
    font-size: var(--type-xs);
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.metric-value {
    font-size: 20px;
    font-weight: 500;
    color: var(--color-text);
}

.metric-value.gold {
    color: var(--color-group);
}

/* ── Opportunities List (in Customer Detail) ─────────────────── */
.opp-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    margin-bottom: 8px;
}

.opp-number {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--color-muted);
    min-width: 180px;
}

.opp-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.opp-value {
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* ── Timeline ────────────────────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-border);
}

.timeline-item {
    position: relative;
    display: flex;
    gap: 16px;
    padding-bottom: 20px;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.tl-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-border);
    border: 2px solid var(--color-bg);
    z-index: 1;
}

.tl-dot.tl-positive {
    background: var(--color-green);
}

.tl-dot.tl-negative {
    background: var(--color-red);
}

.tl-content {
    flex: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    padding: 12px 16px;
}

.tl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.tl-type {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tl-date {
    font-size: 12px;
    color: var(--color-muted);
    font-family: var(--font-mono);
}

.tl-notes {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
}

/* ── Kanban Board (Pipeline Page) ────────────────────────────── */
.kanban-board {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 12px;
}

.kanban-col {
    flex: 1;
    min-width: 220px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.kanban-col-header {
    padding: 14px 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kanban-stage-name {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text);
}

.kanban-count {
    font-size: var(--type-md);
    font-weight: 500;
    color: var(--color-text);
}

.kanban-value {
    padding: 0 16px 12px;
    font-size: 12px;
    color: var(--color-muted);
    font-family: var(--font-mono);
}

.kanban-cards {
    padding: 0 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
}

.kanban-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.kanban-card:hover {
    border-color: var(--color-group);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.kanban-card-stale {
    border-left: 3px solid var(--color-red);
}

.kc-customer {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 3px;
}

.kc-title {
    font-size: var(--type-xs);
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kc-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--type-xs);
    color: var(--color-muted);
}

/* ── Stage Modal ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: var(--color-bg);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: 16px;
    font-weight: 500;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--color-muted);
    background: none;
    border: none;
    border-radius: var(--r);
    cursor: pointer;
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--color-surface);
    color: var(--color-text);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
}

/* ── Quick Log Specific ──────────────────────────────────────── */
.ql-selected {
    padding: 8px 12px;
    margin-top: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.ql-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0 0 var(--r) var(--r);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.ql-dd-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s;
}

.ql-dd-item:hover {
    background: var(--color-group-faint);
}

.ql-dd-empty {
    color: var(--color-muted);
    cursor: default;
}

.ql-dedup-warn {
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(201, 146, 14, 0.08);
    border: 1px solid var(--color-group-border);
    border-radius: var(--r);
    font-size: 12px;
    color: var(--color-group);
}

.ql-flash {
    position: absolute;
    inset: 0;
    background: rgba(27, 138, 58, 0.92);
    color: #fff;
    font-size: var(--type-md);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-lg);
}

.modal-body .form-group {
    position: relative;
}

/* ── Chip Buttons (Type / Outcome selectors) ─────────────────── */
.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-chip {
    padding: 7px 16px;
    font-family: var(--font-primary);
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-chip:hover {
    border-color: var(--color-group);
    color: var(--color-group);
}

.btn-chip.active {
    background: var(--color-group);
    color: #fff;
    border-color: var(--color-group);
}

/* ── FAB (Quick Log Floating Action Button) ──────────────────── */
.fab-quicklog {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-group);
    color: #fff;
    font-size: var(--type-xl);
    font-weight: 300;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(201, 146, 14, 0.35);
    transition: transform 0.15s, box-shadow 0.15s;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-quicklog:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(201, 146, 14, 0.45);
}

/* ── Scorecard Table ─────────────────────────────────────────── */
.scorecard-table tbody td {
    font-variant-numeric: tabular-nums;
}

.sc-green { color: var(--color-green) !important; }
.sc-red { color: var(--color-red) !important; }
.sc-yellow { color: #D9A530 !important; }

.sc-streak,
.sc-champion,
.sc-builder {
    font-size: 14px;
    vertical-align: middle;
}

.scorecard-period {
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-mono);
    color: var(--color-group);
}

/* ── Loading / Empty States ──────────────────────────────────── */
.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px;
    color: var(--color-muted);
    font-size: 13px;
}

.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--color-muted);
    font-size: 13px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-group);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Profile Completeness ────────────────────────────────────── */
.profile-bar-wrap {
    margin-bottom: 24px;
}

.profile-bar-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}

.profile-bar-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
}

.profile-bar-pct {
    font-size: var(--type-xl);
    font-weight: 500;
    color: var(--color-group);
    font-variant-numeric: tabular-nums;
}

.profile-bar-track {
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

.profile-bar-fill {
    height: 100%;
    background: var(--color-group);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.profile-bar-hint {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 6px;
}

/* ── Profile Sections (collapsible) ──────────────────────────── */
.profile-section {
    border: 1px solid var(--color-border);
    border-radius: var(--r);
    margin-bottom: 12px;
    overflow: hidden;
}

.profile-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-surface);
    cursor: pointer;
    user-select: none;
}

.profile-section-header:hover {
    background: var(--color-group-faint);
}

.profile-section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
}

.profile-section-status {
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 3px;
}

.profile-section-status.complete {
    color: var(--color-green);
    background: var(--color-green-bg);
}

.profile-section-status.incomplete {
    color: var(--color-muted);
    background: var(--color-surface);
}

.profile-section-body {
    padding: 16px;
    border-top: 1px solid var(--color-border);
}

.profile-section-body.collapsed {
    display: none;
}

.profile-field-row {
    display: flex;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid var(--color-border);
}

.profile-field-row:last-child {
    border-bottom: none;
}

.profile-field-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 160px;
    flex-shrink: 0;
}

.profile-field-value {
    font-size: 14px;
    color: var(--color-text);
}

.profile-field-value.empty {
    color: var(--color-muted);
    font-style: italic;
    font-size: 12px;
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 24px 40px;
    border-top: 1px solid var(--color-border);
}

.footer-line {
    font-size: var(--type-xs);
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
    .crm-nav { padding: 0 16px; }
    .crm-nav-item { padding: 10px 14px; font-size: 12px; }
    .sc-mini-grid { grid-template-columns: repeat(3, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .kanban-board { flex-direction: column; }
    .kanban-col { min-width: 100%; }
    .pipeline-strip { flex-wrap: wrap; }
    .pipeline-col { flex-basis: calc(50% - 6px); }
}

@media (max-width: 600px) {
    .crm-toolbar { flex-direction: column; }
    .crm-search { min-width: 100%; }
    .sc-mini-grid { grid-template-columns: repeat(2, 1fr); }
    .pipeline-col { flex-basis: 100%; }
}
