/* ===== Global Font Size ===== */
html, body {
    font-size: 12px !important;
}

/* ===== Validation ===== */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}
.invalid {
    outline: 1px solid #e50000;
}
.validation-message {
    color: #e50000;
}

/* ===== Error Boundaries ===== */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}
.blazor-error-boundary::after {
    content: "An error has occurred.";
}
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* ===== Animations ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out both;
}
.animate-fade-in {
    animation: fadeIn 0.6s ease-out both;
}
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }

/* ===== Hero Section ===== */
.hero-section {
    min-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0A1F47 0%, #0E2A5E 45%, #123A7E 72%, #1E5FEB 100%);
    margin: -16px;
    padding: 48px 24px;
    position: relative;
    overflow: hidden;
    border-radius: 0 0 24px 24px;
}
.hero-section::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 50%, rgba(22,167,154,0.18) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 20%, rgba(30,95,235,0.15) 0%, transparent 50%);
    animation: fadeIn 2s ease-out;
}
.hero-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    text-align: center;
}
.hero-title {
    font-size: 3.2rem !important;
    font-weight: 800 !important;
    color: #fff;
    letter-spacing: -1px;
    line-height: 1.15 !important;
    margin-bottom: 16px;
}
.hero-subtitle {
    font-size: 1.3rem !important;
    color: rgba(255,255,255,0.85);
    font-weight: 400 !important;
    max-width: 560px;
    margin: 0 auto 36px;
    line-height: 1.6 !important;
}

/* ===== Feature Cards ===== */
.feature-card {
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 16px;
    padding: 32px 24px;
    text-align: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    color: #fff;
}
.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
    background: rgba(255,255,255,0.18);
}
.feature-card .mud-icon-root {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

/* ===== Stat Cards (Dashboard) ===== */
.stat-card {
    border-radius: 16px;
    padding: 24px;
    color: #fff;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.stat-card::after {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
}
.stat-card-blue    { background: linear-gradient(135deg, #0E2A5E, #1E5FEB); }
.stat-card-cyan    { background: linear-gradient(135deg, #1E5FEB, #16A79A); }
.stat-card-purple  { background: linear-gradient(135deg, #7B1FA2, #AB47BC); }
.stat-card-green   { background: linear-gradient(135deg, #2E7D32, #43a047); }
.stat-card-orange  { background: linear-gradient(135deg, #E65100, #F57F17); }

/* ===== Compact Table ===== */
.compact-table .mud-table-cell,
.compact-table .mud-table-head .mud-table-cell {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    font-size: 0.8125rem;
}
.compact-table td,
.compact-table th {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    font-size: 0.8125rem;
}

/* ===== Dispatcher log viewer (full-screen request/response) ===== */
.kartra-log-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1300;
    width: 96vw;
    height: 92vh;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* Panes share the leftover height; each scrolls on its own rather than the dialog. */
.kartra-log-panes {
    display: flex;
    gap: 16px;
    flex: 1 1 auto;
    min-height: 0;
}
.kartra-log-pane {
    flex: 1 1 50%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.kartra-log-code {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: #1e1e1e;
    border-radius: 8px;
}
.kartra-log-code pre {
    margin: 0;
    color: #d4d4d4;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}
.kartra-log-code pre.kartra-log-empty {
    color: #7a7a7a;
    font-style: italic;
}
/* Tabs (one per Apptivo record, plus Changes) sit between the dialog and the panes, so they
   pass the leftover height down; the active panel scrolls when its content (Changes) runs long. */
.kartra-log-tabs {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.kartra-log-tabs > .mud-tabs-panels {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.kartra-log-tabpanel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: auto;
}
/* Narrow screens can't hold two columns — stack them and let the dialog scroll. */
@media (max-width: 900px) {
    .kartra-log-panes {
        flex-direction: column;
        overflow-y: auto;
    }
    .kartra-log-pane {
        flex: 0 0 auto;
        min-height: 240px;
    }
}

/* ===== Toolbar Upload Fix ===== */
.toolbar-upload {
    margin: 0 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    border: none !important;
}

/* ===== Page Headers ===== */
.page-header {
    margin-bottom: 24px;
}
.page-header-title {
    font-weight: 700 !important;
    font-size: 1.6rem !important;
}
.page-header-desc {
    color: var(--mud-palette-text-secondary);
    margin-top: 4px;
}

/* ===== Nav Drawer Brand ===== */
.nav-brand {
    padding: 12px 14px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #0E2A5E, #1E5FEB);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.nav-brand-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--mud-palette-text-primary);
}
.nav-brand-sub {
    font-size: 0.65rem;
    color: var(--mud-palette-text-secondary);
    margin-top: -2px;
}

/* ===== Compact Nav Links ===== */
.mud-navmenu .mud-nav-link {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    min-height: 34px !important;
    font-size: 13px !important;
}

/* ===== Drawer Scrollbar ===== */
.mud-drawer-content {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}
.mud-drawer-content::-webkit-scrollbar {
    width: 4px;
}
.mud-drawer-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}
.mud-navmenu {
    overflow: visible !important;
}
.mud-nav-link {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

/* ===== User Menu Alignment ===== */
.mud-popover-open .mud-list-item-icon,
.mud-menu .mud-list-item-icon,
.mud-list .mud-list-item-icon {
    min-width: 28px !important;
    margin-right: 0 !important;
}
.mud-popover-open .mud-list-item-gutters,
.mud-menu .mud-list-item-gutters {
    padding-left: 12px !important;
    padding-right: 16px !important;
}

/* ===== Card Hover ===== */
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0,0,0,0.1) !important;
}

/* ===== AppBar Gradient ===== */
.appbar-gradient .mud-appbar {
    background: linear-gradient(90deg, #0A1F47, #0E2A5E, #1E5FEB) !important;
}

/* ===== Mobile-Friendly Signing ===== */
@media (max-width: 960px) {
    /* Remove fixed height — let the page scroll naturally */
    .signing-container-outer {
        height: auto !important;
        overflow: visible !important;
        min-height: 0 !important;
    }
    /* Stack PDF and questions vertically, remove overflow clipping */
    .signing-layout {
        flex-direction: column !important;
        overflow: visible !important;
        height: auto !important;
        flex: none !important;
        min-height: 0 !important;
    }
    /* PDF panel: fixed height, scrollable */
    .signing-pdf-panel {
        flex: none !important;
        height: 35vh !important;
        max-height: 35vh !important;
        width: 100% !important;
        overflow-y: auto !important;
        min-width: 0 !important;
    }
    /* Questions panel: flow naturally, no clipping */
    .signing-questions-panel {
        flex: none !important;
        width: 100% !important;
        min-width: 0 !important;
        overflow-y: visible !important;
        overflow: visible !important;
        padding-bottom: 24px !important;
    }
    /* Larger touch targets on mobile */
    .signing-questions-panel .mud-button {
        min-height: 48px !important;
    }
    .signing-questions-panel .mud-input {
        font-size: 16px !important;
    }
    .signing-questions-panel .mud-input-label {
        font-size: 14px !important;
    }
    /* Header: stack vertically on small screens */
    .signing-container-outer > div:first-child .mud-stack {
        flex-wrap: wrap;
    }
    /* Signature dialog: make canvas responsive and full width */
    .mud-dialog .mud-dialog-content canvas {
        max-width: 100% !important;
    }
    .mud-dialog {
        margin: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }
    /* MudContainer: reduce padding on mobile */
    .mud-main-content .mud-container {
        padding-left: 12px !important;
        padding-right: 12px !important;
        padding-top: 16px !important;
        padding-bottom: 16px !important;
    }
}

/* ===== Documents page: collapsible filter bar on mobile ===== */
/* Desktop: filters show inline; the mobile toggle/close buttons stay hidden. */
.doc-filter-toggle,
.doc-filter-close {
    display: none !important;
}

@media (max-width: 960px) {
    /* Show the "Filters" toggle, hide the inline filter row by default */
    .doc-filter-toggle {
        display: inline-flex !important;
    }
    .doc-filter-inputs {
        display: none !important;
    }
    /* When opened, stack each filter full-width, one per line */
    .doc-filter-inputs.doc-filter-inputs--open {
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;
        width: 100% !important;
        margin-top: 8px;
    }
    /* Force every filter — and MudBlazor's nested input/picker wrappers — to span
       the full width so they line up uniformly instead of some half, some full. */
    .doc-filter-inputs.doc-filter-inputs--open > *,
    .doc-filter-inputs.doc-filter-inputs--open .mud-input-control,
    .doc-filter-inputs.doc-filter-inputs--open .mud-input,
    .doc-filter-inputs.doc-filter-inputs--open .mud-select,
    .doc-filter-inputs.doc-filter-inputs--open .mud-picker,
    .doc-filter-inputs.doc-filter-inputs--open .mud-autocomplete {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
    .doc-filter-close {
        display: flex !important;
        margin-top: 4px;
    }
}

/* ===== Ensure MudSelect/Autocomplete popovers appear above custom dialogs ===== */
.mud-popover-open {
    z-index: 1900 !important;
}

/* ------------------------------------------------------------------ *
 * PDF mark-up controls (labels + brush) — the layer pdfAnnotator.js
 * builds over each rendered page in the document viewer.
 * ------------------------------------------------------------------ */
.annot-layer {
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;              /* select mode: the page stays scrollable/clickable */
    container-type: inline-size;       /* lets label text size itself in page points */
}

.annot-layer.annot-drawing {
    pointer-events: auto;
    background: rgba(99, 102, 241, 0.04);
}

.annot-layer.annot-drawing .annot-item {
    pointer-events: none;              /* while drawing, nothing existing gets grabbed by mistake */
}

/* …except each control's gear, which stays visible and clickable with a tool still armed — draw a
   mark, then open its settings straight away instead of having to switch back to Select first. */
.annot-layer.annot-drawing .annot-gear {
    pointer-events: auto;
    opacity: 1;
    transform: scale(1);
}

.annot-ink {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

.annot-item {
    position: absolute;
    pointer-events: auto;
    cursor: move;
    border-radius: 4px;
    transition: box-shadow .15s ease, outline-color .15s ease;
    outline: 1px dashed transparent;
    outline-offset: 2px;
}

.annot-item:hover:not(.annot-selected) {
    outline-color: rgba(99, 102, 241, .55);
}

/* Over an ink control the pointer is that control's own nib: press and draw and the stroke joins
   it, no trip back to the palette. Only labels still read as "grab me and drag". */
.annot-brush,
.annot-blackout,
.annot-arrow {
    cursor: crosshair;
}

.annot-item.annot-selected {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
    box-shadow: 0 6px 18px rgba(99, 102, 241, .28);
}

.annot-label {
    padding: 2px 3px;
    /* No overflow clipping here — it used to cut the gear badge in half, since the badge sits on
       the box's corner. The text inside does its own clipping instead. */
}

.annot-text {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 400;
    line-height: 1.25;
    /* pre (not pre-wrap): text does not auto-wrap — the box grows in WIDTH as you type, and only
       breaks to a new line where you press Enter (an explicit newline). */
    white-space: pre;
    overflow-wrap: normal;
    pointer-events: none;
    user-select: none;
}

.annot-text.annot-placeholder {
    color: rgba(100, 116, 139, .85);   /* readable even when the label's ink is "None" */
    opacity: .8;
    font-style: italic;
}

.annot-handle {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: #6366f1;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity .15s ease;
}

.annot-item:hover .annot-handle,
.annot-item.annot-selected .annot-handle {
    opacity: 1;
}

/* Draggable dots at the two ends of an arrow/line — grab the head to re-point it. */
.annot-endpoint {
    position: absolute;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;   /* centre on the endpoint */
    border-radius: 50%;
    background: #6366f1;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
    cursor: grab;
    touch-action: none;
    opacity: 0;
    transition: opacity .15s ease;
    z-index: 4;
}

.annot-item:hover .annot-endpoint,
.annot-item.annot-selected .annot-endpoint {
    opacity: 1;
}

.annot-ghost {
    position: absolute;
    border: 2px dashed #6366f1;
    background: rgba(99, 102, 241, .10);
    border-radius: 4px;
    pointer-events: none;
}

.annot-pop {
    animation: annot-pop .35s cubic-bezier(.2, 1.4, .5, 1);
}

@keyframes annot-pop {
    from { transform: scale(.82); opacity: .35; }
    to   { transform: scale(1);   opacity: 1; }
}

/* Floating "Controls" launcher + palette, docked to the viewer's right edge. */
/* Pinned to the page's bottom-right corner, not to the PDF: the launcher stays put while the
   document scrolls, so it is reachable from any page of the file. */
.controls-dock {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1250;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.controls-palette {
    width: 262px;
    max-width: calc(100vw - 48px);
    padding: 0 0 8px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(248, 250, 252, .97));
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    border: 1px solid rgba(148, 163, 184, .28);
    box-shadow: 0 24px 54px rgba(15, 23, 42, .3), 0 2px 6px rgba(15, 23, 42, .12);
    font: 400 12px/1.35 Inter, system-ui, sans-serif;
    color: #0f172a;
    /* Four tools plus the colour row: on a short viewport the card list scrolls rather than
       pushing the launcher off screen. */
    max-height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: controls-rise .2s cubic-bezier(.2, 1.2, .5, 1) both;
}

@keyframes controls-rise {
    from { transform: translateY(12px) scale(.96); opacity: 0; }
    to   { transform: translateY(0)    scale(1);   opacity: 1; }
}

.controls-head {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 8px;
    padding: 10px 14px;
    background: #eef2ff;
    border-bottom: 1px solid rgba(148, 163, 184, .22);
    font-weight: 600;
    font-size: 12.5px;
    color: #312e81;
}

.controls-cards {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    gap: 6px;
    padding: 10px 10px 4px;
    min-height: 0;
    overflow-y: auto;
}

/* A tool is a card, not a menu row: icon, name, and what the gesture actually is. */
.controls-card {
    display: flex;
    align-items: center;
    /* Buttons centre their flex content by default, which only shows once one card's text is
       narrower than the rest — that card's badge and title then sit adrift of the column. Pin the
       row to the start and let the text block take the slack, so every badge lines up. */
    justify-content: flex-start;
    gap: 11px;
    width: 100%;
    padding: 9px 11px;
    border: 1px solid rgba(148, 163, 184, .3);
    border-radius: 13px;
    background: #fff;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.controls-card:hover {
    border-color: rgba(99, 102, 241, .55);
    box-shadow: 0 6px 16px rgba(99, 102, 241, .16);
    transform: translateY(-1px);
}

.controls-card-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 4px 10px rgba(99, 102, 241, .32);
}

.controls-card-badge.is-brush {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    box-shadow: 0 4px 10px rgba(239, 68, 68, .3);
}

/* Blackout wears the ink it lays down — solid and opaque, not a wash. */
.controls-card-badge.is-blackout {
    background: linear-gradient(135deg, #334155, #0f172a);
    box-shadow: 0 4px 10px rgba(15, 23, 42, .35);
}

/* The host page's placement tools — a different job from drawing, so a different badge. */
.controls-card-badge.is-place {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 4px 10px rgba(5, 150, 105, .3);
}

.controls-card-badge.is-arrow {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    box-shadow: 0 4px 10px rgba(37, 99, 235, .3);
}

.controls-card-text {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.controls-card-text strong {
    font-size: 12.5px;
    font-weight: 600;
    color: #0f172a;
}

.controls-card-text small {
    font-size: 10.5px;
    color: #94a3b8;
}

.controls-card.is-active {
    border-color: transparent;
    background: linear-gradient(135deg, rgba(99, 102, 241, .14), rgba(139, 92, 246, .14));
    box-shadow: inset 0 0 0 1.5px #6366f1;
}

.controls-card.is-active .controls-card-text small { color: #6366f1; }

.controls-line {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 8px;
    margin: 6px 12px 2px;
    padding-top: 9px;
    border-top: 1px solid rgba(148, 163, 184, .22);
}

.controls-line-key {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 500;
    color: #64748b;
}

.controls-line-chips {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.controls-foot {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 0 0 auto;
    gap: 5px;
    margin: 9px 10px 0;
    padding-top: 8px;
    border-top: 1px solid rgba(148, 163, 184, .22);
}

.controls-mini {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 6px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #475569;
    font: 600 10.5px/1.1 inherit;
    cursor: pointer;
    transition: background .13s ease, color .13s ease;
}

.controls-mini:hover { background: rgba(99, 102, 241, .12); color: #4338ca; }
.controls-mini.is-active { background: rgba(99, 102, 241, .16); color: #4338ca; }

.controls-swatch {
    width: 19px;
    height: 19px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .9);
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .18);
    cursor: pointer;
    padding: 0;
    transition: transform .15s ease;
}

.controls-swatch:hover { transform: scale(1.14); }

.controls-swatch-none {
    background:
        linear-gradient(to bottom right, transparent calc(50% - 1px), #ef4444 calc(50% - 1px),
                        #ef4444 calc(50% + 1px), transparent calc(50% + 1px)),
        #fff;
}
.controls-swatch.is-active { transform: scale(1.2); box-shadow: 0 0 0 2px #6366f1; }

.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s ease;
}

.control-row:hover { background: var(--mud-palette-action-default-hover); }
.control-row.is-active { background: rgba(99, 102, 241, .12); }

.control-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: 0 0 auto;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .85);
}

/* Settings panel for the selected control — docked to the viewer's top-right. */
.controls-panel {
    position: fixed;
    top: 96px;
    right: 24px;
    z-index: 1250;
    width: 310px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 210px);
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    background: rgba(255, 255, 255, .93);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, .7);
    box-shadow: 0 20px 46px rgba(15, 23, 42, .26);
    animation: controls-slide .22s ease both;
    overflow: hidden;
}

@keyframes controls-slide {
    from { transform: translateX(14px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

.controls-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 8px 10px 14px;
    font: 600 13px/1.2 inherit;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.controls-panel-head .mud-icon-button { color: #fff; }

.controls-panel-body {
    padding: 14px;
    overflow-y: auto;
}

.controls-panel-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--mud-palette-divider);
    background: rgba(248, 250, 252, .9);
}

/* Read-only viewers see the mark-up but can't grab it. */
.annot-readonly .annot-item { pointer-events: none; }
.annot-readonly .annot-item:hover { outline-color: transparent; }

/* Per-control gear + its pop-out settings (colour, thickness, move, size, delete). */
.annot-gear {
    position: absolute;
    top: -11px;
    right: -11px;
    width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #6366f1;
    color: #fff;
    cursor: pointer;
    opacity: 0;
    transform: scale(.7);
    transition: opacity .15s ease, transform .15s ease;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .35);
}

.annot-gear svg { width: 13px; height: 13px; fill: currentColor; }

.annot-item:hover .annot-gear,
.annot-item.annot-selected .annot-gear {
    opacity: 1;
    transform: scale(1);
}

.annot-menu {
    position: fixed;
    z-index: 1400;
    /* Wide enough for a colour row to stay on one line, with room to spare: the longest row is
       "none" + 8 swatches + the custom picker — 10 chips at 19px on a 23px pitch = 226px — and the
       row also carries a 46px key and 8px gap inside 12px padding either side. 320px leaves 242px
       for the chips. Wrapping them onto a second row made the menu taller and harder to scan. */
    width: 320px;
    max-width: calc(100vw - 24px);
    padding: 0 0 10px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(248, 250, 252, .97));
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    border: 1px solid rgba(148, 163, 184, .28);
    box-shadow: 0 24px 54px rgba(15, 23, 42, .28), 0 2px 6px rgba(15, 23, 42, .12);
    font: 400 12px/1.35 Inter, system-ui, sans-serif;
    color: #0f172a;
    overflow: visible;
    animation: annot-menu-in .18s cubic-bezier(.2, 1.2, .5, 1) both;
}

@keyframes annot-menu-in {
    from { transform: translateY(-6px) scale(.97); opacity: 0; }
    to   { transform: translateY(0)    scale(1);   opacity: 1; }
}

/* Little pointer that ties the panel to the control it belongs to. */
.annot-menu-arrow {
    position: absolute;
    top: -6px;
    width: 12px;
    height: 12px;
    transform: rotate(45deg);
    background: #eef2ff;
    border-left: 1px solid rgba(148, 163, 184, .28);
    border-top: 1px solid rgba(148, 163, 184, .28);
    border-radius: 2px;
}

.annot-menu.is-above .annot-menu-arrow {
    top: auto;
    bottom: -6px;
    background: rgba(248, 250, 252, .97);
    border: 0;
    border-right: 1px solid rgba(148, 163, 184, .28);
    border-bottom: 1px solid rgba(148, 163, 184, .28);
}

.annot-menu-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 8px 10px 12px;
    border-radius: 18px 18px 0 0;
    background: #eef2ff;
    border-bottom: 1px solid rgba(148, 163, 184, .22);
}

.annot-menu-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 3px 8px rgba(99, 102, 241, .38);
}

.annot-menu-badge svg { width: 14px; height: 14px; fill: currentColor; }

.annot-menu-name {
    flex: 1 1 auto;
    font-weight: 600;
    font-size: 12.5px;
    letter-spacing: .01em;
    color: #312e81;
}

.annot-menu-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: background .13s ease, color .13s ease;
}

.annot-menu-close svg { width: 14px; height: 14px; fill: currentColor; }
.annot-menu-close:hover { background: rgba(15, 23, 42, .07); color: #0f172a; }

/* Grouped settings: a titled block per concern, one named line per option. */
.annot-menu-group {
    padding: 9px 12px 4px;
    border-bottom: 1px solid rgba(148, 163, 184, .18);
}

.annot-menu-group:last-of-type { border-bottom: 0; }

.annot-menu-title {
    display: block;
    margin-bottom: 7px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #a5b4fc;
}

.annot-menu-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
}

.annot-menu-key {
    flex: 0 0 46px;
    font-size: 11px;
    font-weight: 500;
    color: #64748b;
}

.annot-menu-chips {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.annot-menu-value {
    flex: 0 0 30px;
    text-align: right;
    font-style: normal;
    font-weight: 600;
    font-size: 11px;
    color: #4338ca;
    font-variant-numeric: tabular-nums;
}

.annot-menu-swatch {
    position: relative;
    width: 19px;
    height: 19px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .16);
    cursor: pointer;
    transition: transform .14s cubic-bezier(.2, 1.3, .5, 1), box-shadow .14s ease;
}

.annot-menu-swatch svg {
    width: 11px;
    height: 11px;
    fill: #fff;
    opacity: 0;
    transform: scale(.5);
    transition: opacity .13s ease, transform .13s ease;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .5));
}

.annot-menu-swatch:hover { transform: scale(1.18); }

.annot-menu-swatch.is-active {
    transform: scale(1.18);
    box-shadow: 0 0 0 2px #6366f1, 0 2px 5px rgba(99, 102, 241, .35);
}

.annot-menu-swatch.is-active svg { opacity: 1; transform: scale(1); }

/* "None" — a crossed-out swatch, so transparent reads as a choice like any colour. */
.annot-menu-none {
    background:
        linear-gradient(to bottom right, transparent calc(50% - 1px), #ef4444 calc(50% - 1px),
                        #ef4444 calc(50% + 1px), transparent calc(50% + 1px)),
        #fff;
}

.annot-menu-none svg { fill: #6366f1; filter: none; }

.annot-menu-custom {
    position: relative;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .16);
    background: conic-gradient(#ef4444, #f59e0b, #facc15, #22c55e, #06b6d4, #3b82f6, #a855f7, #ef4444);
    cursor: pointer;
    overflow: hidden;
    transition: transform .14s cubic-bezier(.2, 1.3, .5, 1);
}

.annot-menu-custom:hover { transform: scale(1.18); }

.annot-menu-custom input {
    position: absolute;
    inset: -6px;
    width: 200%;
    height: 200%;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
}

.annot-menu-select {
    flex: 1 1 auto;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid rgba(148, 163, 184, .45);
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font-size: 11.5px;
    cursor: pointer;
    transition: border-color .13s ease, box-shadow .13s ease;
}

.annot-menu-select:hover { border-color: rgba(99, 102, 241, .6); }

.annot-menu-select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .18);
}

.annot-menu-range {
    flex: 1 1 auto;
    min-width: 0;
    height: 4px;
    accent-color: #6366f1;
    cursor: pointer;
}

.annot-menu-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    margin: 8px 10px 0;
    padding-top: 9px;
    border-top: 1px solid rgba(148, 163, 184, .25);
}

.annot-menu-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 7px 2px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: #475569;
    font: 600 9.5px/1.1 inherit;
    letter-spacing: .02em;
    cursor: pointer;
    transition: background .13s ease, color .13s ease, transform .13s ease;
}

.annot-menu-action svg { width: 17px; height: 17px; fill: currentColor; }

.annot-menu-action:hover {
    background: rgba(99, 102, 241, .13);
    color: #4338ca;
    transform: translateY(-1px);
}

.annot-menu-action:active { transform: translateY(0); }

.annot-menu-action.is-danger:hover { background: rgba(239, 68, 68, .13); color: #b91c1c; }

/* Typing happens on the label itself, so it needs a caret and a visible edit state. */
.annot-text[contenteditable="true"] {
    cursor: text;
    pointer-events: auto;
    user-select: text;
    outline: none;
}

.annot-item:hover .annot-text,
.annot-item.annot-selected .annot-text { pointer-events: auto; cursor: text; }

.annot-text.annot-editing {
    background: rgba(255, 255, 255, .5);
    border-radius: 3px;
}

/* Auto-save is meant to be unremarkable: a quiet line while a write is in flight, and nothing at
   all the rest of the time. */
.controls-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .82);
    color: #e2e8f0;
    font: 500 11.5px/1 Inter, system-ui, sans-serif;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .28);
}

/* One-tap repeat of the last tool, so a second control of the same kind is immediate. */
.controls-repeat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px 7px 10px;
    border: 1px solid rgba(148, 163, 184, .3);
    border-radius: 999px;
    background: rgba(255, 255, 255, .95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #4338ca;
    font: 600 11px/1.2 Inter, system-ui, sans-serif;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .16);
    animation: controls-rise .2s ease both;
    transition: background .14s ease, transform .14s ease;
}

.controls-repeat:hover { background: #eef2ff; transform: translateY(-1px); }

/* Save pill in the dock — the side panel no longer opens by itself, so saving lives out here. */
.controls-save {
    border-radius: 999px !important;
    box-shadow: 0 8px 22px rgba(16, 185, 129, .38) !important;
    animation: controls-rise .2s ease both;
}
