/*
 * The board. Tokens straight from docs/03-ui.md §4 — one set per mode, so a
 * colour is defined once and every rule below reads it.
 *
 * Deliberately its own stylesheet rather than Tailwind utilities: a custom
 * Filament theme would add an npm build to a deploy that today is one artisan
 * command, and the spec already describes this design as CSS variables.
 */
.crm-board {
    --surface: #ffffff;
    --surface-raised: #f8fafc;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --danger: #dc2626;
    --warning: #f59e0b;

    --radius: 8px;
    --gap: 12px;

    color: var(--text);
}

.dark .crm-board {
    --surface: #0f1115;
    --surface-raised: #171a21;
    --border: #272b34;
    --text: #e5e7eb;
    --text-muted: #9099ab;
    --accent: #3b82f6;
}

/* ── Toolbar ─────────────────────────────────────────────────────────── */

.crm-board__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap);
    margin-bottom: 16px;
}

.crm-board__toolbar-spacer { flex: 1 1 auto; }

.crm-field {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    padding: 6px 10px;
    min-height: 34px;
}

.crm-field:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.crm-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.crm-toggle input { accent-color: var(--accent); }

.crm-link-button {
    background: none;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    padding: 4px 2px;
    text-decoration: underline;
}

/* ── Columns ─────────────────────────────────────────────────────────── */

.crm-board__columns {
    display: flex;
    gap: var(--gap);
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 8px;
}

.crm-column {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    flex: 0 0 300px;
    max-height: calc(100vh - 260px);
}

.crm-column__head {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 12px;
}

.crm-column__dot {
    border-radius: 50%;
    flex: 0 0 auto;
    height: 8px;
    width: 8px;
}

.crm-column__count {
    color: var(--text-muted);
    font-weight: 400;
    margin-left: auto;
}

.crm-column__cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 60px;
    overflow-y: auto;
    padding: 10px;
}

/* A column you cannot drop into dims while dragging: you cannot mis-drag. */
.crm-column--forbidden { opacity: 0.45; }

.crm-column__empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 12px 4px;
    text-align: center;
}

.crm-column__more {
    border-top: 1px solid var(--border);
    padding: 8px;
    text-align: center;
}

/* ── Cards ───────────────────────────────────────────────────────────── */

.crm-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--card-accent, var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    display: block;
    font-size: 13px;
    padding: 8px 10px;
    text-align: left;
    width: 100%;
}

.crm-card:hover { border-color: var(--accent); }

.crm-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.crm-card--selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.crm-card__top {
    align-items: baseline;
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.crm-card__customer {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-card__title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    margin: 2px 0;
    overflow: hidden;
}

.crm-card__meta,
.crm-card__foot {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    font-size: 12px;
    gap: 6px;
    justify-content: space-between;
}

.crm-card__foot { margin-top: 6px; }

.crm-card.sortable-ghost { opacity: 0.4; }

.crm-card.sortable-drag { box-shadow: 0 8px 20px rgb(0 0 0 / 18%); }

/* ── Badges ──────────────────────────────────────────────────────────── */

.crm-badge {
    border-radius: 4px;
    display: inline-block;
    font-size: 11px;
    line-height: 1.5;
    padding: 0 6px;
    white-space: nowrap;
}

/* Status and label colours come from the database, so they must stay legible
 * in both modes: a dimmed field with contrast-checked text, never a full
 * background. See docs/03-ui.md §4. */
.crm-badge--data {
    background: color-mix(in srgb, var(--badge-color) 18%, transparent);
    color: color-mix(in srgb, var(--badge-color) 70%, var(--text));
}

.crm-badge--priority-high { color: var(--warning); }
.crm-badge--priority-urgent { color: var(--danger); font-weight: 600; }

.crm-due--overdue { color: var(--danger); font-weight: 600; }

.crm-avatar {
    align-items: center;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    display: inline-flex;
    font-size: 11px;
    height: 24px;
    justify-content: center;
    width: 24px;
}

.crm-avatar--empty { border-style: dashed; cursor: pointer; }

.crm-avatar--empty:hover { border-color: var(--accent); color: var(--accent); }

/* ── Detail panel ────────────────────────────────────────────────────── */

.crm-panel {
    background: var(--surface);
    border-left: 1px solid var(--border);
    bottom: 0;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    position: fixed;
    right: 0;
    top: 0;
    width: 460px;
    z-index: 30;
}

.crm-panel__zone {
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

.crm-panel__customer {
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.crm-panel__title {
    font-size: 15px;
    font-weight: 600;
    margin-top: 2px;
}

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

/* Zone 2 says in words what is expected of you, so a screen reader hears the
 * same summary the eye gets. */
.crm-panel__summary {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 13px;
    margin-bottom: 8px;
}

.crm-panel__controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.crm-panel__details {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 8px;
}

.crm-panel__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 16px;
}

.crm-comment {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 10px;
    padding: 8px 10px;
}

.crm-comment--internal { border-style: dashed; }

.crm-comment__head {
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.crm-collapsible {
    border-top: 1px solid var(--border);
    margin-top: 14px;
    padding-top: 10px;
}

.crm-collapsible summary {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
}

/* Sticky, not fixed: on a short screen a fixed foot lies over the content. */
.crm-panel__foot {
    background: var(--surface);
    border-top: 1px solid var(--border);
    bottom: 0;
    padding: 12px 16px;
    position: sticky;
}

.crm-panel__foot textarea {
    resize: vertical;
    width: 100%;
}

.crm-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.crm-button {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    padding: 6px 12px;
}

.crm-button--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.crm-button:disabled { cursor: not-allowed; opacity: 0.5; }

.crm-panel__backdrop {
    background: rgb(0 0 0 / 25%);
    inset: 0;
    position: fixed;
    z-index: 20;
}

.crm-visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

@media (max-width: 640px) {
    .crm-panel { width: 100%; }
    .crm-column { flex-basis: 85vw; }
}
