/* Kanban board (Home). Adapted from the KairosKanBan.html mockup.
   Global, not scoped: the board's dialogs render outside the page. Every class starts with kb-. */

.kb {
    /* Theme palette, so the board follows light and dark mode */
    --kb-bg: var(--mud-palette-background-gray);
    --kb-surface: var(--mud-palette-surface);
    --kb-text: var(--mud-palette-text-primary);
    --kb-muted: var(--mud-palette-text-secondary);
    --kb-border: var(--mud-palette-lines-default);
    --kb-lane: color-mix(in srgb, var(--kb-text) 8%, var(--kb-surface));
    --kb-accent: var(--mud-palette-primary);
    --kb-accent-soft: color-mix(in srgb, var(--kb-accent) 12%, var(--kb-surface));
    --kb-focus: color-mix(in srgb, var(--kb-accent) 45%, var(--kb-surface));
    --kb-radius: 10px;
    color: var(--kb-text);
    font-variant-numeric: lining-nums;
}

.kb-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Page layout ---------- */
.kb-page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: calc(100vh - var(--mud-appbar-height) - 2rem);
}

.kb-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
}
.kb-topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

/* Filters and sort on the first row, "Hide done tasks" underneath */
.kb-toolbar-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
}

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

/* ---------- Switch ("Hide done tasks") ---------- */
.kb-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.15rem 0.25rem;
    border: none;
    border-radius: 999px;
    background: none;
    color: var(--kb-text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.kb-switch:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 2px; }
.kb-switch-track {
    position: relative;
    flex: none;
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: var(--mud-palette-lines-inputs);
    transition: background 0.15s ease;
}
.kb-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.3);
    transition: transform 0.15s ease;
}
.kb-switch[aria-checked="true"] .kb-switch-track { background: var(--kb-accent); }
.kb-switch[aria-checked="true"] .kb-switch-thumb { transform: translateX(14px); }
.kb-switch-label { font-weight: 600; }
.kb-switch-count {
    min-width: 1.4rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--kb-bg);
    color: var(--kb-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
}

/* ---------- Status filter ---------- */
.kb-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font: inherit;
    font-size: 0.9rem;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--kb-border);
    border-radius: var(--kb-radius);
    background: var(--kb-surface);
    color: var(--kb-text);
    cursor: pointer;
}
.kb-filter-btn:hover { border-color: var(--mud-palette-lines-inputs); }
.kb-filter-btn:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 2px; }
.kb-filter-btn-label { color: var(--kb-muted); font-weight: 600; }
.kb-filter-btn-value { font-weight: 700; }
.kb-filter-btn svg { color: var(--kb-muted); transition: transform 0.15s; }
.kb-filter-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.kb-filter-btn.kb-is-filtered { border-color: var(--kb-accent); background: var(--kb-accent-soft); }
.kb-filter-btn.kb-is-filtered .kb-filter-btn-value { color: var(--kb-accent); }

.kb-filter-panel {
    min-width: 260px;
    padding: 0.4rem;
    background: var(--kb-surface);
    border: 1px solid var(--kb-border);
    border-radius: var(--kb-radius);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}
.kb-filter-options { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.kb-filter-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}
.kb-filter-option:hover { background: var(--kb-bg); }
.kb-filter-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--kb-accent); cursor: pointer; }
.kb-filter-swatch { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--status-color, #6b7280); }
.kb-filter-swatch-empty { background: transparent; border: 1.5px dashed var(--kb-muted); box-sizing: border-box; }
.kb-filter-option-name { flex: 1; }
.kb-filter-option-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--kb-muted);
    background: var(--kb-bg);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
}
.kb-filter-actions {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.6rem 0.3rem;
    margin-top: 0.3rem;
    border-top: 1px solid var(--kb-border);
    font-size: 0.85rem;
}

/* ---------- Sort ---------- */
.kb-sort {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--kb-border);
    border-radius: var(--kb-radius);
    background: var(--kb-surface);
    font-size: 0.9rem;
}
.kb-sort:focus-within { border-color: var(--mud-palette-lines-inputs); }
.kb-sort-label { display: flex; align-items: center; padding-left: 0.9rem; color: var(--kb-muted); font-weight: 600; }
.kb-sort-select {
    font: inherit;
    font-weight: 700;
    color: var(--kb-text);
    padding: 0.55rem 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
}
.kb-sort-select:focus-visible,
.kb-sort-dir:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 1px; border-radius: 6px; }
.kb-sort-dir {
    display: inline-flex;
    align-items: center;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0 0.85rem;
    border: none;
    border-left: 1px solid var(--kb-border);
    border-radius: 0 var(--kb-radius) var(--kb-radius) 0;
    background: transparent;
    color: var(--kb-text);
    cursor: pointer;
    white-space: nowrap;
}
.kb-sort-dir:hover { background: var(--kb-bg); }

/* ---------- Workspace ---------- */
.kb-workspace {
    flex: 1;
    display: grid;
    place-items: center;
    border: 2px dashed var(--kb-border);
    border-radius: var(--kb-radius);
    background: var(--kb-surface);
}
.kb-workspace.kb-has-board {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    padding: 1rem;
    overflow-x: auto;
    border-style: solid;
    border-width: 1px;
}

.kb-empty-state { text-align: center; max-width: 360px; padding: 2rem; }
.kb-empty-state svg { color: var(--mud-palette-text-disabled); margin-bottom: 0.75rem; }
.kb-empty-state h2 { margin: 0 0 0.4rem; font-size: 1.25rem; }
.kb-empty-state p { margin: 0; color: var(--kb-muted); line-height: 1.5; }

/* ---------- Customer column (its own kanban: grows with its projects) ---------- */
.kb-column {
    flex: none;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--kb-bg);
    border: 1px solid var(--kb-border);
    border-top: 4px solid var(--col-color, var(--kb-accent));
    border-radius: var(--kb-radius);
}
.kb-column-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--kb-border);
}
.kb-column-heading { display: flex; flex-direction: column; min-width: 0; }
.kb-column-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-column-subtitle {
    font-size: 0.75rem;
    color: var(--kb-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kb-column-count {
    margin-left: auto;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--kb-muted);
    background: var(--kb-surface);
    border: 1px solid var(--kb-border);
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
}
.kb-column-body { flex: 1; display: flex; align-items: stretch; gap: 0.75rem; padding: 0.75rem; }
.kb-column-body > .kb-column-empty { flex: 1; align-self: flex-start; }

.kb-header-btn {
    flex: none;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--kb-border);
    border-radius: 6px;
    background: var(--kb-surface);
    color: var(--kb-text);
    cursor: pointer;
}
.kb-header-btn:hover:not(:disabled) { border-color: var(--kb-accent); color: var(--kb-accent); }
.kb-header-btn:disabled { opacity: 0.5; cursor: default; }
.kb-header-btn:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 1px; }

.kb-eye-btn {
    flex: none;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--kb-muted);
    cursor: pointer;
}
.kb-eye-btn:hover { background: var(--kb-surface); color: var(--kb-text); }
.kb-eye-btn:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 1px; }

.kb-column-empty {
    padding: 1.5rem 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--kb-muted);
    border: 1px dashed var(--kb-border);
    border-radius: 8px;
}

.kb-link-btn {
    font: inherit;
    font-weight: 600;
    color: var(--kb-accent);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}
.kb-link-btn:disabled { color: var(--kb-muted); cursor: default; text-decoration: none; }

/* ---------- Project lane: darker gray, no border; tasks are raised white cards ---------- */
.kb-project-column { flex: 0 0 240px; display: flex; flex-direction: column; background: var(--kb-lane); border-radius: 10px; }
.kb-project-header { padding: 0.75rem 0.8rem 0.6rem; }
.kb-project-eyebrow {
    display: block;
    margin-bottom: 0.2rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--kb-muted);
}
.kb-project-title-row { display: flex; align-items: flex-start; gap: 0.4rem; }
.kb-project-title-row .kb-eye-btn { width: 24px; height: 24px; margin: -2px -4px 0 0; }
.kb-project-title-row .kb-eye-btn:hover { background: color-mix(in srgb, var(--kb-surface) 70%, transparent); }
.kb-project-name { flex: 1; margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.3; }

/* Reordering project columns */
.kb-drag-handle {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 24px;
    margin: -1px 0 0 -6px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--kb-muted);
    cursor: grab;
    opacity: 0.55;
    transition: opacity 0.12s ease, background 0.12s ease;
}
.kb-project-column:hover .kb-drag-handle, .kb-drag-handle:focus-visible { opacity: 1; }
.kb-drag-handle:hover { background: color-mix(in srgb, var(--kb-surface) 70%, transparent); }
.kb-drag-handle:active { cursor: grabbing; }
.kb-drag-handle:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 1px; }
.kb-project-column.kb-is-dragging { opacity: 0.45; }
.kb-project-column.kb-is-drop-target { outline: 2px dashed var(--kb-accent); outline-offset: 2px; }
.kb-project-body { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; min-height: 160px; padding: 0 0.5rem 0.6rem; }
.kb-project-body > .kb-column-empty { border-color: var(--mud-palette-lines-inputs); }

/* ---------- Loading skeletons (same boxes as the real columns and cards) ---------- */
.kb-skeleton-board { display: flex; align-items: stretch; gap: 1rem; }
.kb-skeleton { pointer-events: none; }
.kb-skeleton-row { display: flex; align-items: center; gap: 0.5rem; }
.kb-column-heading .mud-skeleton + .mud-skeleton { margin-top: 0.3rem; }

/* ---------- Task cards ---------- */
.kb-task-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.65rem 0.75rem;
    background: var(--kb-surface);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12), 0 1px 2px rgba(15, 23, 42, 0.06);
}
.kb-task-name { margin: 0; font-size: 0.875rem; font-weight: 600; line-height: 1.35; }
/* Opens the task: the title is a button whose ::after covers the card */
.kb-task-open {
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.kb-task-open::after { content: ""; position: absolute; inset: 0; border-radius: 8px; }
.kb-task-open:focus-visible { outline: none; }
.kb-task-open:focus-visible::after { outline: 3px solid var(--kb-focus); outline-offset: 2px; }
.kb-task-card:hover { box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16), 0 1px 2px rgba(15, 23, 42, 0.08); }
.kb-task-card:hover .kb-task-open { text-decoration: underline; }
/* Assignees as a row of overlapping avatars; each name shows in a tooltip on hover */
.kb-task-owners { display: flex; flex-wrap: wrap; list-style: none; margin: 0; padding: 0 0 0 4px; }
.kb-task-owner { position: relative; z-index: 1; display: flex; margin-left: -4px; border-radius: 50%; box-shadow: 0 0 0 2px var(--kb-surface); }
.kb-task-owner:hover { z-index: 2; }
/* Tooltip from data-tooltip, shown above the element on hover (board avatars, Time Tracking users) */
.kb-tip { position: relative; display: inline-flex; }
.kb-tip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translate(-50%, 2px);
    z-index: 3;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: #383d47;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.kb-tip:hover::after { opacity: 1; transform: translate(-50%, 0); }
.kb-task-unassigned { font-size: 0.8rem; color: var(--kb-muted); }
.kb-task-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.kb-task-created { font-size: 0.75rem; color: var(--kb-muted); }
.kb-task-logged {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    flex: none;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--kb-text);
}
.kb-task-logged svg { color: var(--kb-muted); }
.kb-task-logged.is-none { font-weight: 400; color: var(--kb-muted); }
.kb-task-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0; padding: 0; list-style: none; }
/* One color per tag (--tag-color); background and text derive from it */
.kb-task-tag {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    background: color-mix(in srgb, var(--tag-color, #6b7280) 16%, var(--kb-surface));
    color: color-mix(in srgb, var(--tag-color, #6b7280) 70%, var(--kb-text));
}
/* One color per status (--status-color); background and text derive from it */
.kb-task-status {
    align-self: flex-start;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--status-color, #6b7280) 16%, var(--kb-surface));
    color: color-mix(in srgb, var(--status-color, #6b7280) 70%, var(--kb-text));
}

/* ---------- Avatars ---------- */
.kb-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
}
.kb-avatar-sm { width: 28px; height: 28px; font-size: 0.7rem; }
.kb-avatar-xs { width: 20px; height: 20px; font-size: 0.6rem; }

/* ---------- Dialog lists (customers, projects) ---------- */
.kb-dialog-header-actions { display: flex; align-items: center; gap: 0.75rem; }
.kb-dialog-header-actions .kb-link-btn { font-size: 0.85rem; text-decoration: none; }
.kb-dialog-header-actions .kb-link-btn:hover:not(:disabled) { text-decoration: underline; }
.kb-count { color: var(--kb-muted); font-weight: 400; font-size: 0.9rem; margin-left: 0.35rem; }

.kb-list { list-style: none; margin: 0; padding: 0; }
.kb-list li { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.75rem; border-radius: 8px; }
.kb-list li:hover { background: var(--kb-bg); }
.kb-list .kb-toggle-btn { margin-left: auto; }
.kb-list .kb-status + .kb-toggle-btn { margin-left: 0; }
.kb-info { display: flex; flex-direction: column; min-width: 0; }
.kb-name { font-weight: 600; }
.kb-meta { color: var(--kb-muted); font-size: 0.85rem; }
.kb-no-projects { color: var(--mud-palette-error); }
.kb-state-msg { padding: 1.5rem; text-align: center; color: var(--kb-muted); }

.kb-status { margin-left: auto; font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.55rem; border-radius: 999px; }
.kb-status.kb-active { background: color-mix(in srgb, #16a34a 16%, var(--kb-surface)); color: color-mix(in srgb, #16a34a 75%, var(--kb-text)); }
.kb-status.kb-inactive { background: var(--kb-bg); color: var(--kb-muted); }

.kb-toggle-btn {
    flex: none;
    min-width: 60px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--kb-accent);
    border-radius: 6px;
    background: transparent;
    color: var(--kb-accent);
    cursor: pointer;
}
.kb-toggle-btn:hover { background: var(--kb-accent-soft); }
.kb-toggle-btn.kb-on { background: var(--kb-accent); color: var(--mud-palette-primary-text); }
.kb-toggle-btn.kb-on:hover { background: color-mix(in srgb, var(--kb-accent) 85%, black); }
.kb-toggle-btn:focus-visible { outline: 3px solid var(--kb-focus); outline-offset: 2px; }
.kb-toggle-btn:disabled,
.kb-toggle-btn:disabled:hover { border-color: var(--kb-border); background: transparent; color: var(--kb-muted); cursor: not-allowed; }

/* A task someone is tracking right now: light green card, green edge and a "Tracking" label */
.kb-task-top { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; flex-wrap: wrap; }
.kb-task-card.is-tracking {
    background: color-mix(in srgb, var(--mud-palette-success) 9%, var(--kb-surface));
    box-shadow: inset 3px 0 0 var(--mud-palette-success), 0 0 0 1px color-mix(in srgb, var(--mud-palette-success) 45%, transparent);
}
/* Blocked: same treatment as tracking, in the Blocked status red, with the reason under the title */
.kb-task-card.is-blocked {
    background: color-mix(in srgb, #e11d48 7%, var(--kb-surface));
    box-shadow: inset 3px 0 0 #e11d48, 0 0 0 1px color-mix(in srgb, #e11d48 40%, transparent);
}
.kb-task-blocked {
    display: flex;
    align-items: flex-start;
    gap: 0.3rem;
    margin: 0;
    font-size: 0.75rem;
    color: color-mix(in srgb, #e11d48 75%, var(--kb-text));
}
.kb-task-blocked svg { flex: none; margin-top: 0.1rem; }
.kb-task-blocked > span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.kb-task-tracking {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
    font-size: 0.7rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--mud-palette-success) 80%, var(--kb-text));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-task-tracking-dot {
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mud-palette-success);
    animation: kb-tracking-pulse 1.6s ease-in-out infinite;
}
@keyframes kb-tracking-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .kb-task-tracking-dot { animation: none; } }
.kb-task-pin { flex-shrink: 0; transform: rotate(35deg); }
