/* ------------------------------------------------------------------
   SBIT Web CRM - Dark theme
------------------------------------------------------------------ */
:root {
    --bg: #0f141a;
    --bg-elevated: #161c24;
    --bg-card: #1b2230;
    --bg-card-2: #222a39;
    --border: #2a3344;
    --border-strong: #3a4458;
    --text: #e6ecf2;
    --text-muted: #8892a6;
    --text-faint: #5f6b80;
    --accent: #f59e0b;
    --accent-hover: #fbbf24;
    --accent-strong: #ef8b00;
    --success: #22c55e;
    --danger: #ef4444;
    --overdue-bg: #3a1616;
    --overdue-border: #ef4444;
    --overdue-glow: rgba(239, 68, 68, 0.35);
    --shadow: 0 4px 14px rgba(0,0,0,0.25);
    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.view { min-height: 100vh; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error-text { color: var(--danger); margin: 0; font-size: 13px; }
.success-text { color: var(--success); margin: 0; font-size: 13px; }

/* ---------- Login ---------- */
.view-login {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 10%, rgba(245, 158, 11, 0.08), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(59, 130, 246, 0.05), transparent 45%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { margin: 12px 0 4px; font-size: 20px; }
.login-brand p { margin: 0; }
.logo-mark {
    width: 44px; height: 44px;
    background: var(--accent);
    color: #1a1203;
    font-weight: 700;
    border-radius: 10px;
    display: grid; place-items: center;
    margin: 0 auto;
    font-size: 16px;
    letter-spacing: 0.5px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.stack label span { font-weight: 500; }

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}
input:disabled, select:disabled, textarea:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background: var(--bg);
}
input[type="checkbox"], input[type="radio"] {
    width: auto;
    padding: 0;
    background: transparent;
    border: none;
    accent-color: var(--accent);
    cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
textarea { resize: vertical; min-height: 80px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s, transform .08s;
    background: var(--bg-card-2);
    color: var(--text);
}
.btn:hover { background: var(--bg-elevated); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #1a1203; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-card-2); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- App layout ---------- */
.view-app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex; flex-direction: column;
    gap: 20px;
    position: sticky; top: 0;
    height: 100vh;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 4px 8px;
}
.sidebar-brand .logo-mark { width: 38px; height: 38px; font-size: 14px; margin: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    transition: background-color .15s, color .15s;
}
.nav-link:hover { background: var(--bg-card-2); color: var(--text); }
.nav-link.active {
    background: rgba(245, 158, 11, 0.12);
    color: var(--accent);
}
.admin-only { display: none; }
body.is-admin .admin-only { display: block; }
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.user-badge {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px;
}
.user-badge .avatar {
    width: 32px; height: 32px;
    background: var(--bg-card-2);
    border-radius: 50%;
    display: grid; place-items: center;
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
}

.main { min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 22px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.topbar-actions > select,
.topbar-actions > input { width: auto; min-width: 200px; }
.route-container { padding: 24px 28px; }

/* ---------- KPI strip ---------- */
.kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-tile {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: border-color .2s;
}
.kpi-tile .kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}
.kpi-tile .kpi-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.kpi-tile.danger { border-color: var(--overdue-border); }
.kpi-tile.danger .kpi-value { color: #fca5a5; }
.kpi-tile.success .kpi-value { color: var(--success); }
/* Forecast tile — subtle blue so it reads as "projected, not booked". */
.kpi-tile.info    { border-color: rgba(96, 165, 250, 0.35); }
.kpi-tile.info .kpi-value { color: #93c5fd; }
@media (max-width: 720px) {
    .kpi-strip { grid-template-columns: 1fr; }
}

/* ---------- Cards grid ---------- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
}
.empty-state {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-muted);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex; flex-direction: column; gap: 14px;
    transition: background-color .2s, border-color .2s, box-shadow .2s;
    overflow: hidden;
}

/* ---------- Live site thumbnail ---------- */
.site-thumb {
    position: relative;
    display: block;
    margin: -18px -18px 0;            /* full-bleed to card edges, respecting the 18px card padding */
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--bg-elevated) linear-gradient(135deg, var(--bg-elevated), var(--bg-card-2));
    border-bottom: 1px solid var(--border);
    cursor: zoom-in;
}
.site-thumb-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    transition: transform .3s, opacity .2s;
}
.site-thumb:hover .site-thumb-img { transform: scale(1.02); }
.site-thumb-failed .site-thumb-img { opacity: 0; }
.site-thumb-failed::after {
    content: 'Preview unavailable';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    font-size: 12px;
    font-style: italic;
}
.site-thumb-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    padding: 3px 8px;
    border-radius: 999px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.site-thumb-badge-live { background: rgba(34, 197, 94, 0.75); color: #fff; }
.site-thumb-badge-dev  { background: rgba(96, 165, 250, 0.75); color: #0b1018; }

/* Compact variant for Kanban cards */
.site-thumb-compact {
    margin: -10px -12px 0;            /* matches .kanban-card padding (10px 12px) */
    aspect-ratio: 16 / 6.5;           /* shorter */
    border-radius: 0;
}
.site-thumb-compact .site-thumb-badge {
    top: 4px;
    left: 4px;
    font-size: 9px;
    padding: 2px 6px;
}

/* Larger preview inside the detail modal */
.detail-thumb-section { padding: 0; background: transparent; border: none; overflow: hidden; }
.detail-thumb-section .site-thumb {
    margin: 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    aspect-ratio: 16 / 8;
}
.card.overdue .site-thumb { border-bottom-color: rgba(239, 68, 68, 0.5); }
.card.overdue {
    background: var(--overdue-bg);
    border-color: var(--overdue-border);
    box-shadow: 0 0 0 1px var(--overdue-border), 0 0 22px var(--overdue-glow);
}
.card-header {
    display: flex; justify-content: space-between; gap: 12px;
    align-items: flex-start;
}
.card-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-title .name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-title .sub {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-date {
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
    flex-shrink: 0;
}
.card.overdue .card-date,
.card.overdue .card-title .sub,
.card.overdue .muted {
    color: #fca5a5;
}

/* Compact pip strip — one dot per stage. Filled = done. */
.stage-progress { display: flex; flex-direction: column; gap: 6px; }
.stage-pips {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}
.stage-pip {
    display: block;
    height: 10px;
    min-width: 0;
    padding: 0;
    border: 1px solid var(--border-strong);
    background: transparent;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, transform .08s;
}
.stage-pip:hover:not(.locked) {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.stage-pip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.stage-pip.locked { cursor: default; }
.stage-pip.done {
    background: var(--success);
    border-color: var(--success);
}
.stage-progress-caption {
    font-size: 11.5px;
    color: var(--text-muted);
    letter-spacing: 0.2px;
}
.card.overdue .stage-pip { border-color: rgba(252, 165, 165, 0.55); }
.card.overdue .stage-pip.done {
    background: #86efac;
    border-color: #86efac;
}
.card.overdue .stage-progress-caption { color: #fca5a5; }

/* Stage-breakdown accordion — sits below the pip strip inside each card. */
.stage-details {
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    margin-top: 2px;
}
.stage-details-summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    padding: 2px 0;
}
.stage-details-summary::-webkit-details-marker { display: none; }
.stage-details-summary:hover { color: var(--text); }
.stage-details-caret {
    display: inline-block;
    transition: transform .15s;
    font-size: 10px;
    line-height: 1;
}
.stage-details[open] .stage-details-caret { transform: rotate(90deg); }
.card.overdue .stage-details { border-top-color: rgba(239, 68, 68, 0.35); }
.card.overdue .stage-details-summary { color: #fca5a5; }

.stage-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 12px;
    font-size: 12.5px;
    margin-top: 8px;
}
.stage-grid-item {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
}
.stage-grid-item.locked { cursor: not-allowed; }
.stage-grid-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px; height: 14px;
    margin: 0;
    flex-shrink: 0;
}
.stage-grid-item.done { color: var(--success); }
.stage-grid-item.done .stage-text { text-decoration: line-through; }
.card.overdue .stage-grid-item { color: #fcd0d0; }
.card.overdue .stage-grid-item.done { color: #86efac; }

.card-meta {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.card-meta strong { color: var(--text); font-weight: 500; }
/* Dashboard card: address row is truncated on narrow viewports but kept full in the tooltip. */
.card-address {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-footer {
    display: flex; gap: 8px;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.card.overdue .card-footer { border-top-color: rgba(239, 68, 68, 0.4); }
.card-footer .btn { flex: 1; }

.overdue-pill {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    padding: 3px 8px;
    border-radius: 999px;
}

/* Days-until-auction chip. Level dictates colour — critical (red) → info (blue-ish). */
.countdown-pill {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 999px;
    margin-bottom: 2px;
}
.countdown-pill.level-critical { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.countdown-pill.level-urgent   { background: rgba(245, 158, 11, 0.22); color: #fbbf24; }
.countdown-pill.level-warn     { background: rgba(245, 158, 11, 0.12); color: #fbd27a; }
.countdown-pill.level-info     { background: rgba(96, 165, 250, 0.15); color: #93c5fd; }

/* ---------- Forms ---------- */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 720px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid > label,
.detail-section .form-grid > label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    min-width: 0;
}
.form-grid > label > span { font-weight: 500; }
.form-actions {
    display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 18px;
}
.toggle-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    min-height: 42px;
}
.toggle-row input { flex-shrink: 0; }
.toggle-row span { font-weight: 500; }

/* ---------- Tables (users / packages) ---------- */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.data-table th, .data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}
.data-table th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--bg-card-2);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-admin { background: rgba(245, 158, 11, 0.15); color: var(--accent); }
.badge-inactive { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* ---------- Modal ---------- */
.modal-root {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: grid; place-items: center;
    padding: 24px;
    z-index: 100;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 18px;
}
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text); background: var(--bg-card-2); }

/* ---------- Toasts ---------- */
.toast-root {
    position: fixed; bottom: 20px; right: 20px;
    z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 13px;
    pointer-events: auto;
    min-width: 240px;
    max-width: 360px;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* ---------- Filter bar ---------- */
.filter-bar {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    margin-bottom: 18px;
}
.filter-bar select, .filter-bar input {
    width: auto;
    min-width: 180px;
}
.filter-bar .spacer { flex: 1; }

/* ---------- Login section copy-button row ---------- */
.login-copy-row {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
}

/* ---------- Notes section ---------- */
.notes-section .note-add {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 12px;
}
.notes-section .note-add textarea {
    flex: 1;
    min-height: 60px;
}
.notes-section .note-add .btn { flex-shrink: 0; }
.notes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
    padding-right: 4px;
}
.note {
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.note-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.note-head .author { color: var(--accent); font-weight: 600; }
.note-head .time { flex: 1; }
.note-delete {
    background: transparent;
    border: none;
    color: var(--text-faint);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}
.note-delete:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }
.note-body {
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text);
}

/* ---------- Detail modal specific ---------- */
.detail-section {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 14px;
}
.detail-section h4 {
    margin: 0 0 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-tag {
    font-size: 10px;
    letter-spacing: 0.5px;
    background: var(--bg-card-2);
    color: var(--text-faint);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}
.section-tag.qf-on  { background: rgba(34, 197, 94, 0.2);  color: #86efac; }
.section-tag.qf-off { background: rgba(100, 100, 100, 0.2); color: var(--text-muted); }

/* ---------- Invoices ---------- */
.invoices-section .invoice-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.invoice-row {
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.invoice-top {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.invoice-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.invoice-status {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    padding: 3px 8px;
    border-radius: 999px;
}
.invoice-status-draft   { background: rgba(150, 150, 150, 0.2); color: var(--text-muted); }
.invoice-status-sent    { background: rgba(96, 165, 250, 0.2);  color: #93c5fd; }
.invoice-status-paid    { background: rgba(34, 197, 94, 0.2);   color: #86efac; }
.invoice-status-overdue { background: rgba(239, 68, 68, 0.2);   color: #fca5a5; }
.invoice-status-void    { background: rgba(150, 150, 150, 0.15); color: var(--text-faint); text-decoration: line-through; }
.invoice-desc { color: var(--text); font-size: 13px; }
.invoice-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
}
.invoice-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}
.invoices-section .invoice-add {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.invoices-section h4 { display: flex; align-items: center; gap: 8px; }

/* Invoice-type pills (RECURRING / ESTIMATE) */
.invoice-type-pill {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    padding: 3px 8px;
    border-radius: 999px;
}
.invoice-type-pill.recurring {
    background: rgba(168, 85, 247, 0.2);
    color: #d8b4fe;
    border: 1px solid rgba(168, 85, 247, 0.4);
}
.invoice-type-pill.estimate {
    background: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
}
.invoice-row-recurring {
    border-left: 3px solid rgba(168, 85, 247, 0.6);
    background: linear-gradient(90deg, rgba(168, 85, 247, 0.06), var(--bg-card-2));
}

/* Recurring-profile panel — modelled on Ruby Auctions' Quickfile template.
   Shown only for invoice_type='RECURRING' rows; visualises the RecurringProfileSettings block
   (interval / next due / sent count / auto-bill / start) plus the first line item. */
.recurring-panel {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    background: rgba(168, 85, 247, 0.07);
    border: 1px solid rgba(168, 85, 247, 0.18);
}
.recurring-panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px 16px;
}
.recurring-kpi-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 2px;
}
.recurring-kpi-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.recurring-line {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed rgba(168, 85, 247, 0.2);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    flex-wrap: wrap;
}
.recurring-line-desc {
    font-size: 13px;
    color: var(--text);
}

/* Address block header on the new-submission form — separates Pipedrive-prefilled
   address inputs from the rest of the grid. Inputs themselves inherit .form-grid styling. */
.address-block-header {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}

/* Invoice editor modal: stacked sections with a labelled heading between each .form-grid.
   .invoice-recurring-fields inherits the recurring-panel tint so operators see at a
   glance that those inputs drive the Quickfile RecurringProfileSettings block. */
.invoice-editor .invoice-editor-section + .invoice-editor-section {
    margin-top: 16px;
}
.invoice-editor-heading {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0 0 8px;
}
.invoice-editor .invoice-recurring-fields {
    padding: 12px;
    border-radius: 6px;
    background: rgba(168, 85, 247, 0.06);
    border: 1px solid rgba(168, 85, 247, 0.18);
}
.invoice-editor .invoice-recurring-fields .invoice-editor-heading {
    color: #d8b4fe;
}

.invoice-qf-link {
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    margin-left: auto;
}
.invoice-qf-link:hover {
    background: var(--bg-elevated);
    color: var(--accent-hover);
}

/* Quickfile client picker */
.qf-candidate-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}
.qf-candidate {
    text-align: left;
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    transition: border-color .15s, background .15s;
}
.qf-candidate:hover {
    border-color: var(--accent);
    background: var(--bg-card);
}
.qf-candidate-name { font-weight: 600; font-size: 14px; }
.qf-candidate-meta { margin-top: 2px; }
.detail-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 10px;
    padding: 4px 0;
    font-size: 13px;
}
.detail-row .label { color: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .view-app { grid-template-columns: 1fr; }
    .sidebar {
        position: static; height: auto;
        flex-direction: row; overflow-x: auto;
        padding: 12px;
    }
    .sidebar-brand { flex-shrink: 0; }
    .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; }
    .nav-link { flex-shrink: 0; }
    .sidebar-footer { flex-direction: row; border-top: none; padding-top: 0; border-left: 1px solid var(--border); padding-left: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .stage-pips { grid-template-columns: repeat(7, 1fr); gap: 4px; }
    .stage-grid { grid-template-columns: 1fr; }
    .detail-row { grid-template-columns: 1fr; gap: 2px; }
    .detail-row .label { font-size: 11px; }
}

/* ---------- Pipedrive lookup ---------- */
.pipedrive-lookup {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pipedrive-lookup-header { text-transform: uppercase; letter-spacing: 0.04em; }
.pipedrive-search-wrap { position: relative; }
.pipedrive-search-input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: inherit;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
}
.pipedrive-search-input:focus { outline: none; border-color: var(--accent); }
.pipedrive-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.pipedrive-result {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.pipedrive-result:last-child { border-bottom: none; }
.pipedrive-result:hover,
.pipedrive-result.is-active { background: var(--bg-card-2); }
.pipedrive-result-name { font-size: 14px; font-weight: 500; }
.pipedrive-result-sub { margin-top: 2px; font-size: 12px; }
.pipedrive-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: var(--accent-hover);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
}
.pipedrive-banner strong { color: inherit; }
.pipedrive-banner-text { color: inherit; }
.pipedrive-banner .btn { margin-left: auto; }

.person-picker { display: flex; flex-direction: column; gap: 8px; }
.person-pick-btn {
    text-align: left;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: inherit;
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.person-pick-btn:hover { background: var(--bg-card-2); border-color: var(--accent); }

/* ---------- Stage filter (multi-check popover) ---------- */
.stage-filter { position: relative; }
.stage-filter-btn { white-space: nowrap; }
.stage-filter-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 14px 16px;
    z-index: 30;
    min-width: 260px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}
.stage-filter-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.stage-filter-list { display: flex; flex-direction: column; gap: 6px; }
.stage-filter-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 0;
}
.stage-filter-check input[type="checkbox"] { margin: 0; }
@media (max-width: 560px) {
    .stage-filter-popover { right: -8px; min-width: 240px; }
}

/* ---------- Analytics / Audit ---------- */
.analytics-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
}
.analytics-section h3 { margin: 0 0 14px; font-size: 15px; }
.analytics-section p { margin: 10px 0 0; }
.analytics-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 8px;
}
@media (max-width: 720px) {
    .analytics-kpis { grid-template-columns: 1fr; }
}
.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.analytics-table th,
.analytics-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.analytics-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.4px;
}
.analytics-table td.num,
.analytics-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.analytics-table tbody tr:hover { background: var(--bg-card-2); }

.analytics-wip { display: flex; flex-direction: column; gap: 6px; }
.wip-row {
    display: grid;
    grid-template-columns: minmax(0, 220px) 1fr 40px;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.wip-label { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wip-bar-track {
    height: 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.wip-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-strong), var(--accent));
    border-radius: 999px;
    transition: width .3s;
}
.wip-count { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.audit-action {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    letter-spacing: 0.5px;
}
.audit-view { background: rgba(96, 165, 250, 0.15); color: #93c5fd; }
.audit-copy { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

/* ---------- View toggle (Cards / Kanban) ---------- */
.view-toggle {
    display: inline-flex;
    gap: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}
.view-toggle .view-toggle-btn {
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    padding: 5px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.view-toggle .view-toggle-btn:hover { color: var(--text); }
.view-toggle .view-toggle-btn.active {
    background: var(--bg-card);
    border-color: var(--border-strong);
    color: var(--text);
    font-weight: 600;
}

/* ---------- Kanban board ---------- */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
    align-items: flex-start;
}
/* On wider screens, always show all 8 columns side-by-side with horizontal scroll if needed */
@media (min-width: 1400px) {
    .kanban-board {
        grid-template-columns: repeat(8, minmax(240px, 1fr));
        overflow-x: auto;
    }
}
.kanban-col {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 120px;
    max-height: calc(100vh - 240px);
}
.kanban-col-done {
    border-color: var(--success);
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
}
.kanban-col-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius) var(--radius) 0 0;
    position: sticky;
    top: 0;
    z-index: 1;
}
.kanban-col-done .kanban-col-header {
    background: rgba(34, 197, 94, 0.08);
    border-bottom-color: rgba(34, 197, 94, 0.35);
}
.kanban-col-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kanban-col-done .kanban-col-title { color: #86efac; }
.kanban-col-count {
    flex-shrink: 0;
    background: var(--bg-card-2);
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 22px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.kanban-col-done .kanban-col-count {
    background: rgba(34, 197, 94, 0.25);
    color: #bbf7d0;
}
.kanban-col-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
}
.kanban-col-empty {
    padding: 18px 6px;
    text-align: center;
    font-style: italic;
}
.kanban-card {
    background: var(--bg-card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
    transition: transform .12s, border-color .15s, box-shadow .15s;
}
.kanban-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}
.kanban-card.overdue {
    background: var(--overdue-bg);
    border-color: var(--overdue-border);
    box-shadow: 0 0 0 1px var(--overdue-border);
}
.kanban-card.overdue:hover { box-shadow: 0 0 0 1px var(--overdue-border), 0 4px 14px var(--overdue-glow); }
.kanban-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kanban-card.overdue .kanban-card-title { color: #fecaca; }
.kanban-card-domain {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.kanban-card.overdue .kanban-card-domain { color: #fca5a5; }
/* Kanban card: compact "City · Postcode" line. Full address is in the tooltip title. */
.kanban-card-address {
    font-size: 11px;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 1px;
}
.kanban-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 2px;
}
.kanban-card-date {
    font-size: 11px;
    color: var(--text-faint);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}
.kanban-card.overdue .kanban-card-date { color: #fcd0d0; }

/* ---------- Dashboard search ---------- */
.dashboard-search {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 240px;
    font-size: 13px;
    font-family: inherit;
}
.dashboard-search::placeholder { color: var(--text-faint); }
.dashboard-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}
.dashboard-search::-webkit-search-cancel-button { filter: invert(0.6); }
