/* AmpleoCRM Brand Variables & Design Tokens.
   [data-bs-theme="light"] re-applies the light values inside a dark page, for content that must look the same
   in both themes (public pages, print, e-mail and document previews). */
:root, [data-bs-theme="light"] {
    color-scheme: light; /* drives light-dark() in component styles; Bootstrap only sets the dark one */
    --ampleo-primary: #2A4D69;
    --ampleo-secondary: #62829D;
    --ampleo-vivid: #0037CE;
    --ampleo-accent: #9E7D5F;
    --ampleo-neutral: #D9D9D9;
    --ampleo-bg: #F8F9FA;

    /* Spacing tokens */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    /* Layout tokens */
    --density-sidebar-width: 16.5rem;

    /* Font-size tokens */
    --font-sm: 0.875rem;
    --font-md: 1rem;
    --font-lg: 1.125rem;
    --font-xl: 1.5rem;

    /* Radius tokens */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* App shell tokens: white panels floating on a canvas. The canvas and the hairlines are the warm paper
       of the public site (public-theme.css), the ink is Ampleo navy, and the quiet fills are a light navy
       tint, so the brand reads through tone rather than through large coloured areas. */
    --app-canvas: #F4F0E8;
    --app-surface: #FFFFFF;
    --app-surface-muted: #EEF2F6;
    --app-surface-hover: #E3EAF1;
    --app-ink: #2A4D69;
    --app-muted: #6B7A88;
    --app-line: #E8E3DA;
    --app-accent-text: #806A4E; /* the bronze accent darkened to 5:1 on white, for small text */
    --app-shell-gap: 0.625rem;
    --shadow-float: 0 1px 3px rgba(31, 59, 87, 0.06), 0 0 0 1px rgba(31, 59, 87, 0.05);
    --bs-border-color: #E3DDD2;

    /* Form tokens. A section is marked by a crisp light-blue edge alone, with no fill, fields are white with a
       cool edge, and focus is Ampleo navy rather than Bootstrap's blue. Everything on a form is in the blue
       family, so locked fields keep Bootstrap's cool grey; warm edges and warm locked fields looked brown. */
    --field-line: #D3DCE5;
    --field-focus-line: #2A4D69;
    --field-focus-ring: rgba(42, 77, 105, 0.16);
    --form-panel: var(--app-surface);
    --form-panel-line: #BFCEDC;

    /* Activity types in the timeline, drawn from the brand and status palette. */
    --activity-task: #2A4D69;
    --activity-call: #3D8A5E;
    --activity-meeting: #9E7D5F;
    --activity-email: #4F7598;
    --activity-note: #C98A1B;
    --activity-other: #8A96A3;

    /* Font tokens. Plus Jakarta Sans is self-hosted (wwwroot/css/fonts.css) and shared with the public site. */
    --font-app: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* Dark theme, chosen per browser (data-bs-theme on <html>, set by the head script in App.razor). The same
   roles as above on a deep navy base. Brand navy is far too dark to read as text here, so --ampleo-primary
   becomes a light navy, and filled primary buttons switch to dark text to keep their contrast. */
[data-bs-theme="dark"] {
    color-scheme: dark;
    --ampleo-primary: #8DB0D2;
    --ampleo-secondary: #7F9AB2;
    --ampleo-vivid: #7FA2FF;
    --ampleo-accent: #C4A17F;
    --ampleo-neutral: #3A4652;
    --ampleo-bg: #161C23;

    --app-canvas: #11161C;
    --app-surface: #1A2129;
    --app-surface-muted: #212A34;
    --app-surface-hover: #29343F;
    --app-ink: #DCE5EE;
    --app-muted: #93A1AF;
    --app-line: #2B3540;
    --app-accent-text: #CDAE8C;
    --shadow-float: 0 1px 3px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);

    --field-line: #3A4653;
    --form-panel: var(--app-surface);
    --field-focus-line: #8DB0D2;
    --field-focus-ring: rgba(141, 176, 210, 0.22);
    --form-panel-line: #3F5568;

    --activity-task: #8DB0D2;
    --activity-call: #5FB383;
    --activity-meeting: #CDAE8C;
    --activity-email: #86A6C2;
    --activity-note: #E0A63E;
    --activity-other: #9AA6B2;

    --bs-body-bg: var(--app-surface);
    --bs-body-bg-rgb: 26, 33, 41;
    --bs-body-color: var(--app-ink);
    --bs-body-color-rgb: 220, 229, 238;
    --bs-emphasis-color: #F2F6FA;
    --bs-secondary-bg: #26303B;
    --bs-tertiary-bg: #1F2731;
    --bs-tertiary-bg-rgb: 31, 39, 49;
    --bs-secondary-color: rgba(220, 229, 238, 0.7);
    --bs-border-color: #303B47;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.1);
    --bs-link-color: #8DB0D2;
    --bs-link-color-rgb: 141, 176, 210;
    --bs-link-hover-color: #B3CBE3;
    --bs-link-hover-color-rgb: 179, 203, 227;
}

/* Bootstrap's fixed-light utilities do not follow data-bs-theme; in the app they mean "panel" and "quiet fill". */
[data-bs-theme="dark"] .bg-white { background-color: var(--app-surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--app-surface-muted) !important; }
[data-bs-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-black { color: var(--app-ink) !important; }
[data-bs-theme="dark"] .btn-light {
    --bs-btn-bg: var(--app-surface-muted);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-color: var(--app-ink);
    --bs-btn-hover-bg: var(--app-surface-hover);
    --bs-btn-hover-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--app-ink);
    --bs-btn-active-bg: var(--app-surface-hover);
    --bs-btn-active-color: var(--app-ink);
}
[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--app-surface-muted);
    --bs-table-color: var(--app-ink);
    --bs-table-border-color: var(--bs-border-color);
}
/* The logo JPG has a white background, so the dark theme swaps in a transparent PNG recoloured from it. */
.brand-logo-dark,
[data-bs-theme="dark"] .brand-logo-light { display: none; }
[data-bs-theme="dark"] .brand-logo-dark { display: revert; }

/* ApexCharts writes light-theme colours as SVG attributes from each chart's C# options; presentation
   attributes lose to any CSS rule, so the dark theme is applied here once instead of per chart. */
[data-bs-theme="dark"] .apexcharts-xaxis-label,
[data-bs-theme="dark"] .apexcharts-yaxis-label,
[data-bs-theme="dark"] .apexcharts-xaxis-title-text,
[data-bs-theme="dark"] .apexcharts-yaxis-title-text,
[data-bs-theme="dark"] .apexcharts-title-text,
[data-bs-theme="dark"] .apexcharts-datalabel-label,
[data-bs-theme="dark"] .apexcharts-datalabel-value { fill: var(--app-muted); }
[data-bs-theme="dark"] .apexcharts-legend-text { color: var(--app-ink) !important; }
[data-bs-theme="dark"] .apexcharts-gridline,
[data-bs-theme="dark"] .apexcharts-xaxis-tick,
[data-bs-theme="dark"] .apexcharts-xaxis line,
[data-bs-theme="dark"] .apexcharts-yaxis line { stroke: var(--app-line); }
/* A white stroke in a chart or diagram separates shapes from a white card; on dark it must match the card. */
[data-bs-theme="dark"] svg :is([stroke="white"], [stroke="#fff"], [stroke="#FFF"], [stroke="#ffffff"]):not([data-bs-theme="light"] *),
[data-bs-theme="dark"] .apexcharts-pie-area,
[data-bs-theme="dark"] .apexcharts-pie-series path { stroke: var(--app-surface); }
[data-bs-theme="dark"] .apexcharts-tooltip.apexcharts-theme-light {
    background: var(--app-surface-muted);
    border-color: var(--bs-border-color);
    color: var(--app-ink);
}
[data-bs-theme="dark"] .apexcharts-tooltip.apexcharts-theme-light .apexcharts-tooltip-title,
[data-bs-theme="dark"] .apexcharts-xaxistooltip {
    background: var(--app-surface-hover);
    border-color: var(--bs-border-color);
    color: var(--app-ink);
}
[data-bs-theme="dark"] .apexcharts-menu {
    background: var(--app-surface-muted);
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .btn-primary {
    --bs-btn-color: #0F1720;
    --bs-btn-hover-color: #0F1720;
    --bs-btn-active-color: #0F1720;
    color: #0F1720;
}

/* ── Settings hub cards ─────────────────────────────────────────────── */
.hub-card {
    transition: box-shadow 0.15s ease, transform 0.15s ease;
    border: 1px solid rgba(0,0,0,0.07) !important;
}

.hub-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.10) !important;
    transform: translateY(-2px);
}

.hub-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--ampleo-primary) 10%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--ampleo-primary);
}

/* Proportional root scaling - adjusts smoothly with viewport width and user preference */
html {
    font-size: calc(clamp(13px, 0.5vw + 5px, 15px) * var(--user-zoom, 1));
}

/* Hide the browser's empty date/datetime format hint (e.g. "dd/mm/yyyy") when the
   field has no value and is not focused. The component adds .dt-empty when _inputValue
   is null so this selector is precise: hides hint only for empty+unfocused fields. */
.dt-empty:not(:focus)::-webkit-datetime-edit {
    color: transparent;
}

/* DateTimePicker - time popup spinner */
.dt-time-popup .btn {
    line-height: 1;
    font-size: 0.85rem;
}

/* DateTimePicker calendar. The component draws its own popup, so the browser's is suppressed by hiding
   the only control that opens it: Chrome's popup cannot be styled or scripted, and it navigates one month
   per step, which puts a birth year hundreds of clicks away. The field itself is untouched - typing a date
   straight into it still works. */
.dt-date::-webkit-calendar-picker-indicator {
    display: none;
}

/* Above Bootstrap's modal (1055): the picker is used inside modals and grid cells. */
.dt-cal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1080;
}

.dt-cal-popup {
    position: fixed;
    z-index: 1081;
    width: 290px;
    background: light-dark(#fff, var(--app-surface));
}

.dt-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.dt-cal-grid.dt-cal-weeks {
    grid-template-columns: 1.8rem repeat(7, 1fr);
}

.dt-cal-weekday {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: light-dark(#888, var(--app-muted));
}

/* Week numbers must not read as dates: a tinted band in the brand colour, smaller type, and inert. Grey
   alone is not enough, since it is what the neighbouring months' days use. The negative margin closes the
   grid gap so the band runs unbroken from top to bottom. */
.dt-cal-weeknum {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: -1px 0.15rem -1px 0;
    background: color-mix(in srgb, var(--ampleo-primary) 8%, transparent);
    font-size: 0.7rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--ampleo-primary);
    cursor: default;
    user-select: none;
}

.dt-cal-weeknum:first-child {
    border-radius: 0.25rem 0.25rem 0 0;
}

/* The last row's week number, followed only by its seven days. */
.dt-cal-weeknum:nth-last-child(8) {
    border-radius: 0 0 0.25rem 0.25rem;
}

.dt-cal-day {
    border: 0;
    background: transparent;
    border-radius: 0.25rem;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    line-height: 1.2;
}

.dt-cal-day:hover {
    background: var(--ampleo-bg);
}

.dt-cal-other {
    color: #bbb;
}

.dt-cal-today {
    outline: 1px solid var(--ampleo-primary);
}

.dt-cal-selected, .dt-cal-selected:hover {
    background: var(--ampleo-primary);
    color: #fff;
}

.dt-cal-year {
    max-width: 5.5rem;
}

/* General */
html, body {
    font-family: var(--font-app);
    background-color: var(--ampleo-bg);
    color: light-dark(#444, var(--app-ink));
    line-height: 1.6;
}

h1, .h1, h2, .h2, h3, .h3 {
    font-family: var(--font-app);
    color: var(--ampleo-primary);
    font-weight: 700;
    letter-spacing: -0.5px;
}

h1:focus {
    outline: none;
}

/* Form validation */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: light-dark(#e50000, color-mix(in srgb, #e50000 45%, white));
}

/* Error boundary */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA9NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDg2IDY2LjAxODMaIDI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

/* Form styling */
.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, 
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, 
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* Table enhancements */
.table {
    border-collapse: separate;
    border-spacing: 0;
}

.table > thead {
    background-color: light-dark(#fcfcfc, var(--bs-tertiary-bg));
    color: var(--ampleo-primary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05rem;
}

.table > thead th {
    border-bottom: 2px solid var(--ampleo-neutral) !important;
    padding: var(--space-sm) var(--space-md);
}

/* Hover only tints the row; a row that lifts (transform plus shadow) jitters under the pointer. There is
   no generic card hover shadow either, so only cards made to be clicked, like the hub cards, lift. */
.table > tbody > tr {
    transition: background-color 0.15s ease;
}

.table > tbody > tr:hover {
    background-color: rgba(42, 77, 105, 0.03) !important;
}

/* The open-record link after a lookup value appears on the row being pointed at. Screens that cannot
   point (touch) keep it visible. */
@media (hover: hover) {
    tr .lookup-open {
        opacity: 0;
        transition: opacity 0.12s ease;
    }

    tr:hover .lookup-open,
    .lookup-open:focus-visible {
        opacity: 1;
    }
}

.table td {
    padding: var(--space-sm) var(--space-md);
    vertical-align: middle;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

/* Breadcrumb and Link enhancements */
a, .btn-link {
    color: var(--ampleo-secondary);
    text-decoration: none;
    transition: all 0.2s;
}

a:hover {
    color: var(--ampleo-primary);
    text-decoration: none;
}

.breadcrumb-item a {
    color: var(--ampleo-secondary);
}

.breadcrumb-item.active {
    color: var(--ampleo-accent);
}

/* Tab enhancements */
.nav-tabs {
    border-bottom: 1px solid var(--ampleo-neutral);
    gap: 1.5rem;
}

.nav-tabs .nav-link {
    color: var(--ampleo-secondary);
    border: none !important;
    border-bottom: 3px solid transparent !important;
    padding: var(--space-sm) var(--space-xs);
    font-weight: 600;
    font-size: var(--font-sm);
    background: transparent !important;
    transition: all 0.2s;
}

.nav-tabs .nav-link:hover {
    color: var(--ampleo-primary);
    border-bottom-color: var(--ampleo-neutral) !important;
}

.nav-tabs .nav-link.active {
    color: var(--ampleo-primary) !important;
    border-bottom-color: var(--ampleo-accent) !important;
}

/* The tabs of a form in a narrow frame, as one dropdown. Drawn as the active tab on the tab line rather than
   as a field box, so it reads as navigation and not as something to fill in. */
.compact-tab-picker {
    border-bottom: 1px solid var(--app-line);
    margin-bottom: var(--space-md);
}

    .compact-tab-picker .form-select {
        width: auto;
        max-width: 100%;
        margin-bottom: -1px;
        padding-left: var(--space-xs);
        border: none;
        border-bottom: 3px solid var(--ampleo-accent);
        border-radius: 0;
        background-color: transparent;
        box-shadow: none;
        color: var(--ampleo-primary);
        font-weight: 600;
        font-size: var(--font-sm);
        cursor: pointer;
    }

/* Links and Back buttons */
.text-decoration-none.text-primary, .text-decoration-none:not([class*="text-"]) {
    color: var(--ampleo-secondary) !important;
}

.text-decoration-none:hover {
    color: var(--ampleo-primary) !important;
}

/* Follow-up banner (shown above the form card when followUpDate is set) */
.followup-banner {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.875rem;
    background: light-dark(#fff8e1, color-mix(in srgb, #fff8e1 14%, var(--app-surface)));
    color: light-dark(#8a6d0b, color-mix(in srgb, #8a6d0b 45%, white));
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.8125rem;
    width: 100%;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.followup-banner:hover {
    filter: brightness(0.97);
}

/* A follow-up date or note on a form: read-only, changed through the follow-up dialog it opens. */
.followup-field {
    cursor: pointer;
    border-radius: var(--radius-md);
}

.followup-field:hover {
    outline: 1px solid var(--bs-primary);
    outline-offset: 2px;
}

.followup-banner.is-overdue {
    background: light-dark(#fdecea, color-mix(in srgb, #fdecea 14%, var(--app-surface)));
    color: light-dark(#b42318, color-mix(in srgb, #b42318 45%, white));
}

.followup-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* Related grids (Subgrids) */
.related-grid {
    border: 1px solid var(--ampleo-neutral) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04) !important;
    margin-top: var(--space-md);
    overflow: hidden !important; /* clip rows at rounded corners so they don't spill out */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Editable grids need visible overflow so lookup dropdowns are not clipped */
.related-grid:has(.editable-grid) {
    overflow: visible !important;
}

.related-grid .card-header {
    background-color: light-dark(#fff, var(--app-surface));
    border-bottom: 1px solid var(--ampleo-neutral);
    font-weight: 600;
    color: var(--ampleo-primary);
}

/* Rich grid list (avatar-style rows used when RichGrid is configured) */
.related-grid .rich-grid-list {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.related-grid .rich-grid-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: background-color 0.12s ease;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.related-grid .rich-grid-row:last-child {
    border-bottom: none;
}

.related-grid .rich-grid-row:hover {
    background-color: rgba(42, 77, 105, 0.04);
}

.related-grid .rich-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
}

.related-grid .rich-avatar.rich-avatar-badge {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.related-grid .rich-grid-body {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.related-grid .rich-grid-primary {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ampleo-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.related-grid .rich-grid-secondary {
    font-size: 0.75rem;
    color: var(--ampleo-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.related-grid .rich-grid-phone {
    font-size: 0.8125rem;
    color: var(--ampleo-vivid, #0037CE);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.related-grid .rich-grid-phone:hover {
    text-decoration: underline;
}

.related-grid .rich-grid-amount {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ampleo-primary, #2a4d69);
    white-space: nowrap;
    flex-shrink: 0;
}

.related-grid .rich-grid-options {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
}

.related-grid .rich-grid-options .option-badge {
    font-size: 0.75rem;
}

.related-grid .table thead {
    /* Uses .table-light override from below */
}

.related-grid .table td,
.related-grid .table th {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
}

/* Ensure lookup dropdowns inside editable grid cells render above sibling rows.
   Tables paint rows in DOM order, so position:absolute dropdowns in row N get
   covered by row N+1. Elevating the focused cell to a new stacking context fixes this.
   Note: the global tr:hover rule uses transform which always creates a new stacking
   context; we suppress that here since editable-grid rows are edited in place, not
   navigated, so the hover-lift animation has no UX value and breaks dropdown layering. */
.editable-grid tr {
    transition: background-color 0.2s;
}

.editable-grid tr:hover {
    transform: none !important;
    box-shadow: none !important;
}

.editable-grid td:focus-within {
    position: relative;
    z-index: 10;
}

/* The same problem one level up, for every table with inline editing - the entity list included,
   which carries no .editable-grid class because its rows ARE navigated and keep the hover lift.

   The trap is the hover rule above, on the row holding the dropdown rather than on any other row.
   Its transform makes that row a stacking context, which confines the dropdown's own z-index:1050
   to the inside of the row; the row itself then has z-index auto and loses to row N+1 on DOM order
   alone. And the pointer is over that row by definition - it is the row just clicked into - so the
   dropdown is covered from the moment it opens. Raising the cell (above) does not reach this: it
   only orders cells within the row that is already losing.

   Lifting the whole row is what fixes it - a stacking context at a z-index no unfocused row can
   reach, carrying everything inside it, dropdown included. Verified by reproducing both states in
   the browser against this stylesheet: with the row transformed and the rule suppressed, the point
   over a dropdown option hit-tests to the NEXT row's input; with the rule applied, it hits the
   option. */
.table > tbody > tr:has(td:focus-within) {
    position: relative;
    z-index: 20;
    /* The hover lift must not apply to this row, and not only to stop it jiggling under an open
       dropdown: js/anchored-dropdown.js pins the panel with position:fixed, and a transformed
       ancestor becomes the containing block for fixed descendants. Left in place, the transform
       would place the panel relative to this row instead of the viewport - measured as landing
       several hundred pixels off-screen. */
    transform: none !important;
}

/* A modal is rendered where it is opened, so any element with its own z-index above it - the sticky page
   header (z 20), a focused grid row (z 20) and its cell (z 10) - becomes a stacking context that holds the
   modal at that element's level, under the sidebar and the help button. While a modal is open inside one of
   them, the element itself is lifted to the modal layer. The side panel has the same rule in its own
   stylesheet. Each anchor is a named element, never a bare *:has(), so the browser only re-checks these.
   A new element with a z-index that can host a modal belongs in this list. */
.page-header:has(.modal.show),
.table > tbody > tr:has(.modal.show),
.editable-grid td:has(.modal.show) {
    z-index: 1055;
}

/* Tab contents */
.tab-content {
    background-color: light-dark(#fff, var(--app-surface));
    padding: 1.5rem 0;
}

/* Loading spinner */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* Table enhancements refinements */
.table thead.table-light {
    background-color: rgba(42, 77, 105, 0.05) !important;
    color: var(--ampleo-primary);
}

.table th {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05rem;
    font-weight: 700;
}

.table-sm td {
    font-size: var(--font-sm);
    padding: var(--space-xs) var(--space-sm);
}

/* Button transitions */
.btn {
    transition: all 0.2s;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.btn-primary {
    background-color: var(--ampleo-primary);
    border-color: var(--ampleo-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.btn-secondary {
    background-color: var(--ampleo-secondary);
    border-color: var(--ampleo-secondary);
}

.btn-outline-primary {
    color: var(--ampleo-primary);
    border-color: var(--ampleo-primary);
    /* Pressed or with its menu open, Bootstrap would fill it with its own blue. */
    --bs-btn-active-bg: var(--ampleo-primary);
    --bs-btn-active-border-color: var(--ampleo-primary);
    --bs-btn-active-color: #fff;
    --bs-btn-focus-shadow-rgb: 42, 77, 105;
}

.btn-outline-primary:hover {
    background-color: var(--ampleo-primary);
    color: #fff;
}

.text-primary {
    color: var(--ampleo-primary) !important;
}

/* Re-tints Bootstrap .bg-primary to the brand colour while keeping .bg-opacity-* working.
   A plain background-color drops --bs-bg-opacity, so .bg-primary.bg-opacity-10 rendered as solid
   navy - and every icon tile built from that pair (dashboards, My Day) showed a dark block with an
   invisible brand-coloured icon on it. The other Bootstrap colours were never overridden and so
   never had the problem, which is why only the primary tiles looked wrong. */
.bg-primary {
    background-color: color-mix(in srgb, var(--ampleo-primary) calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important;
}

.spinner-border.text-primary {
    color: var(--ampleo-accent) !important;
}

/* App shell: the sidebar and the content float as panels on the canvas */
.app-shell {
    background-color: var(--app-canvas);
}

/* Sidebar enhancements */
.sidebar {
    background-color: var(--app-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
    margin: var(--app-shell-gap) 0 var(--app-shell-gap) var(--app-shell-gap);
    z-index: 100;
    flex-shrink: 0;
    flex-grow: 0;
    width: var(--density-sidebar-width);
    min-width: var(--density-sidebar-width);
    max-width: var(--density-sidebar-width);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    height: 4rem;
    padding: 0 1.25rem;
    flex-shrink: 0;
    text-decoration: none;
}

.sidebar-brand img {
    height: 1.4rem;
}

.sidebar-brand span {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.4px;
    color: var(--ampleo-primary);
}

.sidebar-divider {
    border-top: 1px solid var(--app-line);
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
}

.sidebar-section {
    padding: 0 0.75rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-muted);
}

.sidebar .nav-link {
    position: relative;
    color: light-dark(#3D5266, color-mix(in srgb, #3D5266 45%, white));
    border-radius: var(--radius-md);
    margin: 1px 0;
    padding: 0.45rem 0.75rem;
    font-weight: 500;
    font-size: var(--font-sm);
    transition: background-color 0.15s, color 0.15s;
}

.sidebar .nav-link i {
    color: var(--ampleo-secondary);
    flex-shrink: 0;
}

/* Keep labels on one line so the rail width stays constant across areas
   regardless of the longest label in the current area. */
.sidebar .nav-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.sidebar .nav-link:hover {
    background-color: var(--app-surface-muted);
    color: var(--app-ink);
}

.sidebar .nav-link.active {
    background-color: light-dark(#E6EDF4, var(--bs-tertiary-bg));
    color: var(--ampleo-primary);
    font-weight: 600;
}

.sidebar .nav-link.active i {
    color: var(--ampleo-accent);
}

/* Bronze marker on the panel's inner edge; the nav list's px-2 padding is the 0.5rem it sits in. */
.sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: -0.5rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background-color: var(--ampleo-accent);
}

.sidebar-footer {
    padding: 0.625rem;
    border-top: 1px solid var(--app-line);
}

.sidebar-area-toggle {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--app-surface-muted);
    color: var(--app-ink);
    text-align: start;
}

.sidebar-area-toggle:hover,
.sidebar-area-toggle[aria-expanded="true"] {
    background-color: var(--app-surface-hover);
}

.sidebar-area-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: var(--radius-md);
    background-color: var(--ampleo-primary);
    color: #fff;
    flex-shrink: 0;
}

.sidebar-area-label {
    display: block;
    font-size: 0.7rem;
    line-height: 1.2;
    color: var(--app-muted);
}

.sidebar-area-name {
    display: block;
    font-size: var(--font-sm);
    font-weight: 600;
    line-height: 1.3;
}

.sidebar-collapse-toggle {
    border: 0;
    background: none;
    text-align: start;
}

/* The menu folded to its icons, for working in split screen. The class sits on <html> (set in App.razor's
   head from localStorage), so the narrow menu is there from the first paint. Labels come back as tooltips.
   Desktop only; on a phone the menu is a full-width drawer (see "Phone layout" below). */
@media (min-width: 768px) {
    html.sidebar-collapsed .sidebar {
        width: 4.25rem !important;
        min-width: 4.25rem;
        max-width: 4.25rem;
    }

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

    html.sidebar-collapsed .sidebar-brand span,
    html.sidebar-collapsed .sidebar .nav-link span:not(.badge),
    html.sidebar-collapsed .sidebar-area-toggle > .flex-grow-1,
    html.sidebar-collapsed .sidebar-area-toggle > .bi-chevron-expand {
        display: none;
    }

    html.sidebar-collapsed .sidebar .nav-link,
    html.sidebar-collapsed .sidebar-area-toggle {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    /* An unread count becomes a small marker on the icon instead of pushing the label aside. */
    html.sidebar-collapsed .sidebar .nav-link .badge {
        position: absolute;
        top: 0.1rem;
        right: 0.2rem;
        font-size: 0.55rem;
        padding: 0.15em 0.35em;
    }

    html.sidebar-collapsed .sidebar-collapse-toggle i {
        transform: rotate(180deg);
    }

    /* The area picker opens wider than the folded menu, or the area names would be cut off. */
    html.sidebar-collapsed .sidebar .dropdown-menu {
        width: 15rem !important;
    }
}

/* Main Content Harmony */
.main-content {
    background-color: var(--app-canvas);
    padding: var(--app-shell-gap) 0.75rem var(--space-md); /* 0.75rem sides absorb the negative margin of Bootstrap .row gutters */
}

.card {
    --bs-card-border-radius: var(--radius-lg);
    border: 1px solid var(--app-line) !important;
    box-shadow: 0 1px 3px rgba(31, 59, 87, 0.05) !important;
    background-color: light-dark(white, var(--app-surface));
}

/* The floating help button (.help-fab, 3rem at 1.5rem from the corner) sits over the bottom-right of the page,
   where a list's footer ends up. Its paging buttons keep clear of it; a footer elsewhere on the page only gets
   a little narrower. */
.entity-list-card > .card-footer,
.card-footer:has(.pagination) {
    padding-right: 5rem;
}

/* The list takes exactly the rest of the page and scrolls inside itself. A short list then ends where a
   long one does instead of leaving a smaller box above empty canvas, and on a long one the column
   headers and the horizontal scrollbar stay in view. Infinite scroll follows along: its sentinel sits in
   the same scroll container and the observer picks the nearest scrolling ancestor as its root. The
   overflow clips the header and footer to the rounded corners; the column menus open inside the table's
   scroll container and were clipped by it already. */
.entity-list-card {
    flex: 1 1 0;
    overflow: hidden;
}

.entity-list-card > .card-body,
.entity-list-card .table-responsive {
    min-height: 0;
}

.entity-list-card .table-responsive {
    overflow: auto;
}

/* On the thead, not the th: the header cells carry Bootstrap's position-relative (!important) for their
   column menu. */
.entity-list-table > thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

/* The z-index above holds a column's menu at the header's level, under the click-outside layer the list
   puts behind it (1040), so every click on the menu landed on that layer and only closed the menu. While
   a menu is open the header is lifted above the layer. */
.entity-list-table > thead:has(.dropdown-menu.show) {
    z-index: 1045;
}

/* The view switch (list, board, split, map ...) as a segmented control, in the header's quiet style. */
.view-toggle {
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-lg);
    background-color: var(--app-surface-muted);
}

.view-toggle > .btn {
    --bs-btn-padding-y: 0.2rem;
    --bs-btn-padding-x: 0.6rem;
    --bs-btn-color: var(--ampleo-secondary);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--ampleo-primary);
    --bs-btn-hover-bg: var(--app-surface-hover);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-disabled-color: var(--ampleo-primary);
    --bs-btn-disabled-bg: var(--app-surface);
    --bs-btn-disabled-border-color: transparent;
    --bs-btn-disabled-opacity: 1;
    margin-left: 0 !important;
    border-radius: var(--radius-md) !important; /* beats .btn-group's squared inner corners */
}

/* The active view renders as a disabled button; it reads as the selected segment, not as unavailable. */
.view-toggle > .btn:disabled {
    box-shadow: 0 1px 2px rgba(31, 59, 87, 0.14);
}

/* Page header: back link, record title and the page's actions on one floating bar that stays in view.
   The ::before strip paints the canvas gap above the stuck bar, so content scrolling underneath does not
   show through between the bar and the top edge. */
.page-header {
    position: sticky;
    top: 0; /* measured from the main area's padding edge, which already holds the gap */
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 0.875rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background-color: var(--app-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
}


/* Bootstrap's .sticky-top sits at z 1020, far above the page header (z 20), so a sticky table header in
   the page painted over the page header once the page scrolled. Kept just under it. */
.main-content .sticky-top {
    z-index: 15;
}

.page-header::before {
    content: "";
    position: absolute;
    left: -1px;
    right: -1px;
    bottom: 100%;
    height: var(--app-shell-gap);
    background-color: var(--app-canvas);
}

.page-header-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background-color: var(--app-surface-muted);
    color: var(--ampleo-secondary);
    flex-shrink: 0;
}

.page-header-back:hover {
    background-color: var(--app-surface-hover);
    color: var(--ampleo-primary);
}

/* The title and the actions share one row whatever the title's length. The title takes the room the
   actions leave and is cut with an ellipsis; only below its minimum do the actions wrap, inside their
   own group, so a long record name never pushes the buttons onto a row of their own. */
.page-header > h1,
.page-header-title {
    flex: 1 1 0;
    min-width: 10rem;
}

/* A record page's command bar is wide enough to squeeze the record name down to that minimum while its
   buttons wrap anyway, so the name keeps a quarter of the header (at most 22rem) and the buttons wrap a
   little sooner. Narrow screens fall back to the 10rem above. */
.page-header:has(> .command-bar) > .page-header-title {
    min-width: clamp(10rem, 25%, 22rem);
}

/* A record's status colour as an edge on the header, so its state reads before its title. */
.page-header.has-record-tone {
    box-shadow: var(--shadow-float), inset 4px 0 0 var(--record-tone);
}

.page-header-icon {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: var(--radius-lg);
    flex-shrink: 0;
    font-size: 1.2rem;
    background-color: color-mix(in srgb, var(--ampleo-primary) 10%, transparent);
    color: var(--ampleo-primary);
}

.page-header-overline {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--app-accent-text);
    line-height: 1.3;
}

.page-header-subtitle {
    margin: 0.125rem 0 0;
    font-size: 0.82rem;
    color: var(--app-muted);
    line-height: 1.4;
}

.page-header h1 {
    margin: 0;
    font-size: 1.45rem;
    line-height: 1.25;
    color: var(--app-ink);
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-header-actions {
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Pages that keep their own action markup (a d-flex group) get the same behaviour as .page-header-actions. */
.page-header > .d-flex:not(.page-header-title) {
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* A fixed width rather than Bootstrap's 100%: a percentage width does not count towards the group's
   natural width, so the group would measure itself too narrow and wrap with room to spare. */
.page-header-actions > .input-group,
.page-header > .d-flex > .input-group {
    width: 18rem;
}

/* User Section Sidebar Refinement */
.hover-bg-light-opacity:hover {
    background-color: rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.card-header {
    background-color: light-dark(#fafbfc, var(--bs-tertiary-bg));
    border-bottom: 2px solid var(--ampleo-neutral);
    font-weight: 700;
    color: var(--ampleo-primary);
    padding: var(--space-sm) 1.25rem;
    text-transform: none;
}

/* Sidebar scrollbar */
.sidebar-scroll {
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(16, 24, 40, 0.15) transparent;
    /* Fade top/bottom edges so content softly disappears into the sidebar */
    mask-image: linear-gradient(to bottom, transparent 0%, black 2rem, black calc(100% - 2rem), transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 2rem, black calc(100% - 2rem), transparent 100%);
}

/* Webkit (Chrome, Edge, Safari) */
.sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(16, 24, 40, 0.15);
    border-radius: 4px;
    transition: background-color 0.2s;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgba(16, 24, 40, 0.3);
}

/* Blazor error UI.
   Defined only here. It was previously styled both here and in MainLayout.razor.css, and the scoped
   rule won on specificity: it set a pale background but no color, so this block's white text stayed and
   the message rendered invisible. Keep the banner's styling in one file so the two cannot drift apart. */
#blazor-error-ui {
    background: #dc3545;
    color: white;
    bottom: 0;
    left: 0;
    position: fixed;
    width: 100%;
    box-sizing: border-box;
    /* Above everything, modals and the side panel included: it says the connection is gone. */
    z-index: 1100;
    padding: 1rem;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 1rem;
}

/* ─── Tiptap Editor ─── */

.tiptap-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.125rem;
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid light-dark(#dee2e6, var(--bs-border-color));
    background: light-dark(#fafbfc, var(--bs-tertiary-bg));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tiptap-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.875rem;
    height: 1.875rem;
    padding: 0 0.375rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: light-dark(#444, var(--app-ink));
    font-size: 0.8125rem;
    cursor: pointer;
    line-height: 1;
}

.tiptap-btn:hover {
    background: light-dark(#e9ecef, var(--bs-tertiary-bg));
    border-color: light-dark(#dee2e6, var(--bs-border-color));
}

.tiptap-btn.active {
    background: var(--ampleo-primary);
    color: #fff;
    border-color: var(--ampleo-primary);
}

.tiptap-separator {
    display: inline-block;
    width: 1px;
    height: 1.25rem;
    background: light-dark(#dee2e6, var(--bs-tertiary-bg));
    margin: 0 var(--space-xs);
    vertical-align: middle;
}

.tiptap-editor-content {
    min-height: 500px;
    max-height: 700px;
    overflow-y: auto;
}

.tiptap-prosemirror {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 11pt;
    line-height: 1.6;
    padding: var(--space-md) 1.25rem;
    outline: none;
    min-height: 500px;
}

.tiptap-prosemirror:focus {
    outline: none;
}

/* Page header and footer repeat on every PDF page; framed here so they read as such while editing. */
.tiptap-prosemirror header,
.tiptap-prosemirror footer {
    border: 1px dashed var(--bs-border-color, #d9d9d9);
    padding: 4px 8px;
    margin: 4px 0 12px;
}

/* Placeholder */
.tiptap-prosemirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    color: #adb5bd;
    pointer-events: none;
    float: left;
    height: 0;
}

/* Merge fields */
.tiptap-prosemirror .merge-field,
.email-subject-prosemirror .merge-field,
.merge-field {
    display: inline;
    background: light-dark(#e8f0fe, color-mix(in srgb, #e8f0fe 14%, var(--app-surface)));
    border: 1px solid #4285f4;
    border-radius: 4px;
    padding: 1px 6px;
    color: light-dark(#1a73e8, color-mix(in srgb, #1a73e8 45%, white));
    font-size: 0.9em;
    font-weight: 500;
    white-space: nowrap;
}

/* Email subject field – contenteditable with merge-field pills */
.email-subject-field {
    white-space: nowrap;
    overflow: hidden;
    min-height: auto;
}
.email-subject-field:empty::before {
    content: attr(data-placeholder);
    color: #adb5bd;
    pointer-events: none;
}
.email-subject-field .merge-field {
    cursor: default;
}

/* Merge table markers */
.tiptap-prosemirror .merge-table-marker,
.merge-table-marker {
    display: block;
    background: light-dark(#fef7e0, color-mix(in srgb, #fef7e0 14%, var(--app-surface)));
    border: 1px dashed #f9ab00;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8em;
    color: #e37400;
    margin-bottom: 4px;
}

/* Merge tables */
.tiptap-prosemirror table.merge-table,
table.merge-table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
}

.tiptap-prosemirror table.merge-table td,
.tiptap-prosemirror table.merge-table th,
table.merge-table td,
table.merge-table th {
    border: 1px solid light-dark(#d0d0d0, var(--bs-border-color));
    padding: 6px 10px;
}

.tiptap-prosemirror table.merge-table thead th,
table.merge-table thead th {
    background: light-dark(#f1f3f4, var(--bs-tertiary-bg));
    font-weight: 600;
}

/* Tiptap native table styles */
.tiptap-prosemirror table {
    border-collapse: collapse;
    margin: 0;
    overflow: hidden;
    table-layout: fixed;
    width: 100%;
}

.tiptap-prosemirror td,
.tiptap-prosemirror th {
    border: 1px solid light-dark(#d0d0d0, var(--bs-border-color));
    box-sizing: border-box;
    min-width: 1em;
    padding: 6px 10px;
    position: relative;
    vertical-align: top;
}

.tiptap-prosemirror th {
    background-color: light-dark(#f1f3f4, var(--bs-tertiary-bg));
    font-weight: 600;
}

.tiptap-prosemirror .selectedCell:after {
    background: rgba(66, 133, 244, 0.15);
    content: "";
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    pointer-events: none;
    position: absolute;
    z-index: 2;
}

/* Table column resize handle */
.tiptap-prosemirror .column-resize-handle {
    background-color: #4285f4;
    bottom: -2px;
    pointer-events: none;
    position: absolute;
    right: -2px;
    top: 0;
    width: 4px;
}

.tiptap-prosemirror.resize-cursor {
    cursor: col-resize;
}

.tableWrapper {
    overflow-x: auto;
}

/* Images */
.tiptap-prosemirror img.template-image {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 8px 0;
}

.tiptap-prosemirror img.ProseMirror-selectednode {
    outline: 2px solid var(--ampleo-vivid);
    border-radius: 4px;
}

/* Horizontal rule */
.tiptap-prosemirror hr {
    border: none;
    border-top: 2px solid light-dark(#dee2e6, var(--bs-border-color));
    margin: 16px 0;
}

/* ─── Document editor: toolbar, sheet and popovers (document-template-editor.js) ─── */

.doc-editor-shell {
    position: relative;
}

.doc-toolbar {
    display: block;
    position: sticky;
    top: var(--doc-sticky-top, 0px);
    z-index: 6;
    padding: 0.25rem 0.5rem;
}

.doc-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.125rem;
    padding: 0.125rem 0;
}

.doc-toolbar-table {
    border-top: 1px solid light-dark(#e5e7eb, var(--bs-border-color));
    margin-top: 0.125rem;
}

/* Outside a table its tools stay in place, greyed out, rather than appearing and moving the text. */
.doc-toolbar-table.idle {
    opacity: 0.45;
    pointer-events: none;
}

.tiptap-btn i {
    font-size: 1rem;
}

.tiptap-btn-text {
    gap: 0.3rem;
    font-size: 0.78rem;
}

.tiptap-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.doc-toolbar-select {
    width: auto;
    min-width: 4.5rem;
    height: 1.875rem;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 0.8125rem;
}

/* The current text colour as a bar under the letter, like a word processor. */
.doc-color-btn i {
    border-bottom: 3px solid var(--doc-swatch, currentColor);
    line-height: 1;
}

/* The sheet: the paper at its real size with the PDF's margins, font and spacing (DocumentExportService). */
.doc-page-mode .doc-canvas {
    background: light-dark(#e9ecef, #2b2f33);
    padding: 1.5rem 1rem 3rem;
    overflow-x: auto;
}

.doc-sheet[data-bs-theme="light"] {
    color-scheme: light;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 20mm 25mm;
    background: #fff;
    color: #000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.08);
}

.doc-sheet[data-bs-theme="light"] .tiptap-prosemirror {
    font-family: 'Liberation Sans', Arial, Helvetica, sans-serif;
    font-size: 10pt;
    line-height: 1.15;
    padding: 0;
    min-height: 120mm;
    color: #000;
}

.doc-sheet .tiptap-prosemirror p { margin: 0 0 6pt; }
/* The app's own headings are blue in its font; the PDF's are black in the document font. */
.doc-sheet .tiptap-prosemirror :is(h1, h2, h3, h4) { font-family: inherit; color: inherit; letter-spacing: normal; line-height: 1.15; }
.doc-sheet .tiptap-prosemirror h1 { font-size: 22pt; font-weight: bold; margin: 12pt 0 6pt; }
.doc-sheet .tiptap-prosemirror h2 { font-size: 18pt; font-weight: bold; margin: 10pt 0 4pt; }
.doc-sheet .tiptap-prosemirror h3 { font-size: 14pt; font-weight: bold; margin: 8pt 0 4pt; }
.doc-sheet .tiptap-prosemirror h4 { font-size: 12pt; font-weight: bold; margin: 6pt 0 2pt; }
.doc-sheet .tiptap-prosemirror ul,
.doc-sheet .tiptap-prosemirror ol { margin: 0 0 6pt; padding-left: 1.5em; }
.doc-sheet .tiptap-prosemirror td p,
.doc-sheet .tiptap-prosemirror th p { margin: 0; }

.doc-sheet .tiptap-prosemirror td,
.doc-sheet .tiptap-prosemirror th {
    border-color: #808080;
    padding: var(--doc-cell-padding, 2pt 4pt);
}

.doc-sheet .tiptap-prosemirror .tableWrapper {
    margin: 0 0 6pt;
    overflow-x: visible;
}

/* A table drawn without borders: dashed guides while editing only, and no grey header fill (as in the PDF,
   which still sets header cells in bold). */
.tiptap-prosemirror table.doc-table-borderless td,
.tiptap-prosemirror table.doc-table-borderless th {
    border: 1px dashed #cfd6de;
}

.tiptap-prosemirror table.doc-table-borderless th {
    background-color: transparent;
}

/* Page header and footer repeat on every PDF page. */
.tiptap-prosemirror .doc-page-section {
    position: relative;
    display: block;
    border: 1px dashed #b6c2cf;
    border-radius: 3px;
    padding: 14px 6px 4px;
    margin: 0 0 12pt;
}

.tiptap-prosemirror footer.doc-page-section {
    margin: 12pt 0 0;
}

/* The table of contents is filled by each output; the sheet only says where it goes. */
.tiptap-prosemirror .doc-toc-hint {
    padding: 4px 2px;
    font-family: var(--bs-body-font-family);
    font-size: 9pt;
    color: #6b7f94;
}

.doc-page-section-label {
    position: absolute;
    top: 0;
    left: 6px;
    font-family: var(--bs-body-font-family);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7f94;
    user-select: none;
}

[data-bs-theme="light"] .doc-page-field {
    display: inline-block;
    padding: 0 4px;
    border-radius: 3px;
    background: #eef2f6;
    color: #4b5d70;
    font-size: 0.9em;
}

/* "Start on a new page": a dashed line above the block where the PDF turns the page. */
.doc-sheet .tiptap-prosemirror [style*="break-before"] {
    position: relative;
    margin-top: 18pt;
}

.doc-sheet .tiptap-prosemirror [style*="break-before"]::before {
    content: var(--doc-new-page-label);
    position: absolute;
    left: 0;
    right: 0;
    top: -13pt;
    border-top: 1px dashed #9aa9b8;
    font-family: var(--bs-body-font-family);
    font-size: 9px;
    font-weight: normal;
    color: #6b7f94;
    text-align: center;
    line-height: 1.6;
}

/* Line table: the marker as a locked band, and the table it repeats framed with it. */
.tiptap-prosemirror .doc-line-marker {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8pt 0 0;
    border-radius: 4px 4px 0 0;
    font-family: var(--bs-body-font-family);
    cursor: default;
    user-select: none;
}

.tiptap-prosemirror .doc-line-marker.ProseMirror-selectednode {
    outline: 2px solid #f9ab00;
}

.tiptap-prosemirror .doc-line-marker + .tableWrapper {
    outline: 1px dashed #f9ab00;
    outline-offset: 0;
}

.tiptap-prosemirror .merge-field.ProseMirror-selectednode {
    outline: 2px solid #1a73e8;
    outline-offset: 1px;
}

.doc-sheet .tiptap-prosemirror .merge-field {
    font-size: 0.95em;
    padding: 0 4px;
}

/* Popovers and the field/image bubble */
.doc-popover,
.doc-bubble {
    position: absolute;
    z-index: 20;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    padding: 0.5rem;
}

.doc-bubble {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    max-width: 26rem;
}

.doc-bubble-title {
    font-weight: 600;
    font-size: 0.8125rem;
}

.doc-bubble-key {
    color: var(--bs-secondary-color);
    font-size: 0.75rem;
    margin-right: 0.25rem;
}

.doc-bubble-check {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    margin: 0 0.25rem;
}

.doc-color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1.5rem);
    gap: 0.25rem;
}

.doc-color-clear,
.doc-color-custom {
    grid-column: 1 / -1;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--radius-sm);
    background: none;
    padding: 0.125rem 0.375rem;
    font-size: 0.78rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
}

.doc-color-custom input {
    width: 1.5rem;
    height: 1.25rem;
    padding: 0;
    border: none;
    background: none;
}

.doc-color-swatch {
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    padding: 0;
    cursor: pointer;
}

.doc-color-swatch:hover {
    outline: 2px solid var(--ampleo-primary);
}

.doc-table-grid {
    display: grid;
    grid-template-columns: repeat(8, 1.1rem);
    gap: 2px;
}

.doc-table-grid button {
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    border-radius: 2px;
}

.doc-table-grid button.on {
    background: color-mix(in srgb, var(--ampleo-primary) 30%, transparent);
    border-color: var(--ampleo-primary);
}

.doc-table-grid-caption {
    text-align: center;
    font-size: 0.78rem;
    margin-top: 0.25rem;
}

.doc-link-form {
    display: flex;
    gap: 0.25rem;
    min-width: 20rem;
}

/* The merge field panel beside the sheet stays in view while scrolling a long document. */
.doc-field-panel {
    position: sticky;
    top: var(--doc-sticky-top, 0.75rem);
    max-height: calc(100vh - var(--doc-sticky-top, 0.75rem) - 1.5rem);
    display: flex;
    flex-direction: column;
}

.doc-field-panel .doc-field-groups {
    overflow-y: auto;
    flex: 1 1 auto;
}

.doc-field-group-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    border: none;
    background: light-dark(#f8f9fa, var(--bs-tertiary-bg));
    border-bottom: 1px solid var(--bs-border-color);
    padding: 0.375rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: left;
}

.doc-field-group-header.doc-field-group-line {
    background: light-dark(#fef7e0, color-mix(in srgb, #fef7e0 14%, var(--app-surface)));
    color: #b45309;
}

.doc-field-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-bottom: 1px solid light-dark(#f1f3f5, var(--bs-border-color));
}

.doc-field-item > button:first-child {
    flex: 1 1 auto;
    border: none;
    background: none;
    text-align: left;
    padding: 0.3rem 0.75rem;
    font-size: 0.8125rem;
}

.doc-field-item > button:hover {
    background: light-dark(#f1f5fb, var(--bs-tertiary-bg));
}

.doc-field-item .doc-field-add-column {
    border: none;
    background: none;
    padding: 0.25rem 0.5rem;
    color: #b45309;
    font-size: 0.75rem;
    white-space: nowrap;
}

.doc-preview-frame {
    width: 100%;
    height: 75vh;
    border: none;
}

/* Document preview in modal; a light .doc-sheet like the template editor's, since a template's own inline
   colours assume white paper. Smaller margins than the real page so it fits the modal. */
.doc-sheet.document-preview {
    max-height: 60vh;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    box-shadow: none;
}
.doc-sheet.document-preview .tiptap-prosemirror { min-height: 0; }

/* Command bar */
.command-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.page-header .command-bar {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    justify-content: flex-end;
}

/* Once the browser has fitted the bar (AmpleoUI.fitCommandBar), the buttons that do not fit are in the "..."
   menu instead of on a second row. */
.command-bar.is-fitted {
    flex-wrap: nowrap;
}

.command-bar > * {
    flex-shrink: 0;
}

.command-bar > .btn,
.command-bar > .dropdown > .btn,
.page-header-actions > .btn {
    --bs-btn-padding-y: 0.375rem;
    --bs-btn-padding-x: 0.75rem;
    --bs-btn-font-size: var(--font-sm);
    --bs-btn-font-weight: 500;
    --bs-btn-border-radius: var(--radius-lg);
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Outline variants become one quiet neutral button; the variant survives only as the icon's tint, so
   the bar has a single filled (primary) action and colour still hints at what a command does. */
.command-bar > [class*="btn-outline-"],
.command-bar > .dropdown > .btn,
.page-header-actions > [class*="btn-outline-"] {
    --bs-btn-color: var(--ampleo-primary);
    --bs-btn-bg: var(--app-surface-muted);
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--app-ink);
    --bs-btn-hover-bg: var(--app-surface-hover);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--app-ink);
    --bs-btn-active-bg: var(--app-surface-hover);
    --bs-btn-active-border-color: transparent;
    --bs-btn-disabled-color: #8796A5;
    --bs-btn-disabled-bg: var(--app-surface-muted);
    --bs-btn-disabled-border-color: transparent;
}

.command-bar > .btn-outline-primary i { color: var(--ampleo-primary); }
.command-bar > .btn-outline-info i { color: light-dark(#0B7285, color-mix(in srgb, #0B7285 45%, white)); }
.command-bar > .btn-outline-success i { color: light-dark(#1E7B45, color-mix(in srgb, #1E7B45 45%, white)); }
.command-bar > .btn-outline-warning i { color: #B7791F; }
.command-bar > .btn-outline-danger i { color: light-dark(#C0392B, color-mix(in srgb, #C0392B 45%, white)); }

.command-bar .dropdown-toggle::after {
    display: none;
}

/* ── Pagination ─────────────────────────────────────────────────────────── */
.page-link {
    color: var(--ampleo-primary);
    border-color: var(--ampleo-neutral);
}

.page-link:hover,
.page-link:focus {
    color: var(--ampleo-primary);
    background-color: color-mix(in srgb, var(--ampleo-primary) 8%, transparent);
    border-color: var(--ampleo-secondary);
}

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

.page-item.disabled .page-link {
    color: var(--ampleo-neutral);
    border-color: var(--ampleo-neutral);
}

/* The help button is styled in HelpButton.razor.css. */

/* Metric cards - Ampleo palette */
.metric-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

/* Each card takes the next colour of the brand's palette, as a bar on its left and a light tint, so a row of figures
   reads at a glance. A card coloured by its value (an option's own colour) keeps that tint over this one. */
.metric-card {
    --metric-accent: #2A4D69;
    background: color-mix(in srgb, var(--metric-accent) 15%, var(--app-surface));
    border: 1px solid color-mix(in srgb, var(--metric-accent) 25%, transparent);
    border-left: 4px solid var(--metric-accent);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    transition: box-shadow 0.15s ease;
}

.metric-card:nth-child(4n+2) { --metric-accent: #8B7355; }
.metric-card:nth-child(4n+3) { --metric-accent: #3D8A5E; }
.metric-card:nth-child(4n+4) { --metric-accent: #4A6FA5; }

.metric-card:hover {
    box-shadow: 0 2px 6px rgba(42, 77, 105, 0.08);
}

.metric-value {
    font-weight: 600;
    font-size: 1.25rem;
    line-height: 1.3;
    color: light-dark(color-mix(in srgb, var(--metric-accent, #2A4D69) 85%, black),
                      color-mix(in srgb, var(--metric-accent, #2A4D69) 50%, white));
}

.metric-value.is-empty {
    color: #A9B4BF;
}

.metric-label {
    font-size: 0.75rem;
    color: var(--ampleo-secondary);
    margin-bottom: 0.25rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* Section headers on forms */
/* A tab with fields beside a growing timeline (TimelineDefinition.GrowOnWideScreens): the fields stop at a readable
   width and the timeline takes what is left, so a wide screen gives its width to the activity. */
@media (min-width: 768px) {
    .form-row-timeline-grows > .form-col-fields { flex: 0 0 auto; width: min(50%, 720px); }
    .form-row-timeline-grows > .form-col-timeline { flex: 1 1 0; width: auto; min-width: 0; }
}

.form-section-header {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--ampleo-secondary);
    letter-spacing: 0.02em;
    margin-bottom: 0.75rem;
    margin-top: 0.25rem;
    text-transform: none;
}

/* Section divider within a form column: a bold uppercase heading with a coloured accent
   bar on the left and generous space above, so each section reads as a distinct block on
   the same page instead of fields lumping together. */
.form-section-divider {
    margin-top: 1.85rem;
    margin-bottom: 1rem;
}

    .form-section-divider .form-section-header {
        margin: 0;
        padding-left: 0.6rem;
        border-left: 3px solid var(--ampleo-accent);
        font-weight: 700;
        font-size: 0.9375rem;
        line-height: 1.15;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--ampleo-primary);
    }

/* Form labels - compact and muted, matching prototype */
.form-label {
    font-size: 0.75rem;
    color: var(--ampleo-secondary);
    font-weight: 500;
    margin-bottom: 0.25rem;
    letter-spacing: 0.01em;
}

/* Form inputs - consistent compact sizing */
.form-control,
.form-select {
    font-size: 0.875rem;
}

/* Signed-in app only (:where keeps the specificity of a bare class, so Bootstrap's :disabled grey still wins
   and locked fields keep reading as locked). Public pages, print and the iframe layout keep plain fields. */
:where(.app-shell) .form-control,
:where(.app-shell) .form-select {
    border-color: var(--field-line);
}

:where(.app-shell) .form-control:focus,
:where(.app-shell) .form-select:focus {
    border-color: var(--field-focus-line);
    box-shadow: 0 0 0 3px var(--field-focus-ring);
}

:where(.app-shell) .form-check-input:focus {
    border-color: var(--field-focus-line);
    box-shadow: 0 0 0 3px var(--field-focus-ring);
}

/* A section of a form column, from one section break to the next, as a panel. White fields stand out on its
   tone, and the edge keeps neighbouring panels apart. */
.form-section-panel {
    background-color: var(--form-panel);
    border: 1px solid var(--form-panel-line);
    border-radius: var(--radius-lg);
    padding: 0.875rem 1rem 0.125rem;
    margin-bottom: 0.875rem;
}

/* The same grouping without a panel adds no box, so flex layouts of the column are unchanged. */
.form-section-plain {
    display: contents;
}

.form-section-panel > .form-section-divider {
    margin-top: 0;
    margin-bottom: 0.875rem;
}

.form-section-panel > .form-section-divider .form-section-header {
    border-left: 0;
    padding-left: 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.95rem;
}

/* An option whose value has a colour (status, priority) shows it as a dot inside the select. */
.option-select {
    position: relative;
}

.option-select > .option-select-dot {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.option-select > .form-select.has-dot {
    padding-left: 1.85rem;
}

/* Initials in front of a lookup to a person or a company. */
.lookup-avatar.input-group-text {
    padding: 0 0.375rem 0 0.5rem;
    background-color: var(--bs-body-bg);
    border-color: var(--field-line);
    border-right: 0;
}

.lookup-avatar + .form-control {
    border-left: 0;
    padding-left: 0.375rem;
}

.lookup-avatar.lookup-avatar-locked.input-group-text {
    background-color: var(--bs-secondary-bg);
    border-color: var(--field-line);
}

.initials-avatar {
    display: inline-grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
}

/* An empty related list: the entity's icon in a tinted circle above the usual text. */
.grid-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem 1.25rem;
    color: var(--app-muted);
    font-size: var(--font-sm);
}

.grid-empty-state-icon {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    font-size: 1.2rem;
    background-color: color-mix(in srgb, var(--ampleo-accent) 14%, transparent);
    color: var(--app-accent-text);
}

/* Status badge styling */
.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2em 0.6em;
    border-radius: 0.35rem;
}

/* Overdue date accent */
.field-overdue {
    color: light-dark(#dc3545, color-mix(in srgb, #dc3545 45%, white));
    font-weight: 600;
}

/* Rich grid avatar initials */
.avatar-initials {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background-color: var(--ampleo-primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.03em;
}

/* Probability badge – standalone version for main list grids */
.avatar-probability-badge {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.probability-inline-badge {
    display: inline-block;
    padding: 0.15em 0.55em;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.4;
}

/* Colored option badge for list views */
.option-badge {
    display: inline-block;
    padding: 0.2em 0.65em;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    background: color-mix(in srgb, var(--option-color) 15%, transparent);
    color: color-mix(in srgb, var(--option-color) 70%, light-dark(#000, var(--app-ink)));
}

/* Related column avatar bubbles */
.related-avatar-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
    cursor: default;
    border: 2px solid light-dark(#fff, var(--app-surface));
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.related-avatar-bubble:not(:first-child) {
    margin-left: -6px;
}

/* Currency value styling for list views */
.currency-value {
    display: inline-flex;
    align-items: baseline;
    gap: 0.3em;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.currency-symbol {
    font-size: 0.75em;
    font-weight: 500;
    color: var(--bs-secondary-color, #6c757d);
}

.currency-amount {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--bs-body-color, #212529);
}

/* ============================================================
   Print - minimal: just hide UI chrome for dashboard printing
   ============================================================ */
@media print {
    @page { size: A4 landscape; margin: 10mm; }

    .sidebar,
    .command-bar,
    .help-button,
    .help-panel,
    .help-guide,
    #blazor-error-ui,
    .toast-container,
    button,
    .btn,
    select,
    .form-select {
        display: none !important;
    }

    .d-flex.vh-100.overflow-hidden {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }

    .main-content {
        padding: 0 !important;
        overflow: visible !important;
        width: 100% !important;
    }

    body { background: #fff !important; }
    * { box-shadow: none !important; overflow: visible !important; }
}

/* ===== Comparison tables (Compare pages) ===== */
.compare-table td,
.compare-table th {
    vertical-align: middle;
    padding: 0.75rem 1rem;
}
.compare-table td.cmp-val {
    vertical-align: middle;
    padding-left: 2.5rem;
}
.cmp-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.cmp-cell .bi {
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
}

/* ─── Rich Text Editor (form field) ─── */
.rich-text-editor-wrapper .ProseMirror {
    padding: 0.75rem;
    outline: none;
    min-height: 120px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.rich-text-editor-wrapper .ProseMirror:focus {
    outline: none;
}

/* In the app the editor is a field like the others: white (the wrapper is otherwise transparent and takes the
   panel's grey), the field edge, and the focus ring while writing. The wrapper carries Bootstrap's .border
   (!important). */
:where(.app-shell) .rich-text-editor-wrapper {
    background-color: var(--bs-body-bg);
    border-color: var(--field-line) !important;
}

:where(.app-shell) .rich-text-editor-wrapper:focus-within {
    border-color: var(--field-focus-line) !important;
    box-shadow: 0 0 0 3px var(--field-focus-ring);
}

.rich-text-editor-wrapper .ProseMirror p {
    margin-bottom: 0.25rem;
}

.rich-text-editor-wrapper .ProseMirror ul,
.rich-text-editor-wrapper .ProseMirror ol {
    padding-left: 1.5rem;
}

.rich-text-editor-wrapper .ProseMirror blockquote {
    border-left: 3px solid light-dark(#dee2e6, var(--bs-border-color));
    padding-left: 0.75rem;
    margin-left: 0;
    color: light-dark(#6c757d, var(--app-muted));
}

.rich-text-editor-wrapper .ProseMirror a {
    color: var(--ampleo-vivid);
    text-decoration: underline;
}

/* An image is dragged to size from its lower-right corner; the handle shows while pointing at or selecting it. */
.rich-text-editor-wrapper .rte-image {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;
}

.rich-text-editor-wrapper .rte-image img {
    max-width: 100%;
    height: auto;
}

.rich-text-editor-wrapper .rte-image.ProseMirror-selectednode img,
.rich-text-editor-wrapper .rte-image-resizing img {
    outline: 2px solid var(--ampleo-vivid);
}

.rich-text-editor-wrapper .rte-image-handle {
    position: absolute;
    right: -5px;
    bottom: -5px;
    width: 12px;
    height: 12px;
    border: 2px solid var(--bs-body-bg);
    border-radius: 2px;
    background: var(--ampleo-vivid);
    cursor: nwse-resize;
    touch-action: none;
    display: none;
}

.rich-text-editor-wrapper .ProseMirror[contenteditable="true"] .rte-image:hover .rte-image-handle,
.rich-text-editor-wrapper .ProseMirror[contenteditable="true"] .rte-image.ProseMirror-selectednode .rte-image-handle,
.rich-text-editor-wrapper .rte-image-resizing .rte-image-handle {
    display: block;
}

/* ── Mail header (From/To/CC on an email activity) ──────────────────────────
   One line per field as in a mail client: the label in front, people as chips, the search box after them. */
.mail-header {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--radius-md);
    background: var(--app-surface);
}

.mail-header-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: 2.5rem;
    padding: var(--space-xs) var(--space-sm);
}

.mail-header > * + .mail-header-row,
.mail-header > .mail-header-row + .mail-header-row {
    border-top: 1px solid var(--app-line);
}

.mail-header-label {
    flex: 0 0 3rem;
    color: var(--app-muted);
    font-size: var(--font-sm);
}

.mail-header-values {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    min-width: 0;
}

.mail-header-input {
    flex: 1 1 10rem;
    min-width: 10rem;
}

.mail-header-input .form-control {
    background: transparent;
}

.mail-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0.125rem 0.25rem 0.125rem 0.5rem;
    border-radius: 999px;
    background: var(--app-surface-muted);
    font-size: var(--font-sm);
}

.mail-chip-remove {
    border: 0;
    background: transparent;
    color: var(--app-muted);
    padding: 0 0.125rem;
    line-height: 1;
}

.mail-chip-remove:hover {
    color: var(--bs-danger);
}

/* ── Responsive modal widths ────────────────────────────────────────────────
   Bootstrap pins .modal-lg to a fixed 800px (and .modal-xl to 1140px) on any screen wide enough,
   which leaves the larger edit dialogs (forms, scheduler, bulk edit, create-record) needlessly
   narrow on laptops. Instead let them grow with the viewport up to a sensible cap: near-full-width
   on small/medium screens, comfortably wide on large ones. The !important and shared cap override
   Bootstrap's own breakpoint rules at every size. */
.modal-lg {
    max-width: min(1100px, calc(100vw - 2rem)) !important;
}

.modal-xl {
    max-width: min(1400px, calc(100vw - 2rem)) !important;
}


/* A section that starts the column: keep the heading, drop the space that separates it from
   the fields above - there are none. */
.form-section-divider-first {
    margin-top: 0;
}

/* ── File drop zones (DocumentGrid, EmailAttachmentPicker) ──────────────
   The class on the zone is set and cleared by wwwroot/js/file-drop.js, so the highlight
   never crosses the circuit. */
.file-drop-zone {
    position: relative;
}

.file-drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 5;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--ampleo-vivid);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--ampleo-vivid) 6%, light-dark(#fff, var(--app-surface)));
    color: var(--ampleo-primary);
    font-weight: 600;
    /* Without this, moving over the overlay reads as leaving the zone and the highlight flickers. */
    pointer-events: none;
}

.file-drop-zone.file-drop-over .file-drop-overlay {
    display: flex;
}

/* ── Multi-line fields grow with their text ──────────────────────────────
   The height is set by wwwroot/js/textarea-autogrow.js; this is the ceiling it
   grows into. Past it the box scrolls rather than pushing the rest of the form
   down the page - a long description must not turn the form into a scroll hunt
   for the Save button. resize stays available for the rare case someone wants
   more than the cap. */
textarea.form-control.autogrow {
    max-height: 24rem;
    overflow-y: auto;
    resize: vertical;
}

/* Bootstrap Icons has no bubble chart. Drawn as a mask so it takes the text colour like the font icons do. */
.bi-bubble-chart::before {
    content: "";
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    background-color: currentColor;
    --bi-bubble-chart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M1 1v14h14' fill='none' stroke='black' stroke-width='1.5'/%3E%3Ccircle cx='5.5' cy='10' r='2'/%3E%3Ccircle cx='10.5' cy='5.5' r='3'/%3E%3Ccircle cx='12' cy='11.5' r='1.5'/%3E%3C/svg%3E");
    -webkit-mask: var(--bi-bubble-chart) no-repeat center / contain;
    mask: var(--bi-bubble-chart) no-repeat center / contain;
}


/* A colleague mentioned with @ in a note, in the editor and wherever the note is shown. */
.mention {
    background: var(--bs-primary-bg-subtle, #e7f0fb);
    color: var(--bs-primary-text-emphasis, #1b4965);
    border-radius: .25rem;
    padding: 0 .2rem;
    white-space: nowrap;
}

/* The related record's phone and email tucked under its lookup field (PrimaryContactPoints, PrimaryCompanyPhone):
   muted and without inputs, so it reads as the contact's or company's data, not a field on this record. */
.related-contact-points {
    margin-top: -.5rem;
}
.related-contact-points .btn-link {
    color: var(--app-muted);
}
.related-contact-points .btn-link:hover {
    color: var(--bs-link-hover-color);
}

/* A part of a dashboard chart that narrows the drill-down list when clicked (a bar row, a table row, a heatmap cell). */
.dashboard-selectable {
    cursor: pointer;
}
.dashboard-selectable:hover {
    background-color: var(--bs-tertiary-bg);
}

/* Phone layout. The app is built for a desktop and is not meant to be worked in on a phone (the mobile web
   app is), but it should still be navigable there. The menu becomes a drawer behind a top bar, so the page
   gets the full width, and the page header puts its buttons on their own row with icons only. */
.mobile-topbar,
.mobile-menu-backdrop,
.phone-tab-picker {
    display: none;
}

@media (max-width: 767.98px) {
    .app-shell {
        flex-direction: column;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-shrink: 0;
        height: 3.25rem;
        padding: 0 0.5rem;
        background-color: var(--app-surface);
        box-shadow: var(--shadow-float);
        z-index: 30;
    }

    .mobile-topbar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.5rem;
        height: 2.5rem;
        padding: 0;
        border: 0;
        border-radius: var(--radius-lg);
        background: none;
        color: var(--app-ink);
        font-size: 1.5rem;
    }

    .mobile-topbar .sidebar-brand {
        height: auto;
        padding: 0;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1045;
        max-width: calc(100vw - 3rem);
        transform: translateX(calc(-100% - 2 * var(--app-shell-gap)));
        visibility: hidden;
        transition: transform 0.2s ease, visibility 0s linear 0.2s;
    }

    html.mobile-menu-open .sidebar {
        transform: none;
        visibility: visible;
        transition: transform 0.2s ease;
    }

    html.mobile-menu-open .mobile-menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1040;
        background-color: rgba(0, 0, 0, 0.35);
    }

    .sidebar-collapse-toggle {
        display: none !important;
    }

    /* A header that wraps to several rows would cover half the screen if it stayed stuck at the top. */
    .page-header {
        position: static;
        flex-wrap: wrap;
    }

    .page-header > h1,
    .page-header-title,
    .page-header:has(> .command-bar) > .page-header-title {
        min-width: 0;
    }

    .page-header .command-bar,
    .page-header-actions,
    .page-header > .d-flex:not(.page-header-title) {
        flex: 1 1 100%;
        justify-content: flex-start;
    }

    .page-header-actions > .input-group,
    .page-header > .d-flex > .input-group {
        width: 100%;
    }

    /* Icons only, except Save and any command without an icon; the label stays as the accessible name. */
    .command-bar > .btn:not([data-command="save"]):has(> .bi) > .command-label {
        display: none;
    }

    .command-bar > .btn:not([data-command="save"]) > .bi {
        margin-right: 0 !important;
    }

    /* A record's tab row wraps to three or four lines here; the side panel's tab dropdown takes one. */
    .phone-tab-picker {
        display: block;
    }

    .record-tabs {
        display: none !important;
    }

    /* A row of toggle buttons (Min dag's type filter) scrolls sideways rather than running off the page.
       Not a group with a dropdown, whose menu the scroll container would clip. */
    .page-header .btn-group:not(:has(.dropdown-menu)) {
        max-width: 100%;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .page-header .btn-group:not(:has(.dropdown-menu)) > .btn {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* Settings search, at the top of the Settings menu. Folded to icons there is no room to type, so it hides. */
.settings-search .dropdown-menu {
    max-height: 60vh;
    overflow-y: auto;
}

.settings-search .settings-search-path {
    font-size: 0.75rem;
}

@media (min-width: 768px) {
    html.sidebar-collapsed .settings-search {
        display: none;
    }
}

/* The section a search hit leads to, marked for a moment once scrolled to. Clear of the sticky page header. */
.settings-search-hit {
    scroll-margin-top: 6rem;
    animation: settings-search-hit 2s ease-out;
    border-radius: 0.25rem;
}

@keyframes settings-search-hit {
    from { background-color: var(--bs-warning-bg-subtle); box-shadow: 0 0 0 0.5rem var(--bs-warning-bg-subtle); }
    to { background-color: transparent; box-shadow: 0 0 0 0.5rem transparent; }
}

/* Content shown only when a field has a value (document-template-editor.js, MergeConditions): a framed section
   with its condition on top, and a row marked at its left edge. */
.tiptap-prosemirror .doc-condition {
    position: relative;
    border: 1px dashed #a78bfa;
    border-radius: 3px;
    padding: 16px 6px 2px;
    margin: 0 0 6pt;
}

.doc-condition-label {
    position: absolute;
    top: 0;
    left: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--bs-body-font-family);
    font-size: 9px;
    font-weight: 600;
    color: light-dark(#6d28d9, #c4b5fd);
    user-select: none;
}

.tiptap-prosemirror tr[data-if-field] > :first-child {
    box-shadow: inset 3px 0 0 #a78bfa;
}

.doc-condition-hint.doc-condition-now {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    background: light-dark(#f3e8ff, color-mix(in srgb, #f3e8ff 14%, var(--app-surface)));
    color: light-dark(#6d28d9, #c4b5fd);
}

.doc-condition-picker {
    width: 18rem;
}

.doc-condition-hint {
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    margin-bottom: 0.375rem;
}

.doc-condition-list {
    max-height: 16rem;
    overflow-y: auto;
    margin-top: 0.375rem;
}

.doc-condition-group {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    padding: 0.375rem 0.25rem 0.125rem;
}

.doc-condition-item {
    display: block;
    width: 100%;
    border: none;
    background: none;
    text-align: left;
    padding: 0.2rem 0.5rem;
    font-size: 0.8125rem;
    border-radius: var(--radius-sm);
}

.doc-condition-item:hover {
    background: light-dark(#f1f5fb, var(--bs-tertiary-bg));
}

/* A field showing a record's value (example data) rather than its name. */
.tiptap-prosemirror .merge-field.has-sample {
    background: light-dark(#e8f5e9, color-mix(in srgb, #e8f5e9 14%, var(--app-surface)));
    border-color: #43a047;
    color: light-dark(#1b5e20, color-mix(in srgb, #2e7d32 55%, white));
    white-space: normal;
}
