/* ----------------------------------------------------------------------------
 * AppFlexer
 *
 * @package     AppFlexer
 * @author      Alex Tselegidis <info@alextselegidis.com>
 * @copyright   Copyright (c) Alex Tselegidis. All rights reserved.
 * @license     Proprietary - unauthorized copying, distribution or use is prohibited
 * ---------------------------------------------------------------------------- */

/* Page-to-page navigation crossfades instead of flashing white; the sidebar and top bar stay put */
@view-transition {
    navigation: auto;
}

#header {
    view-transition-name: header;
}

#sidebar {
    view-transition-name: sidebar;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.15s;
}

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }
}

/* Smooth transitions on interactive elements only */
a,
.btn,
.nav-link,
.dropdown-item,
.list-group-item-action,
.card,
.page-link,
.form-control,
.form-select,
.input-group-text,
.badge {
    transition: background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out,
    color 0.15s ease-in-out,
    opacity 0.15s ease-in-out;
}

/* Design tokens - Bootstrap components all read these */
:root {
    /* Brand. Neutral charcoal (#333): quiet, works with any content. It is
       both the committing button and the accent (links, focus, the active item). */
    --bs-primary: #333333;
    --bs-primary-rgb: 51, 51, 51;
    --cv-primary-hover: #222222;
    --cv-primary-active: #111111;

    --cv-accent: #333333;
    --cv-accent-rgb: 51, 51, 51;
    --cv-accent-subtle: #f0f0f1;

    --bs-link-color: #333333;
    --bs-link-color-rgb: 51, 51, 51;
    --bs-link-hover-color: #222222;
    --bs-link-hover-color-rgb: 34, 34, 34;

    --bs-body-color: #1f2633;
    --bs-secondary-color: #667085;
    --bs-emphasis-color: #0f1520;

    /* Semantic colours, desaturated from the Bootswatch defaults. The bright teal
       and orange read as consumer-app; these hold up in a business report. */
    --bs-secondary: #6b6b76;
    --bs-secondary-rgb: 107, 107, 118;
    --bs-success: #0e8a63;
    --bs-success-rgb: 14, 138, 99;
    --bs-info: #2563d9;
    --bs-info-rgb: 37, 99, 217;
    --bs-warning: #b54708;
    --bs-warning-rgb: 181, 71, 8;
    --bs-danger: #c4321f;
    --bs-danger-rgb: 196, 50, 31;

    /* Tinted pill palette: background / border / text for each semantic colour */
    --bs-primary-bg-subtle: #f0f0f1;
    --bs-primary-border-subtle: #dcdcde;
    --bs-primary-text-emphasis: #222222;

    --bs-secondary-bg-subtle: #f2f2f4;
    --bs-secondary-border-subtle: #e3e3e8;
    --bs-secondary-text-emphasis: var(--cv-text-soft);

    --bs-success-bg-subtle: #e7f6ef;
    --bs-success-border-subtle: #c3e9d8;
    --bs-success-text-emphasis: #0a6a4c;

    --bs-info-bg-subtle: #ebf1fd;
    --bs-info-border-subtle: #cddcfa;
    --bs-info-text-emphasis: #1a4bab;

    --bs-warning-bg-subtle: #fdf3e7;
    --bs-warning-border-subtle: #f6dfc0;
    --bs-warning-text-emphasis: #93450a;

    --bs-danger-bg-subtle: #fdedeb;
    --bs-danger-border-subtle: #f8d3ce;
    --bs-danger-text-emphasis: #9a2516;

    /* System font stack: nothing to download, and it matches the host OS */
    --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --bs-body-font-size: 0.9375rem;

    /* Soft, generous corners; buttons are full pills */
    --bs-border-radius: 0.625rem;
    --bs-border-radius-sm: 0.5rem;
    --bs-border-radius-lg: 1rem;
    --bs-border-radius-xl: 1.25rem;

    /* Neutral ramp: white surfaces on a barely-grey canvas, separated by hairlines */
    --bs-border-color: #e4e4e8;
    --bs-border-color-translucent: rgba(15, 15, 20, 0.08);
    --cv-canvas: #f7f7f8;
    --cv-surface-muted: #f4f4f6;
    --cv-hairline: #ececf0;
    --cv-surface: #fff;
    --cv-surface-hover: #f7f7f9;
    --cv-surface-active: #ebebef;
    --cv-border-strong: #d6d6dc;
    --cv-control-border: #dcdce2;
    --cv-check-border: #c8c8d0;
    --cv-text-muted: #6b6b76;
    --cv-text-soft: #4a4a53;
    --cv-text-strong: #3a3a42;
    --cv-text-faint: #a0a0aa;
    --cv-topbar-bg: rgba(255, 255, 255, 0.92);

    /* Shadows only lift things that float: menus, modals, toasts */
    --bs-box-shadow-sm: 0 1px 2px rgba(15, 15, 20, 0.05);
    --bs-box-shadow: 0 6px 16px -4px rgba(15, 15, 20, 0.1), 0 2px 4px rgba(15, 15, 20, 0.04);
    --bs-box-shadow-lg: 0 24px 48px -12px rgba(15, 15, 20, 0.22);

    --bs-focus-ring-color: rgba(51, 51, 51, 0.25);

    /* App shell */
    --cv-sidebar-width: 15rem;
    --cv-topbar-height: 4rem;
}


/* Dark theme. Bootstrap's own [data-bs-theme=dark] block loads before this file and
   the :root above outweighs it, so every token set above is set again here. */
[data-bs-theme=dark] {
    color-scheme: dark;

    --bs-primary: #52525b;
    --bs-primary-rgb: 82, 82, 91;
    --cv-primary-hover: #63636d;
    --cv-primary-active: #44444c;

    --cv-accent: #d4d4d8;
    --cv-accent-rgb: 212, 212, 216;
    --cv-accent-subtle: rgba(212, 212, 216, 0.14);

    --bs-link-color: #d4d4d8;
    --bs-link-color-rgb: 212, 212, 216;
    --bs-link-hover-color: #f4f4f5;
    --bs-link-hover-color-rgb: 244, 244, 245;

    --bs-body-bg: #1a1d23;
    --bs-body-bg-rgb: 26, 29, 35;
    --bs-body-color: #dfe3ea;
    --bs-body-color-rgb: 223, 227, 234;
    --bs-secondary-color: #98a1b0;
    --bs-emphasis-color: #f4f6f9;
    --bs-tertiary-bg: #20242b;
    --bs-secondary-bg: #23272f;

    --bs-secondary: #8a93a3;
    --bs-secondary-rgb: 138, 147, 163;
    --bs-success: #3fb68b;
    --bs-success-rgb: 63, 182, 139;
    --bs-info: #6b9bf0;
    --bs-info-rgb: 107, 155, 240;
    --bs-warning: #e0954a;
    --bs-warning-rgb: 224, 149, 74;
    --bs-danger: #ec6a5a;
    --bs-danger-rgb: 236, 106, 90;

    --bs-primary-bg-subtle: rgba(212, 212, 216, 0.14);
    --bs-primary-border-subtle: rgba(212, 212, 216, 0.3);
    --bs-primary-text-emphasis: #f4f4f5;
    --bs-secondary-bg-subtle: rgba(152, 161, 176, 0.14);
    --bs-secondary-border-subtle: rgba(152, 161, 176, 0.28);
    --bs-secondary-text-emphasis: #c5ccd6;
    --bs-success-bg-subtle: rgba(63, 182, 139, 0.14);
    --bs-success-border-subtle: rgba(63, 182, 139, 0.3);
    --bs-success-text-emphasis: #7dd3b0;
    --bs-info-bg-subtle: rgba(107, 155, 240, 0.14);
    --bs-info-border-subtle: rgba(107, 155, 240, 0.3);
    --bs-info-text-emphasis: #a5c3f6;
    --bs-warning-bg-subtle: rgba(224, 149, 74, 0.14);
    --bs-warning-border-subtle: rgba(224, 149, 74, 0.3);
    --bs-warning-text-emphasis: #f0bd88;
    --bs-danger-bg-subtle: rgba(236, 106, 90, 0.14);
    --bs-danger-border-subtle: rgba(236, 106, 90, 0.3);
    --bs-danger-text-emphasis: #f4a69c;

    --bs-border-color: #2f3540;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.1);
    --cv-canvas: #121418;
    --cv-surface-muted: #23272f;
    --cv-hairline: #2a2f38;
    --cv-surface: #1a1d23;
    --cv-surface-hover: #20242b;
    --cv-surface-active: #2b303a;
    --cv-border-strong: #3d4451;
    --cv-control-border: #3a404c;
    --cv-check-border: #4f5665;
    --cv-text-muted: #98a1b0;
    --cv-text-soft: #b6bdc9;
    --cv-text-strong: #d5dae2;
    --cv-text-faint: #6c7482;
    --cv-topbar-bg: rgba(26, 29, 35, 0.92);

    --bs-box-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --bs-box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
    --bs-box-shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);

    --bs-focus-ring-color: rgba(212, 212, 216, 0.3);
}

/* The dark mark on the light theme, the white one on the dark theme */
[data-bs-theme=dark] .logo-on-light,
[data-bs-theme=light] .logo-on-dark,
:root:not([data-bs-theme]) .logo-on-dark {
    display: none !important;
}

/* Links are coloured, not underlined; the underline appears on hover inside the page */
a {
    color: var(--bs-link-color);
    text-decoration: none;
}

a:hover {
    color: var(--bs-link-hover-color);
}

.app-content a:not(.btn):not(.dropdown-item):not(.nav-link):not(.page-link):hover {
    text-decoration: underline;
}

/* Labels use a different color */
.form-label {
    color: var(--cv-text-strong) !important;
}

/* Headings: heavier and slightly tightened */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--bs-emphasis-color);
}

.text-dark {
    color: var(--bs-emphasis-color) !important;
}

.btn-primary {
    --bs-btn-bg: var(--bs-primary);
    --bs-btn-border-color: var(--bs-primary);
    --bs-btn-hover-bg: var(--cv-primary-hover);
    --bs-btn-hover-border-color: var(--cv-primary-hover);
    --bs-btn-active-bg: var(--cv-primary-active);
    --bs-btn-active-border-color: var(--cv-primary-active);
    --bs-btn-disabled-bg: var(--bs-primary);
    --bs-btn-disabled-border-color: var(--bs-primary);
}

/* Secondary actions inside cards: a white pill, not a coloured outline */
.btn-outline-primary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-bg: var(--cv-surface);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--cv-surface-muted);
    --bs-btn-hover-border-color: var(--cv-border-strong);
    --bs-btn-active-color: var(--bs-emphasis-color);
    --bs-btn-active-bg: var(--cv-surface-active);
    --bs-btn-active-border-color: var(--cv-border-strong);
}

.bg-primary {
    background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity, 1)) !important;
}

/* Dashboard card image gradient background */
.card .card-img-top {
    background: var(--cv-surface-muted) !important;
}

/* Markdown announcement bodies: no stray gap under the last paragraph */
.announcement-body > :last-child {
    margin-bottom: 0;
}

/* Card footer reads as a quiet strip, not a second surface */
.card .card-footer {
    background-color: transparent !important;
    border-top-color: var(--cv-hairline) !important;
}

/* Neutral surfaces */
.bg-light {
    background-color: var(--cv-canvas) !important;
}

.bg-white {
    background-color: var(--cv-surface) !important;
}

.bg-body-secondary {
    background-color: var(--cv-surface-muted) !important;
}

.bg-body-tertiary {
    background-color: var(--cv-surface-hover) !important;
}

.main-layout {
    background-color: var(--cv-canvas) !important;
}

.text-muted {
    color: var(--cv-text-muted) !important;
}

.text-body-secondary {
    color: var(--cv-text-muted) !important;
}

/* One secondary column per list table appears at md, so the record name stops
   claiming the whole row there rather than at lg */
@media (min-width: 768px) {
    .w-md-auto {
        width: auto !important;
    }
}

/* Responsive width utilities for lg breakpoint */
@media (min-width: 992px) {
    .w-lg-auto {
        width: auto !important;
    }

    .flex-lg-grow-0 {
        flex-grow: 0 !important;
    }

    .rounded-lg-3 {
        border-radius: var(--bs-border-radius-lg) !important;
    }

    .shadow-lg-sm {
        box-shadow: var(--bs-box-shadow-sm) !important;
    }

    .min-vh-lg-auto {
        min-height: auto !important;
    }

    .table-responsive {
        overflow: visible;
    }
}

/* Card hover effect */
.card-hover-move {
    transition: transform 0.2s ease-in-out,
    background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;
}

.card-hover-move:hover {
    transform: translateY(-2px);
}

/* Link image styling - stretch for og_image, contain for favicon */
.card .card-img-top.img-cover {
    object-fit: cover;
}

.card .card-img-top.img-contain {
    object-fit: contain;
}

/* Equal width buttons */
.btn-equal-width {
    min-width: 120px;
}

/* Buttons are pills; neutral ones are white with a hairline border */
.btn {
    --bs-btn-padding-x: 1.125rem;
    --bs-btn-padding-y: 0.5rem;
    --bs-btn-font-weight: 600;
    --bs-btn-focus-box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
    border-radius: var(--bs-border-radius-pill);
}

.btn-sm {
    --bs-btn-padding-x: 0.875rem;
    --bs-btn-padding-y: 0.3rem;
}

.btn-light {
    --bs-btn-bg: var(--cv-surface);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-hover-bg: var(--cv-surface-muted);
    --bs-btn-hover-border-color: var(--cv-border-strong);
    --bs-btn-active-bg: var(--cv-surface-active);
    --bs-btn-active-border-color: var(--cv-border-strong);
}

.btn-light.border {
    border-color: var(--bs-border-color) !important;
}

.btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-hover-bg: var(--cv-surface-muted);
    --bs-btn-hover-border-color: var(--cv-border-strong);
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-active-bg: var(--cv-surface-active);
    --bs-btn-active-border-color: var(--cv-border-strong);
}

/* Clean table design */
.table {
    border-collapse: separate;
    border-spacing: 0;
}

/* Rows are dense on a pointer and roomy on a thumb - see the touch-target block
   near the end of the file for the phone value */
.table > :not(caption) > * > * {
    border-bottom-width: 1px;
    border-bottom-color: var(--cv-hairline);
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
}

/* A row is exactly one line tall. Cells do not wrap, and the wide text cells - a
   record name or a link - cut off with an ellipsis; the full text is on the detail
   page. `width: 0` on the inner block is what makes it work: a cell whose content
   is nowrap has the whole string as its minimum width, which would push the table
   out of its card, and a percentage `min-width` is ignored while the browser sizes
   the columns - so the cell asks for nothing and then fills the column it gets. */
.table td,
.table th {
    white-space: nowrap;
}

.table td .fw-medium,
.table td a:not(.dropdown-item) {
    display: block;
    width: 0;
    min-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Auto layout hands leftover width to whichever column happens to be widest, which
   is usually a date range that does not need it. These two preferences aim it at the
   two columns that do; they are preferences, so a column still keeps its content
   width when the table is tight. */
.table td:has(> .fw-medium) {
    width: 32%;
}

.table td:has(> a:not(.dropdown-item)) {
    width: 22%;
}

/* Remove last row border */
.table > tbody > tr:last-child > * {
    border-bottom: 0;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--cv-surface-hover);
}

.table-hover > tbody > tr:hover > * {
    background-color: var(--cv-surface-hover);
}

/* Table header: quiet sentence-case labels on white, one hairline underneath */
.table-light-header > thead {
    background-color: var(--cv-surface);
}

.table-light-header > thead > tr > th {
    background-color: var(--cv-surface);
    color: var(--cv-text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    border-bottom: 1px solid var(--bs-border-color);
    transition: background-color 0.15s ease-in-out;
}

/* A checkbox is sized in em, so the 0.75rem header type would leave the select-all
   box smaller than the ones in the rows below it */
.table-light-header > thead > tr > th .form-check-input {
    font-size: 1rem;
}

.table-light-header > thead > tr > th:has(a):hover {
    background-color: var(--cv-surface-muted);
}

.table-light-header > thead > tr > th a {
    color: var(--cv-text-muted);
}

.table-light-header > thead > tr > th a:hover {
    color: var(--bs-emphasis-color);
}

/* Card with table - zero padding on card-body */
.card-table > .card-body {
    padding: 0;
}

/* With no filter row above it, the header row is the card's top edge; round its
   corner cells so their white fill does not square off the card's corners */
.card-table > .card-body > .table-responsive:first-child thead > tr:first-child > :first-child {
    border-top-left-radius: var(--bs-card-inner-border-radius);
}

.card-table > .card-body > .table-responsive:first-child thead > tr:first-child > :last-child {
    border-top-right-radius: var(--bs-card-inner-border-radius);
}

/* Filter/search section above table */
.card-table .table-filters {
    padding: 1rem;
    border-bottom: 1px solid var(--cv-hairline);
}

/* Pagination section below table */
.card-table .table-pagination {
    padding: 1rem;
    border-top: 1px solid var(--cv-hairline);
}

/* Fix pagination styling */
.pagination {
    gap: 0.25rem;
}

.pagination .page-item .page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.125rem;
    height: 2.125rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--bs-border-radius-sm);
    color: var(--cv-text-soft);
    background-color: transparent;
    border-color: transparent;
    border-radius: var(--bs-border-radius-pill);
}

.pagination .page-item .page-link:hover {
    color: var(--bs-emphasis-color);
    background-color: var(--cv-surface-muted);
    border-color: transparent;
}

.pagination .page-item.active .page-link {
    color: #fff;
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

.pagination .page-item.disabled .page-link {
    color: var(--cv-text-faint);
    background-color: transparent;
    border-color: transparent;
}

.pagination .page-item .page-link i {
    font-size: 0.75rem;
}

/* Table header sorting hover effect */
.table-dark th a {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0;
}

.table-dark th {
    vertical-align: middle;
}

.table-dark th a:hover {
    opacity: 0.8;
}

.table-dark th a::after {
    content: '\F282';
    font-family: 'bootstrap-icons';
    margin-left: 0.5rem;
    opacity: 0;
    font-size: 0.75rem;
    transition: opacity 0.15s ease-in-out;
}

.table-dark th a:hover::after {
    opacity: 0.6;
}

/* Borderless icon button, used for the row action and note menus. Transparent
   rather than a white fill so it follows the row tint on hover. */
.btn-icon {
    --bs-btn-color: var(--cv-text-soft);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--cv-surface-muted);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--bs-emphasis-color);
    --bs-btn-active-bg: var(--cv-surface-active);
    --bs-btn-active-border-color: transparent;
    --bs-btn-padding-x: 0.5rem;
    border-radius: var(--bs-border-radius-pill);
}

/* Row editors (invoice lines, survey questions) on a phone: each row stacks, its first cell on a
   line of its own and the rest side by side under it (--stack-cols per row), each labelled from
   data-label since the header row is hidden */
@media (max-width: 767.98px) {
    .stack-table thead {
        display: none;
    }

    .stack-table tr {
        display: grid;
        grid-template-columns: repeat(var(--stack-cols, 3), minmax(0, 1fr));
        gap: 0.5rem;
        padding: 0.75rem 0;
        border-bottom: 1px solid var(--cv-hairline);
    }

    .stack-table td {
        padding: 0 !important;
        border: 0;
    }

    .stack-table td:first-child {
        grid-column: 1 / -1;
    }

    .stack-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.25rem;
        font-size: 0.75rem;
        color: var(--cv-text-muted);
    }
}

/* The Setup menu swipes sideways on a phone; its scrollbar would only add a grey bar */
#setup-nav {
    scrollbar-width: none;
}

@media (max-width: 991.98px) {
    /* Fade the right edge so the cut-off items read as "swipe for more" */
    #setup-nav {
        mask-image: linear-gradient(to right, #000 85%, transparent);
    }
}

/* Calendar search and type filter: one line, the full width on a phone, a fixed width beside the month above it */
.calendar-filters {
    width: 100%;
}

@media (min-width: 768px) {
    .calendar-filters {
        width: 28rem;
    }
}

/* Flex children must be allowed to shrink, otherwise long text and
   .table-responsive scroll containers push the whole page sideways */
.flex-grow-1 {
    min-width: 0;
}

/* Search input groups: white addon, and a single focus ring around the
   whole group instead of a square one clipping over the addon/button */
.input-group-text.border-end-0 {
    background-color: var(--cv-surface);
}

.input-group:focus-within {
    border-radius: var(--bs-border-radius);
    box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
}

.input-group:focus-within > .form-control:focus,
.input-group:focus-within > .form-select:focus {
    box-shadow: none;
}

.input-group:focus-within > .form-control,
.input-group:focus-within > .form-select,
.input-group:focus-within > .input-group-text,
.input-group:focus-within > .btn {
    border-color: var(--cv-accent);
}

/* Long URLs and email addresses must wrap instead of spilling out of a card */
.card-body a {
    overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
 * Modern UI pass - surfaces, badges, controls
 * -------------------------------------------------------------------------- */

/* Cards are flat white surfaces on a hairline border; only floating layers cast shadows */
.card {
    --bs-card-border-radius: var(--bs-border-radius-lg);
    --bs-card-inner-border-radius: calc(var(--bs-border-radius-lg) - 1px);
    --bs-card-cap-bg: transparent;
    --bs-card-spacer-x: 1.25rem;
}

.card.border-0,
.shadow-sm {
    border: 1px solid var(--bs-border-color) !important;
    box-shadow: none !important;
}

.card-header {
    border-bottom-color: var(--cv-hairline);
    padding-top: 1rem;
    padding-bottom: 1rem;
    font-weight: 700;
}

.card-header h5,
.card-header .h6,
.card-header h6 {
    font-weight: 700;
}

/* Badges: quiet tinted pills instead of saturated blocks */
.badge {
    padding: 0.35em 0.7em;
    font-weight: 500;
    font-size: 0.75em;
    border: 1px solid transparent;
    border-radius: var(--bs-border-radius-pill);
}

.badge.bg-primary {
    background-color: var(--bs-primary-bg-subtle) !important;
    border-color: var(--bs-primary-border-subtle);
    color: var(--bs-primary-text-emphasis) !important;
}

.badge.bg-secondary {
    background-color: var(--bs-secondary-bg-subtle) !important;
    border-color: var(--bs-secondary-border-subtle);
    color: var(--bs-secondary-text-emphasis) !important;
}

.badge.bg-success {
    background-color: var(--bs-success-bg-subtle) !important;
    border-color: var(--bs-success-border-subtle);
    color: var(--bs-success-text-emphasis) !important;
}

.badge.bg-info {
    background-color: var(--bs-info-bg-subtle) !important;
    border-color: var(--bs-info-border-subtle);
    color: var(--bs-info-text-emphasis) !important;
}

.badge.bg-warning {
    background-color: var(--bs-warning-bg-subtle) !important;
    border-color: var(--bs-warning-border-subtle);
    color: var(--bs-warning-text-emphasis) !important;
}

.badge.bg-danger {
    background-color: var(--bs-danger-bg-subtle) !important;
    border-color: var(--bs-danger-border-subtle);
    color: var(--bs-danger-text-emphasis) !important;
}

.badge.bg-light {
    background-color: var(--cv-surface-muted) !important;
    border-color: var(--cv-hairline);
    color: var(--cv-text-soft) !important;
}

/* Form controls: tall, soft and with a brand-coloured focus ring */
.form-control,
.form-select {
    border-color: var(--cv-control-border);
    border-radius: var(--bs-border-radius);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--cv-accent);
    box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
}

/* Roomier single-line inputs, but leave textareas alone so `rows` still means rows */
input.form-control,
.form-select {
    padding-top: 0.5625rem;
    padding-bottom: 0.5625rem;
}

.form-control::placeholder {
    color: var(--cv-text-faint);
}

.form-check-input:checked {
    background-color: var(--cv-accent);
    border-color: var(--cv-accent);
}

.form-check-input:focus {
    border-color: var(--cv-accent);
    box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color);
}

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
}

.form-check-input {
    border-color: var(--cv-check-border);
}

/* Dropdowns and modals */
.dropdown-menu {
    --bs-dropdown-bg: var(--cv-surface);
    --bs-dropdown-link-color: var(--bs-body-color);
    --bs-dropdown-link-hover-color: var(--bs-emphasis-color);
    --bs-dropdown-link-hover-bg: var(--cv-surface-hover);
    --bs-dropdown-header-color: var(--cv-text-muted);
    min-width: 11rem;
    border-color: var(--cv-hairline);
    border-radius: var(--bs-border-radius-lg);
    box-shadow: var(--bs-box-shadow);
    padding: 0.375rem;
    font-size: 0.875rem;
}

.dropdown-menu.show {
    animation: cv-dropdown-in 0.12s ease-out;
}

@keyframes cv-dropdown-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .dropdown-menu.show {
        animation: none;
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    border-radius: var(--bs-border-radius-sm);
    padding: 0.5rem 0.75rem;
    font-weight: 500;
}

.dropdown-item:focus-visible {
    outline: 0;
    background-color: var(--cv-surface-hover);
    box-shadow: inset 0 0 0 2px var(--cv-accent);
}

.dropdown-item.active,
.dropdown-item:active {
    color: var(--cv-accent);
    background-color: var(--cv-accent-subtle);
}

.dropdown-item i {
    width: 1rem;
    flex-shrink: 0;
    text-align: center;
    color: var(--cv-text-muted);
}

.dropdown-item.active i,
.dropdown-item:hover i {
    color: inherit;
}

/* Destructive actions turn red on a red tint, icon included */
.dropdown-item.text-danger:hover,
.dropdown-item.text-danger:focus,
.dropdown-item.text-danger:active {
    color: var(--bs-danger-text-emphasis) !important;
    background-color: var(--bs-danger-bg-subtle);
}

.dropdown-item.text-danger i {
    color: inherit;
}

.dropdown-item:disabled,
.dropdown-item.disabled {
    color: var(--cv-text-faint);
}

.dropdown-header {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.5rem 0.75rem 0.25rem;
}

.dropdown-divider {
    margin: 0.375rem -0.375rem;
    border-top-color: var(--cv-hairline);
}

.modal-content {
    border: 0;
    border-radius: var(--bs-border-radius-xl);
    box-shadow: var(--bs-box-shadow-lg);
}

.modal-header,
.modal-footer {
    border-color: var(--cv-hairline);
}

/* List groups used as row lists */
.list-group-flush > .list-group-item {
    border-color: var(--cv-hairline);
}

.list-group {
    --bs-list-group-action-color: var(--bs-body-color);
    --bs-list-group-action-hover-color: var(--bs-emphasis-color);
}

.list-group-item-action:hover {
    background-color: var(--cv-surface-hover);
}

/* Toasts */
.toast {
    border-radius: var(--bs-border-radius-lg);
    box-shadow: var(--bs-box-shadow);
}

/* Breadcrumb reads as a quiet trail, and scrolls rather than clipping when a
   deep trail does not fit on a phone */
.breadcrumb {
    --bs-breadcrumb-divider-color: var(--cv-text-faint);
    font-weight: 500;
    scrollbar-width: none;
}

.breadcrumb::-webkit-scrollbar {
    display: none;
}

/* --------------------------------------------------------------------------
 * App shell: sidebar, top bar, page header
 *
 * From lg up the sidebar is a fixed column and the page scrolls beside it.
 * Below lg it is Bootstrap's offcanvas-lg drawer, opened from the top bar, so
 * no layout script is needed at either size.
 * -------------------------------------------------------------------------- */

.main-layout {
    min-height: 100vh;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.app-sidebar {
    --bs-offcanvas-width: 17rem;
    background-color: var(--cv-surface);
    /* The whole column scrolls, brand row included, so the scrollbar runs the full height */
    overflow-y: auto;
    scrollbar-width: thin;
}

@media (min-width: 992px) {
    .app-sidebar {
        position: sticky;
        top: 0;
        flex: 0 0 var(--cv-sidebar-width);
        width: var(--cv-sidebar-width);
        height: 100vh;
        border-right: 1px solid var(--bs-border-color);
    }
}

/* offcanvas-lg turns the drawer into a plain block from lg up, which would drop
   the column layout below; keep it a flex column at every size */
.app-sidebar,
.app-sidebar.offcanvas-lg {
    display: flex;
    flex-direction: column;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    flex: 0 0 var(--cv-topbar-height);
    padding: 0 1.25rem;
}

.app-sidebar .btn-close {
    opacity: 0.7;
}

.app-sidebar-nav {
    flex: 1 0 auto;
    padding: 0.25rem 0.75rem 1.5rem;
}

.app-sidebar-heading {
    padding: 1.25rem 0.75rem 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--cv-text-faint);
}

.app-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.5rem;
    padding: 0.375rem 0.75rem;
    margin-bottom: 0.125rem;
    border-radius: var(--bs-border-radius);
    color: var(--cv-text-strong);
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

.app-sidebar-link i {
    font-size: 1.125rem;
    color: var(--cv-text-muted);
    transition: color 0.15s ease-in-out;
}

.app-sidebar-link:hover {
    background-color: var(--cv-surface-muted);
    color: var(--bs-emphasis-color);
}

.app-sidebar-link.active {
    background-color: var(--cv-accent-subtle);
    color: var(--bs-emphasis-color);
    font-weight: 600;
}

.app-sidebar-link.active i {
    color: var(--cv-accent);
}

/* Collapsed (desktop only): an icon rail; the labels come back as tooltips via title */
@media (min-width: 992px) {
    .app-sidebar {
        transition: flex-basis 0.2s ease-in-out, width 0.2s ease-in-out;
    }

    .sidebar-collapsed .app-sidebar {
        flex-basis: 4.5rem;
        width: 4.5rem;
    }

    .sidebar-collapsed .app-sidebar-brand {
        justify-content: center;
        padding: 0;
    }

    .sidebar-collapsed .app-sidebar-brand span,
    .sidebar-collapsed .app-sidebar-link span {
        display: none;
    }

    .sidebar-collapsed .app-sidebar-brand img {
        margin: 0 !important;
    }

    .sidebar-collapsed .app-sidebar-heading {
        height: 1px;
        padding: 0;
        margin: 0.75rem 0.5rem;
        overflow: hidden;
        background-color: var(--cv-hairline);
    }

    .sidebar-collapsed .app-sidebar-nav {
        padding-inline: 0.75rem;
    }

    .sidebar-collapsed .app-sidebar {
        scrollbar-width: none;
    }

    .sidebar-collapsed .app-sidebar-link {
        justify-content: center;
        padding: 0.375rem 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar {
        transition: none !important;
    }
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: var(--cv-topbar-height);
    padding: 0 1rem;
    background-color: var(--cv-topbar-bg);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--bs-border-color);
}

@media (min-width: 992px) {
    .app-topbar {
        padding: 0 2rem;
    }
}

/* The workspace switcher in the top bar: a pill showing the current workspace, its name truncated */
.app-workspace-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.5rem;
    max-width: 16rem;
    padding: 0 0.875rem;
}

.app-workspace-switcher > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-workspace-switcher + .dropdown-menu {
    max-width: 20rem;
}

/* Looks like a search field, opens the search dialog */
.app-search-trigger {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    max-width: 26rem;
    height: 2.5rem;
    padding: 0 0.875rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-pill);
    background-color: var(--cv-surface-muted);
    color: var(--cv-text-muted);
    font-size: 0.9375rem;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.app-search-trigger:hover {
    background-color: var(--cv-surface);
    border-color: var(--cv-border-strong);
}

@media (max-width: 575.98px) {
    .app-search-trigger {
        width: 2.5rem;
        justify-content: center;
        padding: 0;
    }
}

.app-search-trigger kbd {
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    background-color: var(--cv-surface);
    color: var(--cv-text-muted);
    font-size: 0.75rem;
}

.app-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background-color: var(--cv-accent-subtle);
    color: var(--cv-accent);
    font-size: 0.875rem;
    font-weight: 700;
    transition: box-shadow 0.15s ease-in-out;
}

/* The Add menu is a round plus, the same size as the avatar beside it */
.app-add-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border-radius: 50%;
    font-size: 1.125rem;
}

.app-avatar:hover,
.app-avatar[aria-expanded="true"] {
    box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}

.app-search-input .form-control {
    font-size: 1.125rem;
}

/* Spotlight results under the search field */
.app-spotlight {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 0.5rem;
    border-top: 1px solid var(--cv-hairline);
}

.app-spotlight .list-group-item {
    border: 0;
    border-radius: var(--bs-border-radius);
}

.app-spotlight-code {
    flex-shrink: 0;
    font-family: var(--bs-font-monospace);
    font-size: 0.8125rem;
    opacity: 0.65;
}

.app-spotlight-heading {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--cv-text-muted);
}

/* From a tablet up the search dialog sits clear of the top bar, with a taller field */
@media (min-width: 768px) {
    #search-modal .modal-dialog {
        margin-top: 15vh;
    }

    #search-modal .modal-body {
        padding: 0.75rem !important;
    }

    .app-search-input .form-control {
        padding-block: 0.875rem;
        font-size: 1.375rem;
    }

    .app-search-input .input-group-text {
        font-size: 1.375rem;
    }
}

/* Page header: the breadcrumb trail as a quiet line above a large title */
.app-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    padding: 1.5rem 1rem 1.25rem;
}

.app-content {
    flex: 1 0 auto;
    padding: 0 1rem 2rem;
}

@media (min-width: 992px) {
    .app-page-header {
        padding: 2rem 2rem 1.5rem;
    }

    .app-content {
        padding: 0 2rem 2.5rem;
    }

    /* A page whose content is a centred column (create forms, articles) lines its title and
       breadcrumb up with that column: the inset matches the gutter maths of .col-lg-8 / -9 */
    .app-main:has(.app-content > .row.justify-content-center > .col-lg-8) .app-page-header {
        padding-inline: calc(2rem + (100% - 2.5rem) / 6);
    }

    .app-main:has(.app-content > .row.justify-content-center > .col-lg-9) .app-page-header {
        padding-inline: calc(2rem + (100% - 2.5rem) / 8);
    }
}

.app-record-code {
    font-family: var(--bs-font-monospace);
    font-size: 0.8125rem;
    color: var(--cv-text-muted);
    user-select: all;
}

.app-page-title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .app-page-title {
        font-size: 1.5rem;
    }
}

/* The title already names the current page, so the trail stops at its parent,
   and a trail that would only hold the home icon is left out */
.app-page-header .breadcrumb {
    margin-bottom: 0.375rem !important;
}

.app-page-header .breadcrumb-item.active {
    display: none;
}

.app-page-header .breadcrumb:not(:has(> li:nth-child(3))) {
    display: none;
}

/* Page actions are yielded by every page as plain nav-links; they render as pill
   buttons here, and the "add" action becomes the primary one. */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.page-actions form {
    display: inline-flex;
    margin: 0 !important;
}

.page-actions .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    margin: 0 !important;
    padding: 0.4rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-pill);
    background-color: var(--cv-surface);
    color: var(--bs-body-color);
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.page-actions .nav-link:hover {
    background-color: var(--cv-surface-muted);
    border-color: var(--cv-border-strong);
}

.page-actions .nav-link i {
    color: var(--cv-text-muted);
}

.page-actions .nav-link:has(.bi-plus-square) {
    border-color: var(--bs-primary);
    background-color: var(--bs-primary);
    color: #fff;
}

.page-actions .nav-link:has(.bi-plus-square):hover {
    background-color: var(--cv-primary-hover);
}

.page-actions .nav-link:has(.bi-plus-square) i {
    color: #fff;
}

.page-actions .nav-link:has(.bi-trash):hover {
    color: var(--bs-danger);
}

.page-actions .nav-link:has(.bi-trash):hover i {
    color: var(--bs-danger);
}

.page-actions .bi-plus-square::before {
    content: "\F64D"; /* bi-plus-lg reads cleaner inside a pill */
}

.app-footer {
    padding: 0 1rem;
}

@media (min-width: 992px) {
    .app-footer {
        padding: 0 2rem;
    }
}

.app-footer .container {
    max-width: none;
    padding: 0;
}

.app-footer .row {
    margin: 0;
}

.app-footer .col {
    padding: 0;
}

/* --------------------------------------------------------------------------
 * Touch targets below the lg breakpoint
 *
 * A 16px checkbox, a 14px sort link and a 31px button are all reliable with a
 * mouse and awkward with a thumb, so everything interactive grows to roughly
 * 40px on phones and tablets.
 * -------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
        margin-top: 0;
    }

    .form-check {
        min-height: 1.5rem;
        padding-left: 2rem;
    }

    .form-check .form-check-input {
        margin-left: -2rem;
    }

    .form-check-label {
        line-height: 1.5rem;
    }

    .form-switch {
        padding-left: 3.5rem;
    }

    .form-switch .form-check-input {
        width: 3rem;
        margin-left: -3.5rem;
    }

    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Centering is only the default; the alignment utilities still win */
    .btn.text-start {
        justify-content: flex-start;
    }

    .btn.text-end {
        justify-content: flex-end;
    }

    .btn-sm,
    .btn-group-sm > .btn {
        --bs-btn-padding-y: 0.5rem;
        --bs-btn-padding-x: 0.75rem;
        min-height: 2.5rem;
    }

    /* Sorting is triggered by the whole header cell, not just the label text */
    .table-light-header > thead > tr > th a {
        display: block;
        padding: 0.7rem 0;
    }

    .breadcrumb-item a {
        display: inline-block;
        padding: 0.5rem;
        margin: -0.5rem;
    }

    /* Links in dense areas need vertical room to be tappable. Two exclusions:
       dropdown items are sized by the .dropdown-item rule below, and mailto:/tel:
       get the taller target of the next rule - either would otherwise be outweighed
       by this selector and flattened back to 30px. */
    .table td a:not(.dropdown-item):not([href^="mailto:"]):not([href^="tel:"]),
    .card-body p a:not([href^="mailto:"]):not([href^="tel:"]),
    footer a {
        display: inline-block;
        padding-top: 0.2rem;
        padding-bottom: 0.2rem;
    }

    /* The mailto: and tel: links on detail pages matter most - on a phone they are
       the primary action, so they get a full-height target. */
    a[href^="mailto:"],
    a[href^="tel:"] {
        display: inline-block;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Bulk select needs a pointer and a keyboard to be worth anything. On a phone
       the column only steals width from the record name, and with no checkboxes
       the bulk actions toolbar simply never unhides itself. */
    .table th:has(.bulk-select-all),
    .table td:has(.bulk-select-item) {
        display: none;
    }

    /* A file name or URL with no spaces sets the cell's minimum width and pushes
       the card wider than the phone; let it break mid-token instead. Table cells
       do not need this - they truncate rather than wrap at every width. */
    .card-body p a {
        overflow-wrap: anywhere;
    }

    /* A long paginator overflows a phone; let the links wrap instead */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .dropdown-item {
        padding: 0.625rem 0.75rem;
    }

    /* A row is a tap target on a phone, so it keeps the taller padding */
    .table > :not(caption) > * > * {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    /* Stacked checkboxes and switches sit flush; space them so a thumb cannot
       hit the wrong one */
    .form-check + .form-check {
        margin-top: 0.5rem;
    }

    /* A lone form action becomes a full-width, thumb-friendly button */
    .card-footer > .btn:only-child {
        width: 100%;
    }

    .pagination .page-item .page-link {
        min-width: 2.5rem;
        height: 2.5rem;
    }
}

/* Sales pipeline board: fixed-width columns that scroll sideways inside the page. */
.sales-board {
    overflow-x: auto;
}

.sales-board-column {
    width: 260px;
    min-height: 200px;
    background: var(--cv-surface-muted);
}

.sales-board-column.is-drop-target {
    outline: 2px dashed var(--cv-accent);
}

.sales-board .card[draggable='true'] {
    cursor: grab;
}

/* Month calendar: seven equal columns, each day a fixed-height cell whose events truncate. */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-top: 1px solid var(--cv-hairline);
}

.calendar-weekday {
    padding: 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    border-bottom: 1px solid var(--cv-hairline);
}

.calendar-day {
    min-height: 110px;
    padding: 0.25rem 0.5rem 0.5rem;
    border-right: 1px solid var(--cv-hairline);
    border-bottom: 1px solid var(--cv-hairline);
}

.calendar-day:nth-child(7n) {
    border-right: 0;
}

.calendar-day.is-outside {
    background: var(--cv-surface-muted);
    color: var(--bs-secondary-color);
}

.calendar-day.is-today .calendar-date {
    color: var(--cv-accent);
    font-weight: 700;
}

.calendar-date {
    font-size: 0.8125rem;
    margin-bottom: 0.25rem;
}

.calendar-event {
    display: block;
    font-size: 0.8125rem;
    padding: 0.125rem 0.375rem;
    margin-bottom: 0.125rem;
    border-radius: var(--bs-border-radius-sm);
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
    text-decoration: none;
}

/* Knowledge base articles render Markdown; keep images and code inside the column. */
.kb-article img {
    max-width: 100%;
    height: auto;
}

.kb-article pre {
    padding: 1rem;
    background: var(--cv-surface-muted);
    border-radius: var(--bs-border-radius);
    overflow-x: auto;
}

/* A field the user has touched and left invalid is marked the same way as a server-side error */
.form-control:user-invalid,
.form-select:user-invalid {
    border-color: var(--bs-form-invalid-border-color);
}

.form-control:user-invalid:focus,
.form-select:user-invalid:focus {
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-danger-rgb), 0.25);
}

/* A form on its way to the server shows its buttons as busy */
form.is-submitting [type="submit"] {
    cursor: progress;
    opacity: 0.65;
}

/* Searchable select (appflexer.js): a .form-select button over a dropdown with a search box */
.cv-select-button {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cv-select-button:disabled {
    background-color: var(--bs-secondary-bg);
}

.cv-select-menu {
    min-width: 12rem;
}

.cv-select-list {
    max-height: 16rem;
    overflow-y: auto;
}

.cv-select-list .dropdown-item {
    white-space: normal;
}

/* Bootstrap Icons has no crown; drawn here so <i class="bi bi-crown"> works like any other icon */
.bi-crown::before {
    content: "";
    width: 1em;
    height: 1em;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath d='M1 4.5l3.6 3.2L8 2l3.4 5.7L15 4.5 13.6 12H2.4zM2.4 13.2h11.2v1.3H2.4z'/%3e%3c/svg%3e") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath d='M1 4.5l3.6 3.2L8 2l3.4 5.7L15 4.5 13.6 12H2.4zM2.4 13.2h11.2v1.3H2.4z'/%3e%3c/svg%3e") center / contain no-repeat;
}

/* The AI panel's replies keep their line breaks (lists of changes) and break long keys */
.ai-reply {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.ai-reply-more summary {
    color: var(--cv-accent);
    cursor: pointer;
    padding: 0.25rem 0;
}

/* ---------------------------------------------------------------------------
 * Studio workspace: tabs, preview frame, data model diagram, history
 * ------------------------------------------------------------------------- */

.studio-tabs {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--cv-hairline);
    overflow-x: auto;
}

.studio-tabs .nav-link {
    white-space: nowrap;
    color: var(--cv-text-muted);
}

.studio-tabs .nav-link.active {
    color: var(--cv-text-strong);
}

.studio-sandbox-status {
    margin-left: auto;
    flex-shrink: 0;
}

.studio-main {
    min-width: 0;
}

@media (min-width: 1200px) {
    .studio-side {
        position: sticky;
        top: calc(var(--cv-topbar-height) + 1rem);
        align-self: flex-start;
        max-height: calc(100vh - var(--cv-topbar-height) - 2rem);
        overflow-y: auto;
    }
}

.studio-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    background: var(--cv-surface);
}

.studio-toolbar [aria-pressed="true"] {
    background: var(--cv-surface-active);
    border-color: var(--cv-border-strong) !important;
}

.studio-page-select {
    max-width: 14rem;
}

.studio-frame-wrap {
    background: var(--cv-canvas);
    height: 72vh;
    min-height: 28rem;
    overflow: hidden;
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
}

/* Fit fills the space; a device keeps its own width and is scaled down by appflexer.js when the
   space is narrower, so the application lays itself out as it would on that device. */
.studio-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--cv-surface);
    transform-origin: top left;
}

.studio-frame-wrap:not([data-device="fit"]) .studio-frame {
    box-sizing: content-box;
    border: 1px solid var(--cv-hairline);
    border-radius: 0.75rem;
}

/* The diagram: boxes are surfaces with hairlines, lines are muted, the selection uses the accent */
.studio-diagram {
    overflow: auto;
    max-height: 72vh;
    background: var(--cv-canvas);
}

.dm {
    display: block;
    font-family: inherit;
}

.dm-box {
    fill: var(--cv-surface);
    stroke: var(--cv-border-strong);
}

.dm-header {
    fill: var(--cv-surface-muted);
}

.dm-node-user .dm-header {
    fill: var(--cv-surface-active);
}

.dm-title {
    fill: var(--cv-text-strong);
    font-weight: 600;
    font-size: 14px;
}

.dm-row-bg {
    fill: transparent;
}

.dm-row-key {
    fill: var(--cv-text-faint);
    font-size: 10px;
    font-weight: 600;
}

.dm-row-label {
    fill: var(--bs-body-color);
    font-size: 13px;
}

.dm-row-type {
    fill: var(--cv-text-muted);
    font-size: 11px;
    font-family: var(--bs-font-monospace);
}

.dm-row-calculated .dm-row-label {
    font-style: italic;
}

.dm-edge-line,
.dm-edge-mark,
.dm-edge-ring {
    fill: none;
    stroke: var(--cv-text-faint);
    stroke-width: 1.5;
}

.dm-edge-ring {
    fill: var(--cv-canvas);
}

.dm-edge-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 12;
}

.dm [data-af-id] {
    cursor: pointer;
    outline: none;
}

.dm .dm-row[data-af-id]:hover .dm-row-bg,
.dm .dm-row[data-af-id]:focus-visible .dm-row-bg {
    fill: var(--cv-surface-hover);
}

.dm .dm-node[data-af-id]:focus-visible > .dm-box,
.dm .dm-node.is-selected > .dm-box {
    stroke: var(--cv-accent);
    stroke-width: 2;
}

.dm .dm-row.is-selected .dm-row-bg {
    fill: var(--cv-accent-subtle);
}

.dm .dm-edge:hover .dm-edge-line,
.dm .dm-edge:focus-visible .dm-edge-line,
.dm .dm-edge.is-selected .dm-edge-line,
.dm .dm-edge.is-selected .dm-edge-mark,
.dm .dm-edge.is-selected .dm-edge-ring {
    stroke: var(--cv-accent);
    stroke-width: 2.25;
}

.studio-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
}

.studio-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
}

.studio-facts dt {
    font-weight: 500;
    color: var(--cv-text-muted);
}

.studio-facts dd {
    margin: 0;
    min-width: 0;
}

/* History */
.studio-entry-dot {
    font-size: 0.75rem;
    margin-top: 0.3rem;
    flex-shrink: 0;
}

.studio-timeline .studio-entry > .d-flex > .flex-grow-1 {
    min-width: 0;
}

.studio-checkpoint > summary {
    cursor: pointer;
    list-style: none;
}

.studio-checkpoint > summary::-webkit-details-marker {
    display: none;
}

/* The AI panel's selection chip */
.ai-selection .badge {
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.35rem 0.5rem;
}

.ai-selection-clear {
    border: 0;
    background: none;
    color: inherit;
    padding: 0 0 0 0.25rem;
    line-height: 1;
    font-size: 0.75rem;
    opacity: 0.7;
}

.ai-selection-clear:hover,
.ai-selection-clear:focus-visible {
    opacity: 1;
}

/* Below lg, a 40px target around the small mark, without growing the chip */
@media (max-width: 991.98px) {
    .ai-selection-clear {
        padding: 0.9rem 0.6rem;
        margin: -0.9rem -0.6rem -0.9rem 0;
    }
}
