/*
 * QuickAlpha CRM look. Plain CSS (no build step), loaded only by the CRM
 * panel and scoped to .fi-panel-crm so the admin panel is untouched.
 * The crm-* classes are used by the CRM's own Blade views.
 */

/* Built from the panel's own colour variables, so light and dark mode
   match the rest of Filament exactly (no tint of our own). */
.fi-panel-crm {
    --crm-green: rgb(var(--primary-600));
    --crm-green-soft: rgba(var(--primary-500), 0.1);
    --crm-ink: rgb(var(--gray-950));
    --crm-muted: rgb(var(--gray-500));
    --crm-line: rgba(var(--gray-950), 0.1);
    --crm-card: #ffffff;
    --crm-bg: rgb(var(--gray-50));
    --crm-column: rgba(var(--gray-950), 0.04);
}

.dark .fi-panel-crm,
.dark.fi-panel-crm {
    --crm-green: rgb(var(--primary-400));
    --crm-green-soft: rgba(var(--primary-500), 0.15);
    --crm-ink: #ffffff;
    --crm-muted: rgb(var(--gray-400));
    --crm-line: rgba(255, 255, 255, 0.1);
    --crm-card: rgb(var(--gray-900));
    --crm-bg: rgb(var(--gray-950));
    --crm-column: rgba(255, 255, 255, 0.03);
}

/* ---------------------------------------------------------------- shell -- */

.fi-panel-crm .fi-header-heading {
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

.fi-panel-crm .fi-main {
    padding-top: 0.5rem;
}

.fi-panel-crm .fi-sidebar-item-button {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}

/* Tighter tables: a salesperson scans many rows. */
.fi-panel-crm .fi-ta-text,
.fi-panel-crm .fi-ta-actions-cell > div,
.fi-panel-crm .fi-ta-selection-cell > div {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
}

.fi-panel-crm .fi-ta-header-cell {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--crm-muted);
}

.fi-panel-crm .fi-section {
    border-radius: 0.875rem;
}

.fi-panel-crm .fi-section-header {
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

.fi-panel-crm .fi-section-header-heading {
    font-size: 0.95rem;
}

.fi-panel-crm .fi-in-entry-wrp-label {
    font-size: 0.75rem;
    color: var(--crm-muted);
}

/* Stats on Home: number first, calmer label. */
.fi-panel-crm .fi-wi-stats-overview-stat {
    border-radius: 0.875rem;
}

.fi-panel-crm .fi-wi-stats-overview-stat-value {
    font-size: 1.85rem;
    letter-spacing: -0.02em;
}

/* --------------------------------------------------------- shared bits -- */

.crm-card {
    background: var(--crm-card);
    border: 1px solid var(--crm-line);
    border-radius: 0.875rem;
}

.crm-muted {
    color: var(--crm-muted);
}

.crm-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    background: #f1f5f9;
    color: #334155;
}

.dark .crm-chip {
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
}

.crm-chip--info { background: #e0f2fe; color: #075985; }
.crm-chip--warning { background: #fef3c7; color: #92400e; }
.crm-chip--success { background: #dcfce7; color: #166534; }
.crm-chip--danger { background: #fee2e2; color: #991b1b; }
.crm-chip--gray { background: #f1f5f9; color: #475569; }

.dark .crm-chip--info { background: rgba(14, 165, 233, 0.18); color: #7dd3fc; }
.dark .crm-chip--warning { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.dark .crm-chip--success { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.dark .crm-chip--danger { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

/* ---------------------------------------------------- customer: hero -- */

.crm-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
}

.crm-avatar {
    flex: none;
    display: grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 999px;
    background: var(--crm-green-soft);
    color: var(--crm-green);
    font-weight: 700;
    font-size: 1.15rem;
}

.crm-hero-main {
    flex: 1 1 18rem;
    min-width: 0;
}

.crm-hero-name {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--crm-ink);
    letter-spacing: -0.01em;
}

.crm-hero-contacts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--crm-muted);
}

.crm-hero-contacts a:hover {
    color: var(--crm-green);
}

.crm-hero-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.crm-hero-actions {
    display: flex;
    gap: 0.5rem;
}

.crm-quick {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border-radius: 0.6rem;
    border: 1px solid var(--crm-line);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--crm-ink);
    background: var(--crm-card);
}

.crm-quick:hover {
    border-color: var(--crm-green);
    color: var(--crm-green);
}

.crm-quick svg {
    width: 1rem;
    height: 1rem;
}

.crm-alert {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    margin: 0 1.5rem 1.25rem;
    padding: 0.7rem 0.9rem;
    border-radius: 0.6rem;
    background: #fffbeb;
    color: #92400e;
    font-size: 0.85rem;
}

.dark .crm-alert {
    background: rgba(245, 158, 11, 0.12);
    color: #fcd34d;
}

/* ------------------------------------------------ customer: facts list -- */

.crm-facts {
    display: grid;
    gap: 0.7rem;
    font-size: 0.875rem;
}

.crm-fact {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.crm-fact dt {
    color: var(--crm-muted);
}

.crm-fact dd {
    color: var(--crm-ink);
    font-weight: 500;
    text-align: right;
}

/* --------------------------------------------------- customer: timeline -- */

.crm-timeline {
    position: relative;
    display: grid;
    gap: 1.1rem;
}

.crm-timeline::before {
    content: "";
    position: absolute;
    left: 0.95rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 2px;
    background: var(--crm-line);
}

.crm-tl-item {
    position: relative;
    display: flex;
    gap: 0.85rem;
}

.crm-tl-dot {
    position: relative;
    z-index: 1;
    flex: none;
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 999px;
    background: var(--crm-card);
    border: 2px solid var(--crm-line);
    color: var(--crm-muted);
}

.crm-tl-dot svg {
    width: 0.9rem;
    height: 0.9rem;
}

.crm-tl-item--note .crm-tl-dot {
    border-color: var(--crm-green);
    color: var(--crm-green);
    background: var(--crm-green-soft);
}

.crm-tl-body {
    min-width: 0;
    flex: 1;
    padding-top: 0.2rem;
}

.crm-tl-line {
    font-size: 0.875rem;
    color: var(--crm-ink);
}

.crm-tl-line b {
    font-weight: 600;
}

.crm-tl-when {
    margin-top: 0.15rem;
    font-size: 0.75rem;
    color: var(--crm-muted);
}

.crm-tl-note {
    margin-top: 0.45rem;
    padding: 0.65rem 0.85rem;
    border-radius: 0.6rem;
    background: var(--crm-bg);
    border: 1px solid var(--crm-line);
    font-size: 0.875rem;
    color: var(--crm-ink);
    white-space: pre-line;
}

.crm-empty {
    padding: 1.5rem 0;
    text-align: center;
    font-size: 0.875rem;
    color: var(--crm-muted);
}

/* ------------------------------------------------- courses bought list -- */

.crm-list {
    display: grid;
    gap: 0.6rem;
    font-size: 0.875rem;
}

.crm-list-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.crm-list-row span:last-child {
    color: var(--crm-muted);
    white-space: nowrap;
}

/* --------------------------------------------------------- pipeline bar -- */

.crm-pipeline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
    gap: 0.6rem;
}

.crm-stage {
    display: block;
    padding: 0.8rem 0.9rem;
    border-radius: 0.75rem;
    border: 1px solid var(--crm-line);
    background: var(--crm-card);
    transition: border-color 0.15s;
}

.crm-stage:hover {
    border-color: var(--crm-green);
}

.crm-stage-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--crm-muted);
}

.crm-stage-count {
    margin-top: 0.2rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--crm-ink);
    letter-spacing: -0.02em;
}

.crm-stage-bar {
    margin-top: 0.5rem;
    height: 0.3rem;
    border-radius: 999px;
    background: var(--crm-line);
    overflow: hidden;
}

.crm-stage-bar span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--crm-green);
}

.crm-stage--lost .crm-stage-bar span { background: #ef4444; }
.crm-stage--converted .crm-stage-bar span { background: #16a34a; }

.crm-greeting {
    font-size: 0.95rem;
    color: var(--crm-muted);
    margin-bottom: 0.25rem;
}

/* ------------------------------------------------------- pipeline board -- */

.crm-board-page {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.crm-board-modals {
    position: absolute;
    width: 0;
    height: 0;
}

/* The board runs to the bottom of the screen: drop the page's own bottom padding. */
.fi-panel-crm section:has(> div > .crm-board-page),
.fi-panel-crm section:has(.crm-board-page) {
    padding-bottom: 0;
}

/* Thin scrollbars that suit both themes (the default is a thick light bar). */
.crm-board,
.crm-col-body {
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--gray-500), 0.35) transparent;
}

.crm-board::-webkit-scrollbar,
.crm-col-body::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.crm-board::-webkit-scrollbar-thumb,
.crm-col-body::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(var(--gray-500), 0.35);
}

.crm-board::-webkit-scrollbar-track,
.crm-col-body::-webkit-scrollbar-track {
    background: transparent;
}

.crm-board-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.crm-board-search { width: 20rem; max-width: 100%; }
.crm-board-owner { width: 13rem; max-width: 100%; }
.crm-board-total { margin-left: auto; font-size: 0.875rem; display: inline-flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }

/* The board fills the screen; only the columns scroll, never the page too. */
.crm-board {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    align-items: stretch;
    /* Set exactly by the page script to the space left on screen. */
    height: calc(100vh - 16rem);
    min-height: 22rem;
    margin-top: 0.25rem;
    padding-bottom: 0.5rem;
}

.crm-board--busy { opacity: 0.6; pointer-events: none; }

.crm-col {
    /* Equal columns that grow to fill wide screens; text never stretches them. */
    flex: 1 0 14rem;
    width: 14rem;
    min-width: 14rem;
    max-width: 24rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-radius: 0.875rem;
    background: var(--crm-column);
    border: 1px solid var(--crm-line);
    transition: border-color 0.15s, background 0.15s;
}

.crm-col--over {
    border-color: rgb(var(--primary-500));
    background: rgba(var(--primary-500), 0.08);
}

.crm-col-head {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.8rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--crm-ink);
}

.crm-col-dot {
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: rgb(var(--primary-500));
}

.crm-col--nurture .crm-col-dot { background: rgb(var(--gray-400)); }
.crm-col--lost .crm-col-dot { background: rgb(var(--danger-500)); }
.crm-col--converted .crm-col-dot { background: rgb(var(--success-500)); }
.crm-col--contacted .crm-col-dot,
.crm-col--qualified .crm-col-dot,
.crm-col--demo .crm-col-dot,
.crm-col--payment_pending .crm-col-dot { background: rgb(var(--warning-500)); }

.crm-col-title {
    flex: 1;
    min-width: 0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-col-count {
    flex: none;
    min-width: 1.5rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--crm-card);
    border: 1px solid var(--crm-line);
    text-align: center;
    font-size: 0.7rem;
    color: var(--crm-muted);
}

.crm-col-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.15rem 0.5rem 0.6rem;
    overflow-y: auto;
}

.crm-col-empty {
    padding: 1rem 0.5rem;
    border: 1.5px dashed var(--crm-line);
    border-radius: 0.6rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--crm-muted);
}

.crm-col-more {
    display: block;
    padding: 0.3rem;
    text-align: center;
    font-size: 0.72rem;
    color: var(--crm-green);
}

/* A card: two lines, with call and WhatsApp as small icons in the corner. */
.crm-lead {
    position: relative;
    flex: none;
    border-radius: 0.65rem;
    background: var(--crm-card);
    border: 1px solid var(--crm-line);
    box-shadow: 0 1px 2px rgba(var(--gray-950), 0.05);
    cursor: grab;
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}

.crm-lead:hover {
    border-color: rgba(var(--primary-500), 0.6);
    box-shadow: 0 4px 12px rgba(var(--gray-950), 0.1);
}

.crm-lead:active { cursor: grabbing; }
.crm-lead--dragging { opacity: 0.4; transform: rotate(1.5deg); }

.crm-lead-link { display: block; padding: 0.6rem 0.65rem 0.55rem; }

.crm-lead-top { display: flex; align-items: center; gap: 0.5rem; }
.crm-lead--callable .crm-lead-top { padding-right: 5.1rem; }
.crm-lead--move-only .crm-lead-top { padding-right: 1.9rem; }

.crm-lead-avatar {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: var(--crm-green-soft);
    color: var(--crm-green);
    font-size: 0.65rem;
    font-weight: 700;
}

.crm-lead-who { min-width: 0; flex: 1; overflow: hidden; }

.crm-lead-name {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--crm-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-lead-contact {
    font-size: 0.7rem;
    line-height: 1.3;
    color: var(--crm-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-lead-meta {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.6rem;
    margin-top: 0.45rem;
    font-size: 0.7rem;
    color: var(--crm-muted);
    white-space: nowrap;
    overflow: hidden;
}

.crm-lead-meta span { display: inline-flex; align-items: center; gap: 0.2rem; }
.crm-lead-owner { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.crm-lead-icon { width: 0.8rem; height: 0.8rem; flex: none; }
.crm-lead-warn { color: rgb(var(--warning-600)); font-weight: 600; }
.dark .crm-lead-warn { color: rgb(var(--warning-400)); }

.crm-lead-actions {
    position: absolute;
    right: 0.5rem;
    top: 0.6rem;
    display: flex;
    gap: 0.25rem;
}

.crm-lead-actions a,
.crm-lead-actions button {
    display: grid;
    place-items: center;
    width: 1.55rem;
    height: 1.55rem;
    border-radius: 0.45rem;
    color: var(--crm-green);
    background: var(--crm-green-soft);
}

.crm-lead-actions a:hover,
.crm-lead-actions button:hover {
    background: rgb(var(--primary-600));
    color: #fff;
}

/* ------------------------------------------------- board: small screens -- */

/* Tablets and phones: the toolbar stacks, each column is nearly the screen's
   width, and the board snaps column by column as you swipe. The page scrolls
   normally; each column keeps its own scroll. */
@media (max-width: 767px) {
    .crm-board-toolbar { gap: 0.5rem; }
    .crm-board-search,
    .crm-board-owner { width: 100%; }
    .crm-board-total { margin-left: 0; width: 100%; font-size: 0.8rem; }

    .crm-board {
        height: auto !important;
        min-height: 0;
        scroll-snap-type: x mandatory;
        scroll-padding: 0 0.25rem;
        gap: 0.6rem;
    }

    .crm-col {
        flex: 0 0 85%;
        width: 85%;
        min-width: 0;
        max-width: none;
        max-height: 70vh;
        scroll-snap-align: start;
    }

    /* No hover on touch screens: keep the shortcuts visible and easy to tap. */
    .crm-lead-actions a,
    .crm-lead-actions button { width: 2rem; height: 2rem; }
    .crm-lead--callable .crm-lead-top { padding-right: 6.6rem; }
    .crm-lead--move-only .crm-lead-top { padding-right: 2.4rem; }
}

/* Mid-size tablets in landscape: a little narrower columns. */
@media (min-width: 768px) and (max-width: 1023px) {
    .crm-col { flex-basis: 13rem; width: 13rem; min-width: 13rem; }
}

/* ------------------------------------------- other pages: small screens -- */

@media (max-width: 767px) {
    /* The stage summary is one row you swipe, not four rows of boxes. */
    .crm-pipeline {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
    }

    .crm-pipeline::-webkit-scrollbar { display: none; }

    .crm-stage {
        flex: 0 0 7.25rem;
        padding: 0.6rem 0.7rem;
        scroll-snap-align: start;
    }

    .crm-stage-count { font-size: 1.15rem; }

    /* Customer card: no initials badge, contact buttons share the row. */
    .crm-hero { gap: 0.85rem; padding: 1rem; }
    .crm-avatar { display: none; }
    .crm-hero-actions { width: 100%; }
    .crm-hero-actions .crm-quick { flex: 1; justify-content: center; padding: 0.55rem 0.5rem; }
    .crm-alert { margin: 0 1rem 1rem; }
}
