:root {
    /* Immoni logo plum, with lavender, rose and sage companions. */
    --mg-accent-rgb: 32, 18, 44;
    --mg-canvas: #f5f1f6;
    --mg-ink: #20122c;
    --mg-muted: #716579;
    --mg-subtle: #807487;
    --mg-accent: #20122c;
    --mg-accent-deep: #3d2850;
    --mg-pink: #bd5275;
    --mg-green: #288064;
    --mg-purple: #8866a6;
    --mg-line: rgba(154, 137, 166, 0.18);
    --mg-glass-border: rgba(255, 255, 255, 0.78);
    --mg-window: rgba(250, 247, 251, 0.78);
    --mg-panel: rgba(252, 250, 253, 0.72);
    --mg-card: rgba(255, 255, 255, 0.72);
    --mg-card-strong: rgba(255, 255, 255, 0.9);
    --mg-shadow: 0 30px 80px rgba(117, 97, 132, 0.17);
    --mg-card-shadow: 0 14px 34px rgba(121, 101, 135, 0.09);
}

* {
    box-sizing: border-box;
}

html,
body.mg-admin-body {
    min-height: 100%;
    margin: 0;
    color: var(--mg-ink);
    font-family: "Manrope", sans-serif;
    background: var(--mg-canvas);
}

body.mg-admin-body {
    min-height: 100vh;
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

.mg-scene {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    isolation: isolate;
    background:
        radial-gradient(circle at 48% 11%, rgba(255, 255, 255, 0.94), transparent 25%),
        radial-gradient(circle at 7% 75%, rgba(221, 234, 225, 0.48), transparent 28%),
        radial-gradient(circle at 91% 79%, rgba(244, 231, 210, 0.55), transparent 27%),
        linear-gradient(126deg, #f6f3f9 0%, #f4f0f7 48%, #f7f4f9 100%);
}

.mg-backdrop-glow {
    position: absolute;
    z-index: -3;
    border-radius: 999px;
    pointer-events: none;
    filter: blur(34px);
}

.mg-backdrop-glow-blue {
    width: 42vw;
    height: 22vw;
    top: 0;
    left: 33%;
    background: rgba(186, 163, 203, 0.28);
    rotate: -9deg;
}

.mg-backdrop-glow-pink {
    width: 30vw;
    height: 22vw;
    bottom: -8vw;
    left: 5%;
    background: rgba(193, 149, 174, 0.18);
}

.mg-backdrop-glow-yellow {
    width: 28vw;
    height: 32vw;
    right: -10vw;
    bottom: 0;
    background: rgba(223, 197, 156, 0.2);
}

.mg-orb {
    position: absolute;
    z-index: -2;
    pointer-events: none;
}

.mg-orb-top {
    top: -84px;
    right: 12%;
    width: 240px;
    height: 240px;
    border: 5px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    background:
        radial-gradient(circle at 28% 26%, rgba(255, 255, 255, 0.94) 0 7%, transparent 24%),
        radial-gradient(circle at 68% 67%, rgba(164, 133, 187, 0.9), transparent 36%),
        linear-gradient(142deg, rgba(98, 242, 255, 0.8), rgba(255, 255, 255, 0.5) 43%, rgba(180, 154, 198, 0.74));
    box-shadow: inset 18px 12px 28px rgba(255, 255, 255, 0.76), 0 20px 65px rgba(153, 117, 178, 0.22);
    rotate: -18deg;
}

.mg-orb-top::before {
    position: absolute;
    inset: 18px;
    border: 4px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    content: "";
}

.mg-orb-top span {
    position: absolute;
    width: 80px;
    height: 148px;
    top: 38px;
    left: -16px;
    border-radius: 50%;
    background: linear-gradient(90deg, rgba(98, 226, 255, 0.86), rgba(255, 255, 255, 0.8));
    box-shadow: 0 0 26px rgba(255, 255, 255, 0.78);
}

.mg-orb-bottom {
    width: 250px;
    height: 250px;
    left: 8%;
    bottom: -126px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.78), transparent 7%),
        radial-gradient(circle at 38% 28%, #fdb4fd 0, #df61df 30%, #8f49bb 68%, #6c3b9e 100%);
    box-shadow: inset -26px -30px 46px rgba(79, 34, 129, 0.35), 0 34px 80px rgba(150, 63, 185, 0.25);
}

.mg-app-window {
    position: fixed;
    z-index: 3;
    inset: 0;
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: var(--mg-window);
    box-shadow: var(--mg-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(30px) saturate(145%);
    backdrop-filter: blur(30px) saturate(145%);
}

.mg-sidebar {
    display: flex;
    width: 320px;
    min-width: 220px;
    overflow: hidden;
    border-right: 1px solid rgba(255, 255, 255, 0.52);
    background: rgba(247, 245, 249, 0.34);
    box-shadow: inset -1px 0 0 rgba(149, 130, 162, 0.06);
    -webkit-backdrop-filter: blur(26px) saturate(125%);
    backdrop-filter: blur(26px) saturate(125%);
    transition: width 180ms ease, min-width 180ms ease;
}

.mg-sidebar.is-collapsed {
    width: 62px;
    min-width: 62px;
}

/* Unfolded, the menu carries icon and name itself: the icon rail beside it
   would only repeat the icons. Folded, only the rail is left. */
.mg-sidebar:not(.is-collapsed) {
    width: 258px;
    min-width: 220px;
}

.mg-sidebar:not(.is-collapsed) .mg-icon-rail {
    display: none;
}

.mg-icon-rail {
    display: flex;
    width: 62px;
    min-width: 62px;
    flex-direction: column;
    align-items: center;
    padding: 15px 9px 13px;
    border-right: 1px solid rgba(255, 255, 255, 0.46);
    background: rgba(243, 238, 246, 0.26);
}

.mg-rail-logo,
.mg-wordmark-mark {
    display: grid;
    place-items: center;
    color: var(--mg-accent);
    font-weight: 800;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.88);
    box-shadow: 0 8px 22px rgba(118, 95, 135, 0.12), inset 0 1px 0 #fff;
}

.mg-rail-logo {
    width: 38px;
    height: 38px;
    margin-bottom: 23px;
    border-radius: 12px;
    text-decoration: none;
}

.mg-rail-logo img {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.mg-rail-logo span {
    font-size: 17px;
}

.mg-rail-links,
.mg-rail-footer,
.mg-menu-list {
    display: flex;
    flex-direction: column;
}

/* The rail and the menu take whatever height is left and scroll inside it, so
   the last entry is reachable on a short window and on a phone. */
.mg-rail-links {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    align-items: center;
    gap: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.mg-rail-footer {
    width: 100%;
    align-items: center;
    gap: 6px;
}

.mg-rail-footer form,
.mg-menu-footer form {
    margin: 0;
}

.mg-rail-link,
.mg-rail-footer .mg-rail-link {
    position: relative;
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 11px;
    color: #84788c;
    background: rgba(255, 255, 255, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.52);
    text-decoration: none;
    transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.mg-rail-link i {
    color: inherit !important;
    font-size: 18px;
    opacity: 1 !important;
}

.mg-rail-link:hover,
.mg-rail-link.is-active {
    color: var(--mg-accent);
    background: rgba(255, 255, 255, 0.76);
    border-color: rgba(255, 255, 255, 0.94);
    box-shadow: 0 9px 22px rgba(125, 99, 143, 0.15), inset 0 1px 0 #fff;
    transform: translateY(-1px);
}

.mg-rail-link.is-active::before {
    position: absolute;
    left: -10px;
    width: 3px;
    height: 20px;
    border-radius: 0 4px 4px 0;
    background: var(--mg-accent);
    content: "";
    box-shadow: 0 0 12px rgba(153, 117, 178, 0.5);
}

.mg-rail-collapse {
    display: grid;
    width: 38px;
    height: 32px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 10px;
    color: #7b7083;
    background: rgba(255, 255, 255, 0.34);
    transition: background 160ms ease;
}

.mg-rail-collapse:hover {
    background: rgba(255, 255, 255, 0.7);
}

.mg-rail-collapse i {
    font-size: 16px;
    transition: transform 180ms ease;
}


.mg-nav-panel {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    padding: 16px 13px 14px;
    overflow: hidden;
    opacity: 1;
    transition: opacity 120ms ease;
}

.mg-sidebar.is-collapsed .mg-nav-panel {
    display: none;
}

.mg-wordmark {
    display: flex;
    height: 38px;
    align-items: center;
    gap: 9px;
    margin-bottom: 23px;
    color: var(--mg-ink);
    text-decoration: none;
}

.mg-wordmark-logo {
    max-width: 100%;
    height: 24px;
    width: auto;
    object-fit: contain;
    object-position: left center;
}

/* The bundled mark is flat ink, so it is flipped to white on dark surfaces.
   An uploaded logo is left exactly as the customer supplied it. */
body[data-mg-theme="dark"] .mg-brand-default {
    filter: brightness(0) invert(1);
}

.mg-wordmark-text {
    overflow: hidden;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.03em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-menu-list {
    gap: 6px;
}

.mg-menu-footer {
    margin-top: auto;
    padding-top: 12px;
}

.mg-menu-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

/* A slim bar that only shows itself where there is something to scroll. */
.mg-rail-links::-webkit-scrollbar,
.mg-menu-list::-webkit-scrollbar {
    width: 6px;
}

.mg-rail-links::-webkit-scrollbar-thumb,
.mg-menu-list::-webkit-scrollbar-thumb {
    border-radius: 6px;
    background: rgba(123, 112, 131, 0.28);
}

.mg-rail-links::-webkit-scrollbar-track,
.mg-menu-list::-webkit-scrollbar-track {
    background: transparent;
}

body[data-mg-theme="dark"] .mg-rail-links::-webkit-scrollbar-thumb,
body[data-mg-theme="dark"] .mg-menu-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.24);
}

.mg-menu-collapse {
    display: flex;
    width: 100%;
    min-height: 34px;
    align-items: center;
    gap: 10px;
    padding: 0 11px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 10px;
    color: #7b7083;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.34);
    transition: background 160ms ease;
}

.mg-menu-collapse:hover {
    background: rgba(255, 255, 255, 0.7);
}

.mg-menu-collapse i {
    width: 17px;
    font-size: 16px;
}

.mg-menu-link,
.mg-menu-footer .mg-menu-link {
    position: relative;
    display: flex;
    width: 100%;
    min-height: 38px;
    align-items: center;
    gap: 10px;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: #7a7081;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
    background: transparent;
    transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.mg-menu-link i {
    width: 17px;
    color: #8c8293;
    font-size: 17px;
}

.mg-menu-link:hover,
.mg-menu-link.is-active {
    color: var(--mg-accent);
    background: rgba(255, 255, 255, 0.62);
    border-color: rgba(255, 255, 255, 0.78);
    box-shadow: 0 8px 20px rgba(119, 97, 134, 0.08), inset 0 1px 0 #fff;
}

.mg-menu-link.is-active::after {
    position: absolute;
    right: -14px;
    width: 3px;
    height: 24px;
    border-radius: 4px 0 0 4px;
    background: var(--mg-accent);
    content: "";
}

.mg-menu-link.is-active i {
    color: var(--mg-accent);
}

.mg-rail-link:focus-visible,
.mg-rail-collapse:focus-visible,
.mg-menu-collapse:focus-visible,
.mg-menu-link:focus-visible,
.mg-wordmark:focus-visible,
.mg-date-filter:focus-within,
.mg-search:focus-within {
    outline: 3px solid rgba(var(--mg-accent-rgb), 0.28);
    outline-offset: 2px;
}

.mg-workspace {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    background: rgba(250, 249, 251, 0.18);
}

.mg-topbar {
    position: relative;
    z-index: 50;
    display: flex;
    height: 58px;
    min-height: 58px;
    align-items: center;
    gap: 18px;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.52);
    background: rgba(247, 245, 249, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.46);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    overflow: visible;
}

.mg-mobile-menu {
    display: none;
}

.mg-search {
    display: flex;
    width: min(55%, 480px);
    height: 38px;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--mg-accent);
    background: transparent;
}

.mg-search i {
    font-size: 18px;
}

.mg-search input {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--mg-ink);
    font-size: 12px;
    background: transparent;
}

.mg-search input::placeholder {
    color: #8e8496;
    opacity: 1;
}

.mg-top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.mg-top-actions > button {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    padding: 0;
    border: 0;
    color: #817788;
    background: transparent;
}

.mg-top-actions > button i {
    font-size: 18px;
}

.mg-notification-button {
    position: relative;
}

.mg-notification-button::after {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 6px;
    height: 6px;
    border: 2px solid rgba(248, 245, 250, 0.86);
    border-radius: 50%;
    background: var(--mg-pink);
    content: "";
}

.mg-profile-menu {
    position: relative;
    z-index: 60;
}

.mg-profile-menu .menu-sub-dropdown {
    z-index: 1000 !important;
}

.mg-avatar {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.88);
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    background: linear-gradient(145deg, #f6c36c, #a96855 52%, #423a48);
    box-shadow: 0 7px 18px rgba(87, 74, 97, 0.18);
}

.mg-profile-chevron {
    color: #8a8092;
    font-size: 13px;
}

.mg-page-content {
    position: relative;
    z-index: 1;
    min-height: 0;
    flex: 1;
    margin: 0;
    overflow: auto;
    padding: 14px 20px 16px;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 21px 0 0 0;
    background:
        radial-gradient(circle at 67% -10%, rgba(196, 176, 210, 0.2), transparent 30%),
        rgba(253, 252, 253, 0.34);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
    scrollbar-color: rgba(130, 111, 143, 0.24) transparent;
    scrollbar-width: thin;
}

.mg-dashboard {
    width: 100%;
    max-width: none;
    margin: 0;
}

.mg-dashboard-heading {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 8px;
}

.mg-dashboard-kicker {
    display: none;
    color: var(--mg-accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.mg-dashboard-heading h1 {
    margin: 0;
    color: var(--mg-ink);
    font-size: clamp(25px, 2.2vw, 32px);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.15;
}

.mg-date-filter {
    position: relative;
    display: flex;
    min-width: 214px;
    height: 36px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.74);
    border-radius: 12px;
    color: #7d7284;
    background: rgba(255, 255, 255, 0.44);
    box-shadow: 0 8px 22px rgba(119, 100, 132, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.94);
}

.mg-date-filter select {
    width: 100%;
    height: 100%;
    padding: 0 35px 0 13px;
    border: 0;
    outline: 0;
    color: inherit;
    font-size: 11px;
    appearance: none;
    background: transparent;
}

.mg-date-filter i {
    position: absolute;
    right: 12px;
    font-size: 11px;
    pointer-events: none;
}

.mg-analytics-grid {
    display: grid;
    grid-template-areas:
        "revenue kpis"
        "funnel breakdown";
    grid-template-columns: minmax(0, 2.35fr) minmax(245px, 0.78fr);
    gap: 12px;
}

.mg-analytics-card {
    min-width: 0;
    border: 1px solid var(--mg-glass-border);
    border-radius: 16px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(26px) saturate(125%);
    backdrop-filter: blur(26px) saturate(125%);
}

.mg-revenue-card {
    grid-area: revenue;
    min-height: 284px;
    padding: 17px 20px 16px;
}

.mg-kpi-stack {
    display: grid;
    grid-area: kpis;
    grid-template-rows: 1fr auto;
    gap: 12px;
}

.mg-funnel-card {
    grid-area: funnel;
    min-height: 170px;
    padding: 16px 20px;
}

.mg-breakdown-card {
    grid-area: breakdown;
    min-height: 170px;
    padding: 16px 18px;
}

.mg-card-heading,
.mg-card-title-row,
.mg-total-card > div,
.mg-rate-stat,
.mg-chart-legend,
.mg-compare-switch,
.mg-stream-row > div,
.mg-funnel-stats > div,
.mg-breakdown-list > div {
    display: flex;
    align-items: center;
}

.mg-card-heading {
    min-height: 25px;
    justify-content: space-between;
    gap: 12px;
}

.mg-card-heading h2,
.mg-revenue-streams h3 {
    margin: 0;
    color: var(--mg-ink);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.mg-card-heading > a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #7b7183;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
}

.mg-card-heading > a:hover {
    color: var(--mg-accent);
}

.mg-card-heading > a i {
    font-size: 10px;
}

.mg-card-title-row {
    gap: 10px;
}

.mg-positive,
.mg-negative {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--mg-green);
    font-size: 10px;
    font-weight: 700;
}

.mg-negative {
    color: var(--mg-pink);
}

.mg-positive i,
.mg-negative i {
    font-size: 14px;
}

.mg-negative span {
    color: var(--mg-muted);
    font-weight: 500;
}

.mg-revenue-toolbar {
    display: flex;
    min-height: 36px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.mg-chart-legend {
    gap: 22px;
    color: var(--mg-muted);
    font-size: 10px;
}

.mg-chart-legend > span,
.mg-funnel-stats > div {
    display: flex;
    align-items: center;
    gap: 7px;
}

.mg-legend-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    min-width: 6px;
    border-radius: 50%;
}

.mg-legend-current,
.mg-breakdown-blue {
    background: var(--mg-accent);
}

.mg-legend-previous {
    background: #e3dce8;
}

.mg-legend-pink,
.mg-breakdown-pink {
    background: var(--mg-pink);
}

.mg-legend-green,
.mg-breakdown-green {
    background: var(--mg-green);
}

.mg-breakdown-purple {
    background: var(--mg-purple);
}

.mg-breakdown-sky {
    background: #b59bc7;
}

.mg-breakdown-peach {
    background: #f4a57e;
}

.mg-compare-switch {
    gap: 8px;
    color: var(--mg-muted);
    font-size: 10px;
    white-space: nowrap;
}

.mg-compare-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mg-compare-switch > i {
    position: relative;
    display: block;
    width: 29px;
    height: 16px;
    border-radius: 999px;
    background: #d5ceda;
    box-shadow: inset 0 1px 3px rgba(94, 75, 107, 0.18);
}

.mg-compare-switch > i::after {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 5px rgba(81, 64, 94, 0.24);
    content: "";
    transition: transform 160ms ease;
}

.mg-compare-switch input:checked + i {
    background: var(--mg-accent);
}

.mg-compare-switch input:checked + i::after {
    transform: translateX(13px);
}

.mg-revenue-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.72fr) minmax(170px, 0.72fr);
    gap: 20px;
}

.mg-line-chart {
    position: relative;
    min-width: 0;
    height: 190px;
    padding: 7px 0 25px 35px;
}

.mg-line-chart svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.mg-chart-grid line {
    stroke: rgba(145, 128, 157, 0.18);
    stroke-width: 1;
}

.mg-chart-area {
    fill: url(#mgChartFill);
}

.mg-chart-current,
.mg-chart-previous {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 3;
}

.mg-chart-current {
    stroke: var(--mg-accent);
}

.mg-chart-previous {
    stroke: #dbd4e0;
    stroke-width: 2;
}

.mg-chart-focus-line {
    stroke: rgba(var(--mg-accent-rgb), 0.24);
    stroke-dasharray: 4 5;
}

.mg-chart-point-ring {
    fill: rgba(255, 255, 255, 0.9);
    stroke: var(--mg-accent);
    stroke-width: 2;
}

.mg-chart-point {
    fill: var(--mg-accent);
}

.mg-y-axis {
    position: absolute;
    inset: 4px auto 27px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: var(--mg-muted);
    font-size: 9px;
}

.mg-x-axis {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 35px;
    display: flex;
    justify-content: space-between;
    color: var(--mg-muted);
    font-size: 9px;
}

.mg-chart-tooltip {
    position: absolute;
    top: 62px;
    right: 13%;
    display: flex;
    width: 91px;
    flex-direction: column;
    gap: 2px;
    padding: 8px 9px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 9px;
    color: #fff;
    font-size: 8px;
    background: rgba(69, 56, 79, 0.84);
    box-shadow: 0 8px 20px rgba(70, 55, 80, 0.2);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.mg-chart-tooltip span {
    margin-bottom: 2px;
    font-size: 9px;
}

.mg-chart-tooltip small {
    display: flex;
    justify-content: space-between;
    font-size: 7px;
}

.mg-chart-tooltip strong {
    font-weight: 700;
}

.mg-revenue-streams {
    padding-top: 6px;
}

.mg-revenue-streams h3 {
    margin-bottom: 10px;
    font-size: 11px;
}

.mg-stream-row {
    margin-bottom: 8px;
}

.mg-stream-row > div {
    gap: 8px;
    margin-bottom: 4px;
    color: var(--mg-muted);
    font-size: 9px;
}

.mg-stream-row > div span {
    overflow: hidden;
    flex: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-stream-row > div strong {
    color: var(--mg-ink);
    font-size: 9px;
}

.mg-stream-row > div small {
    min-width: 30px;
    text-align: right;
}

.mg-stream-row > i {
    display: block;
    height: 3px;
    overflow: hidden;
    border-radius: 99px;
    background: rgba(220, 212, 226, 0.7);
}

.mg-stream-row > i span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--mg-accent);
}

.mg-stream-78 { width: 78%; }
.mg-stream-56 { width: 56%; }
.mg-stream-28 { width: 28%; }
.mg-stream-24 { width: 24%; }
.mg-stream-20 { width: 20%; }
.mg-stream-10 { width: 10%; }

.mg-abandonment-card {
    min-height: 205px;
    padding: 16px 18px;
}

.mg-abandonment-card .mg-card-heading > i {
    color: #9d94a3;
    font-size: 13px;
}

.mg-abandonment-card > p {
    margin: 8px 0 12px;
    line-height: 1.45;
}

.mg-rate-stat {
    gap: 12px;
    margin-top: 10px;
}

.mg-ring {
    position: relative;
    display: grid;
    width: 48px;
    height: 48px;
    min-width: 48px;
    place-items: center;
    border-radius: 50%;
    color: var(--mg-pink);
    background: conic-gradient(var(--mg-pink) 0 61%, rgba(245, 31, 118, 0.11) 61% 100%);
}

.mg-ring::before {
    position: absolute;
    width: 39px;
    height: 39px;
    border-radius: 50%;
    background: rgba(252, 251, 253, 0.9);
    content: "";
}

.mg-ring i {
    position: relative;
    z-index: 1;
    font-size: 17px;
}

.mg-ring-blue {
    color: var(--mg-accent);
    background: conic-gradient(var(--mg-accent) 0 58%, rgba(var(--mg-accent-rgb), 0.11) 58% 100%);
}

.mg-rate-stat > div:last-child {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.mg-rate-stat strong {
    color: var(--mg-pink);
    font-size: 16px;
    line-height: 1.2;
}

.mg-rate-stat:nth-of-type(2) strong {
    color: var(--mg-accent);
}

.mg-rate-stat span,
.mg-rate-stat small {
    color: var(--mg-muted);
    font-size: 9px;
    line-height: 1.45;
}

.mg-rate-stat small {
    color: var(--mg-ink);
    font-weight: 700;
}

.mg-total-card {
    min-height: 64px;
    padding: 13px 18px;
}

.mg-total-card > span {
    color: var(--mg-ink);
    font-size: 12px;
    font-weight: 700;
}

.mg-total-card > div {
    gap: 9px;
    margin-top: 3px;
}

.mg-total-card strong {
    color: var(--mg-ink);
    font-size: 19px;
    letter-spacing: -0.04em;
}

.mg-total-card small {
    color: var(--mg-green);
    font-size: 9px;
    font-weight: 700;
}

.mg-funnel-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(190px, 0.7fr);
    gap: 22px;
    margin-top: 9px;
}

.mg-bar-chart {
    display: grid;
    height: 104px;
    grid-template-columns: 31px 1fr;
    gap: 7px;
}

.mg-bar-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-bottom: 19px;
    color: var(--mg-muted);
    font-size: 8px;
}

.mg-bar-plot {
    position: relative;
    display: flex;
    min-width: 0;
    align-items: flex-end;
    justify-content: space-around;
    padding: 0 5px 19px;
}

.mg-bar-grid {
    position: absolute;
    inset: 0 0 19px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.mg-bar-grid i {
    height: 1px;
    background: var(--mg-line);
}

.mg-bar-group {
    position: relative;
    z-index: 1;
    display: flex;
    width: 25%;
    height: 100%;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
}

.mg-bar {
    width: 22px;
    min-height: 3px;
    border-radius: 4px 4px 0 0;
}

.mg-bar-blue { background: var(--mg-accent); }
.mg-bar-pink { background: var(--mg-pink); }
.mg-bar-green { background: var(--mg-green); }
.mg-bar-soft { background: rgba(214, 204, 221, 0.66); }
.mg-bar-92 { height: 92%; }
.mg-bar-85 { height: 85%; }
.mg-bar-18 { height: 18%; }
.mg-bar-12 { height: 12%; }
.mg-bar-8 { height: 8%; }
.mg-bar-5 { height: 5%; }

.mg-bar-group small {
    position: absolute;
    bottom: -18px;
    color: var(--mg-muted);
    font-size: 8px;
    white-space: nowrap;
}

.mg-funnel-stats {
    padding-top: 2px;
}

.mg-funnel-stats .mg-compare-switch {
    justify-content: space-between;
    margin-bottom: 12px;
}

.mg-funnel-stats > div {
    display: grid;
    grid-template-columns: 7px 1fr auto 35px;
    min-height: 27px;
    color: var(--mg-muted);
    font-size: 9px;
}

.mg-funnel-stats > div strong {
    color: var(--mg-ink);
    font-size: 9px;
}

.mg-funnel-stats > div small {
    text-align: right;
}

.mg-breakdown-layout {
    display: grid;
    grid-template-columns: minmax(76px, 0.65fr) minmax(125px, 1fr);
    gap: 15px;
    height: 112px;
    margin-top: 8px;
}

.mg-mini-bars {
    display: flex;
    height: 92px;
    align-items: flex-end;
    justify-content: center;
    gap: 5px;
    padding: 12px 7px 0;
    border-bottom: 1px solid var(--mg-line);
    background: repeating-linear-gradient(to bottom, transparent 0, transparent 27px, var(--mg-line) 28px);
}

.mg-mini-bars span {
    width: 9px;
    min-height: 3px;
    border-radius: 3px 3px 0 0;
}

.mg-mini-bar-74 { height: 74%; }
.mg-mini-bar-59 { height: 59%; }
.mg-mini-bar-31 { height: 31%; }
.mg-mini-bar-21 { height: 21%; }
.mg-mini-bar-10 { height: 10%; }
.mg-mini-bar-7 { height: 7%; }

.mg-breakdown-list {
    padding-top: 4px;
}

.mg-breakdown-list > div {
    display: grid;
    grid-template-columns: 6px 1fr auto;
    min-height: 24px;
    gap: 6px;
    color: var(--mg-muted);
    font-size: 8px;
}

.mg-breakdown-list i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.mg-breakdown-list strong {
    color: var(--mg-ink);
    font-size: 8px;
}

.mg-page-content > .card,
.mg-page-content .card {
    width: 100%;
    max-width: none;
    border: 1px solid var(--mg-glass-border);
    border-radius: 16px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.mg-page-content .btn-primary {
    border-color: var(--mg-accent);
    background: linear-gradient(135deg, var(--mg-accent-deep), var(--mg-accent));
}

.mg-page-content .form-control,
.mg-page-content .form-select {
    border: 1px solid rgba(127, 109, 140, 0.42);
    background-color: rgba(255, 255, 255, 0.6);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 2px 8px rgba(108, 89, 122, 0.05);
}

.mg-page-content .form-control:hover,
.mg-page-content .form-select:hover {
    border-color: rgba(115, 92, 132, 0.58);
}

.mg-page-content .form-control:focus,
.mg-page-content .form-select:focus {
    border-color: var(--mg-accent);
    box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.mg-page-content .text-muted,
.mg-page-content .table .text-muted {
    color: #7d7384 !important;
}

.mg-page-content .table {
    color: var(--mg-ink);
}

.mg-page-content .table thead th {
    color: #756a7c !important;
}

.mg-page-content > * {
    width: 100%;
    max-width: none;
}

.mg-page-content .card-header,
.mg-page-content .card-toolbar > .d-flex {
    flex-wrap: wrap;
    gap: 12px;
}

.mg-page-content .table-responsive {
    max-width: 100%;
    width: 100%;
}

.mg-page-content .card-toolbar {
    max-width: 100%;
    justify-content: flex-end;
}

.mg-page-content .card-toolbar > .d-flex {
    justify-content: flex-end;
}

.mg-settings-page {
    width: 100%;
    max-width: none;
    margin: 0;
    padding-bottom: 18px;
}

.mg-settings-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    margin-bottom: 16px;
}

.mg-settings-heading span {
    color: var(--mg-accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.mg-settings-heading h1 {
    margin: 3px 0 4px;
    color: var(--mg-ink);
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -0.035em;
}

.mg-settings-heading p {
    margin: 0;
    color: var(--mg-muted);
    font-size: 13px;
}

.mg-settings-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px 15px;
    border: 1px solid rgba(89, 211, 147, 0.4);
    border-radius: 12px;
    color: #1f754a;
    font-size: 13px;
    font-weight: 700;
    background: rgba(225, 250, 238, 0.58);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

.mg-settings-alert i {
    font-size: 19px;
}

.mg-settings-form {
    display: grid;
    gap: 14px;
}

.mg-settings-card {
    padding: 20px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 16px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(25px) saturate(125%);
    backdrop-filter: blur(25px) saturate(125%);
}

.mg-settings-card-heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 17px;
}

.mg-settings-icon {
    display: grid;
    width: 38px;
    height: 38px;
    min-width: 38px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.86);
    border-radius: 11px;
    color: var(--mg-accent);
    background: rgba(245, 242, 248, 0.7);
    box-shadow: inset 0 1px 0 #fff;
}

.mg-settings-icon i {
    font-size: 19px;
}

.mg-settings-card-heading h2 {
    margin: 0 0 3px;
    color: var(--mg-ink);
    font-size: 16px;
    font-weight: 800;
}

.mg-settings-card-heading p {
    margin: 0;
    color: var(--mg-muted);
    font-size: 12px;
}

.mg-settings-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.mg-settings-field label,
.mg-logo-upload > label {
    display: block;
    margin-bottom: 7px;
    color: var(--mg-ink);
    font-size: 12px;
    font-weight: 700;
}

.mg-settings-input {
    display: flex;
    height: 44px;
    align-items: center;
    gap: 10px;
    padding: 0 13px;
    border: 1px solid rgba(127, 109, 140, 0.42);
    border-radius: 11px;
    color: var(--mg-accent);
    background: rgba(255, 255, 255, 0.42);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.mg-settings-input:focus-within {
    border-color: var(--mg-accent);
    box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.12);
}

.mg-settings-input.has-error {
    border-color: #d65f6b;
}

.mg-settings-input i {
    font-size: 17px;
}

.mg-settings-input input,
.mg-settings-input select,
.mg-settings-input textarea {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--mg-ink);
    font-size: 13px;
    background: transparent;
}

/* A field that needs the whole row: a company name, a note. */
.mg-settings-field.is-wide {
    grid-column: 1 / -1;
}

.mg-settings-input:has(textarea) {
    height: auto;
    align-items: flex-start;
    padding-block: 11px;
}

.mg-settings-input textarea {
    min-height: 62px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
}

/* ── Settings → Company: the signature ──────────────────────────── */
.mg-company-signature {
    display: grid;
    grid-template-columns: minmax(200px, 0.8fr) minmax(0, 1.2fr);
    gap: 18px;
    align-items: start;
}

.mg-company-signature-current {
    display: grid;
    gap: 8px;
    padding: 14px;
    border: 1px solid rgba(127, 109, 140, 0.28);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.4);
}

.mg-company-signature-image {
    width: 100%;
    max-height: 130px;
    object-fit: contain;
    object-position: left center;
}

.mg-company-signature-empty {
    margin: 0;
    color: var(--mg-muted);
    font-size: 12px;
}

.mg-company-signature-remove {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--mg-muted);
    font-size: 12px;
    cursor: pointer;
}

.mg-company-signature-new {
    display: grid;
    gap: 16px;
}

.mg-company-pad {
    width: 100%;
    height: 170px;
    border: 1px dashed rgba(127, 109, 140, 0.55);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.62);
    touch-action: none;
    cursor: crosshair;
}

.mg-company-pad-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.mg-settings-ghost {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1px solid rgba(127, 109, 140, 0.42);
    border-radius: 10px;
    color: var(--mg-ink);
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
}

.mg-settings-ghost:hover {
    background: rgba(255, 255, 255, 0.85);
}

body[data-mg-theme="dark"] .mg-company-signature-current,
body[data-mg-theme="dark"] .mg-company-pad,
body[data-mg-theme="dark"] .mg-settings-ghost {
    background: rgba(255, 255, 255, 0.06);
}

@media (max-width: 860px) {
    .mg-company-signature {
        grid-template-columns: 1fr;
    }
}

.mg-settings-input select {
    appearance: none;
    cursor: pointer;
    padding-right: 18px;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: right 6px center, right 1px center;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.mg-settings-input select option {
    color: #312837;
    background: #fff;
}

.mg-settings-input input::placeholder {
    color: #9a91a1;
}

.mg-settings-hint {
    margin: 6px 0 0;
    color: #897e91;
    font-size: 11.5px;
}

.mg-settings-error {
    margin: 6px 0 0;
    color: #ad3342;
    font-size: 11px;
    font-weight: 700;
}

.mg-logo-setting {
    display: flex;
    align-items: center;
    gap: 18px;
}

.mg-logo-preview {
    display: grid;
    width: 84px;
    height: 84px;
    min-width: 84px;
    place-items: center;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.88);
    border-radius: 18px;
    color: var(--mg-accent);
    font-size: 30px;
    font-weight: 800;
    background: linear-gradient(145deg, rgba(247, 245, 249, 0.88), rgba(238, 232, 242, 0.64));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 #fff;
}

.mg-logo-preview img {
    width: 70px;
    height: 70px;
    object-fit: contain;
}

.mg-logo-upload {
    min-width: 0;
    flex: 1;
}

.mg-logo-upload input {
    width: 100%;
    padding: 9px;
    border: 1px dashed rgba(123, 102, 138, 0.58);
    border-radius: 10px;
    color: #726879;
    background: rgba(255, 255, 255, 0.34);
}

.mg-logo-upload small {
    display: block;
    margin-top: 6px;
    color: var(--mg-muted);
    font-size: 11px;
}

.mg-theme-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.mg-theme-option {
    position: relative;
    display: grid;
    grid-template-columns: 82px 1fr;
    grid-template-rows: auto auto;
    column-gap: 13px;
    align-items: center;
    padding: 13px;
    border: 1px solid rgba(162, 147, 173, 0.26);
    border-radius: 14px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.3);
}

.mg-theme-option:has(input:checked) {
    border-color: var(--mg-accent);
    box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.11);
}

.mg-theme-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mg-theme-option strong {
    color: var(--mg-ink);
    font-size: 13px;
}

.mg-theme-option small {
    color: var(--mg-muted);
    font-size: 11px;
}

.mg-theme-preview {
    display: grid;
    grid-row: 1 / 3;
    grid-template-columns: 21px 1fr;
    grid-template-rows: 14px 1fr;
    width: 82px;
    height: 56px;
    overflow: hidden;
    border: 1px solid rgba(146, 130, 157, 0.26);
    border-radius: 9px;
    box-shadow: 0 7px 16px rgba(99, 81, 112, 0.1);
}

.mg-theme-preview i:first-child { grid-row: 1 / 3; }
.mg-theme-preview i:nth-child(2) { grid-column: 2; }
.mg-theme-preview i:last-child { grid-column: 2; }
.mg-theme-preview-light { background: #f6f3f9; }
.mg-theme-preview-light i:first-child { background: var(--mg-accent); }
.mg-theme-preview-light i:nth-child(2) { background: #eee9f2; }
.mg-theme-preview-light i:last-child { margin: 5px; border-radius: 4px; background: rgba(255, 255, 255, 0.82); }
.mg-theme-preview-dark { background: #271f2d; }
.mg-theme-preview-dark i:first-child { background: var(--mg-accent); }
.mg-theme-preview-dark i:nth-child(2) { background: #392f40; }
.mg-theme-preview-dark i:last-child { margin: 5px; border-radius: 4px; background: #4d4156; }

.mg-settings-actions {
    display: flex;
    justify-content: flex-end;
}

.mg-settings-save {
    display: inline-flex;
    min-height: 43px;
    align-items: center;
    gap: 8px;
    padding: 0 18px;
    border: 1px solid rgba(255, 255, 255, 0.48);
    border-radius: 11px;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--mg-accent-deep), var(--mg-accent));
    box-shadow: 0 10px 24px rgba(132, 97, 157, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.mg-settings-save:hover {
    filter: brightness(1.05);
}

.mg-settings-save:focus-visible,
.mg-theme-option:has(input:focus-visible) {
    outline: 3px solid rgba(var(--mg-accent-rgb), 0.27);
    outline-offset: 3px;
}

body.mg-admin-body[data-mg-theme="dark"] {
    --mg-accent: #89639f;
    --mg-accent-deep: #79558f;
    --mg-accent-rgb: 137, 99, 159;
    --mg-canvas: #1e1824;
    --mg-ink: #f9f7fa;
    --mg-muted: #c2b9c9;
    --mg-subtle: #a397ab;
    --mg-line: rgba(214, 202, 223, 0.14);
    --mg-glass-border: rgba(242, 238, 245, 0.16);
    --mg-window: rgba(44, 35, 50, 0.58);
    --mg-panel: rgba(46, 37, 52, 0.55);
    --mg-card: rgba(46, 37, 52, 0.58);
    --mg-card-strong: rgba(62, 51, 69, 0.68);
    --mg-shadow: 0 30px 80px rgba(10, 7, 12, 0.44);
    --mg-card-shadow: 0 16px 38px rgba(10, 7, 13, 0.28);
}

body[data-mg-theme="dark"] .mg-scene {
    background:
        radial-gradient(circle at 50% 0%, rgba(131, 105, 149, 0.28), transparent 31%),
        radial-gradient(circle at 8% 78%, rgba(46, 139, 137, 0.19), transparent 28%),
        linear-gradient(126deg, #201826, #271f2c 50%, #2c2332);
}

body[data-mg-theme="dark"] .mg-sidebar,
body[data-mg-theme="dark"] .mg-icon-rail,
body[data-mg-theme="dark"] .mg-topbar,
body[data-mg-theme="dark"] .mg-workspace {
    border-color: rgba(239, 234, 243, 0.1);
    background: rgba(41, 33, 46, 0.32);
}

body[data-mg-theme="dark"] .mg-page-content {
    border-color: rgba(239, 234, 243, 0.13);
    background:
        radial-gradient(circle at 67% -10%, rgba(161, 128, 184, 0.16), transparent 30%),
        rgba(42, 33, 48, 0.48);
}

body[data-mg-theme="dark"] .mg-rail-logo,
body[data-mg-theme="dark"] .mg-wordmark-mark,
body[data-mg-theme="dark"] .mg-rail-link,
body[data-mg-theme="dark"] .mg-rail-collapse,
body[data-mg-theme="dark"] .mg-menu-collapse,
body[data-mg-theme="dark"] .mg-date-filter,
body[data-mg-theme="dark"] .mg-settings-input,
body[data-mg-theme="dark"] .mg-logo-upload input,
body[data-mg-theme="dark"] .mg-theme-option {
    border-color: rgba(241, 236, 245, 0.16);
    color: #dcd3e3;
    background: rgba(59, 49, 66, 0.54);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

body[data-mg-theme="dark"] .mg-rail-link:hover,
body[data-mg-theme="dark"] .mg-rail-link.is-active,
body[data-mg-theme="dark"] .mg-menu-link:hover,
body[data-mg-theme="dark"] .mg-menu-link.is-active {
    color: #f0ebf3;
    background: rgba(144, 112, 167, 0.35);
    border-color: rgba(233, 225, 238, 0.16);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

body[data-mg-theme="dark"] .mg-menu-link,
body[data-mg-theme="dark"] .mg-menu-link i,
body[data-mg-theme="dark"] .mg-search input,
body[data-mg-theme="dark"] .mg-settings-input input,
body[data-mg-theme="dark"] .mg-settings-input select {
    color: #d5ccdc;
}

body[data-mg-theme="dark"] .mg-settings-input select option {
    color: #f0ebf3;
    background: #392f41;
}

body[data-mg-theme="dark"] .mg-settings-hint {
    color: #ada1b5;
}

body[data-mg-theme="dark"] .mg-search input::placeholder,
body[data-mg-theme="dark"] .mg-settings-input input::placeholder {
    color: #a59aad;
}

body[data-mg-theme="dark"] .mg-ring::before {
    background: rgba(57, 47, 65, 0.96);
}

body[data-mg-theme="dark"] .mg-chart-tooltip {
    background: rgba(21, 15, 26, 0.88);
}

body[data-mg-theme="dark"] .mg-logo-preview {
    border-color: rgba(241, 236, 245, 0.16);
    color: #e6deec;
    background: linear-gradient(145deg, rgba(91, 75, 102, 0.74), rgba(63, 51, 71, 0.68));
}

body[data-mg-theme="dark"] .mg-settings-alert {
    border-color: rgba(89, 211, 147, 0.24);
    color: #a6e8c5;
    background: rgba(35, 104, 72, 0.28);
}

body[data-mg-theme="dark"] .mg-page-content .form-control,
body[data-mg-theme="dark"] .mg-page-content .form-select {
    border-color: rgba(231, 223, 237, 0.34);
    color: #f4f0f6;
    background-color: rgba(50, 40, 58, 0.66);
}

body[data-mg-theme="dark"] .mg-settings-input,
body[data-mg-theme="dark"] .mg-logo-upload input {
    border-color: rgba(231, 223, 237, 0.34);
}

body[data-mg-theme="dark"] .mg-page-content .form-control:hover,
body[data-mg-theme="dark"] .mg-page-content .form-select:hover,
body[data-mg-theme="dark"] .mg-settings-input:hover {
    border-color: rgba(239, 233, 243, 0.52);
}

body[data-mg-theme="dark"] .mg-page-content .form-control:focus,
body[data-mg-theme="dark"] .mg-page-content .form-select:focus {
    border-color: #c2acd1;
    box-shadow: 0 0 0 3px rgba(181, 155, 199, 0.2);
}

@media (max-width: 1100px) {
    .mg-app-window {
        inset: 0;
    }

    .mg-sidebar {
        width: 290px;
        min-width: 190px;
    }

    .mg-analytics-grid {
        grid-template-columns: minmax(0, 1.9fr) minmax(220px, 0.78fr);
    }

    .mg-revenue-layout {
        grid-template-columns: minmax(0, 1.55fr) minmax(150px, 0.72fr);
        gap: 13px;
    }

    .mg-funnel-layout {
        grid-template-columns: minmax(0, 1.25fr) minmax(170px, 0.8fr);
        gap: 14px;
    }

    .mg-breakdown-layout {
        grid-template-columns: 80px 1fr;
        gap: 9px;
    }
}

@media (max-width: 860px) {
    .mg-app-window {
        inset: 0;
    }

    /* Too narrow for icon and name side by side: the rail alone carries the
       menu here, unfolded or not. */
    .mg-sidebar,
    .mg-sidebar:not(.is-collapsed) {
        width: 62px;
        min-width: 62px;
    }

    .mg-sidebar:not(.is-collapsed) .mg-icon-rail {
        display: flex;
    }

    .mg-nav-panel {
        display: none;
    }

    .mg-page-content {
        padding: 16px;
    }

    .mg-analytics-grid {
        grid-template-areas:
            "revenue"
            "kpis"
            "funnel"
            "breakdown";
        grid-template-columns: 1fr;
    }

    .mg-kpi-stack {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
    }

    .mg-abandonment-card,
    .mg-total-card {
        min-height: 190px;
    }

    .mg-total-card {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

@media (max-width: 700px) {
    body.mg-admin-body {
        overflow: hidden;
    }

    .mg-app-window {
        inset: 0;
        border: 0;
        border-radius: 0;
    }

    .mg-sidebar {
        position: fixed;
        z-index: 30;
        inset: 0 auto 0 0;
        display: none;
    }

    .mg-sidebar.is-mobile-open {
        display: flex;
        width: 250px;
        min-width: 250px;
        border-right: 1px solid rgba(255, 255, 255, 0.65);
        background: rgba(245, 242, 247, 0.88);
        box-shadow: 18px 0 46px rgba(89, 70, 103, 0.22);
    }

    body[data-mg-theme="dark"] .mg-sidebar.is-mobile-open {
        background: rgba(45, 36, 52, 0.94);
    }

    /* The phone menu is always the full one: no rail beside it, no folding. */
    .mg-sidebar.is-mobile-open .mg-icon-rail,
    .mg-sidebar.is-mobile-open .mg-menu-footer {
        display: none;
    }

    .mg-sidebar.is-mobile-open .mg-nav-panel {
        display: flex;
    }

    .mg-topbar {
        padding: 0 14px;
    }

    .mg-mobile-menu {
        display: grid;
        width: 32px;
        height: 32px;
        place-items: center;
        padding: 0;
        border: 0;
        color: var(--mg-accent);
        background: transparent;
    }

    .mg-search {
        width: min(68%, 380px);
        padding-inline: 5px;
    }

    .mg-page-content {
        margin-right: 0;
        margin-bottom: 0;
        border-radius: 18px 18px 0 0;
    }

    .mg-dashboard-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .mg-date-filter {
        width: 100%;
    }

    .mg-revenue-layout,
    .mg-funnel-layout {
        grid-template-columns: 1fr;
    }

    .mg-revenue-streams {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 15px;
    }

    .mg-revenue-streams h3 {
        grid-column: 1 / -1;
    }
}

@media (max-width: 520px) {
    .mg-top-actions > .mg-notification-button,
    .mg-profile-chevron {
        display: none;
    }

    .mg-search {
        width: 100%;
    }

    .mg-page-content {
        padding: 14px;
    }

    .mg-kpi-stack,
    .mg-settings-fields,
    .mg-theme-options {
        grid-template-columns: 1fr;
    }

    .mg-revenue-toolbar {
        align-items: flex-start;
        flex-direction: column;
        padding-block: 8px;
    }

    .mg-line-chart {
        height: 205px;
    }

    .mg-revenue-streams {
        grid-template-columns: 1fr;
    }

    .mg-funnel-layout {
        gap: 18px;
    }

    .mg-breakdown-layout {
        grid-template-columns: 1fr 1.15fr;
    }

    .mg-logo-setting {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-sidebar,
    .mg-rail-link,
    .mg-rail-collapse,
    .mg-rail-collapse i,
    .mg-menu-link,
    .mg-compare-switch > i::after {
        transition: none;
    }
}

/* Rich text output (text blocks) */
.mg-rich-text > *:first-child { margin-top: 0; }
.mg-rich-text > *:last-child { margin-bottom: 0; }
.mg-rich-text h1,
.mg-rich-text h2,
.mg-rich-text h3,
.mg-rich-text h4,
.mg-rich-text h5,
.mg-rich-text h6 { margin: 1.5rem 0 0.75rem; font-weight: 700; }
.mg-rich-text p { margin-bottom: 1rem; }
.mg-rich-text ul,
.mg-rich-text ol { margin: 0 0 1rem 1.25rem; }
.mg-rich-text li { margin-bottom: 0.35rem; }
.mg-rich-text blockquote { margin: 0 0 1rem; padding: 0.5rem 1rem; border-left: 3px solid var(--bs-primary, #a383ba); background: rgba(0, 0, 0, 0.02); }
.mg-rich-text table { width: 100%; margin-bottom: 1rem; border-collapse: collapse; }
.mg-rich-text th,
.mg-rich-text td { padding: 0.5rem 0.75rem; border: 1px solid var(--bs-border-color, #eae7ec); }
.mg-rich-text figure { max-width: 100%; overflow-x: auto; }

/* ── Operational dashboard ──────────────────────────────────────── */
.mg-ops {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-bottom: 4px;
}

.mg-ops-hero {
    position: relative;
    display: flex;
    min-height: 92px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    overflow: hidden;
    padding: 18px 22px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    background:
        radial-gradient(circle at 78% -80%, rgba(188, 165, 205, 0.42), transparent 46%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(249, 247, 250, 0.5));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.mg-ops-hero::after {
    position: absolute;
    top: -48px;
    right: 13%;
    width: 130px;
    height: 130px;
    border: 24px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    content: "";
    pointer-events: none;
}

.mg-ops-eyebrow,
.mg-ops-card-kicker {
    display: block;
    margin-bottom: 4px;
    color: var(--mg-accent);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.mg-ops-hero h1 {
    margin: 0;
    color: var(--mg-ink);
    font-size: clamp(22px, 2.3vw, 31px);
    font-weight: 800;
    letter-spacing: -0.045em;
    line-height: 1.1;
}

.mg-ops-hero p {
    margin: 6px 0 0;
    color: var(--mg-muted);
    font-size: 11px;
}

.mg-ops-hero-actions {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.mg-ops-live,
.mg-ops-action {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    gap: 7px;
    border-radius: 11px;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

.mg-ops-live {
    padding: 0 11px;
    color: var(--mg-muted);
    background: rgba(255, 255, 255, 0.35);
}

.mg-ops-live i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mg-green);
    box-shadow: 0 0 0 4px rgba(48, 199, 115, 0.12);
}

.mg-ops-action {
    padding: 0 13px;
    border: 1px solid rgba(139, 120, 152, 0.2);
    color: var(--mg-ink);
    background: rgba(255, 255, 255, 0.58);
    text-decoration: none;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.mg-ops-action:hover {
    color: var(--mg-accent);
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 8px 18px rgba(113, 92, 128, 0.11);
    transform: translateY(-1px);
}

.mg-ops-action.is-primary {
    border-color: transparent;
    color: #fff;
    background: linear-gradient(135deg, var(--mg-accent-deep), var(--mg-accent));
}

.mg-ops-action.is-primary:hover { color: #fff; }

.mg-ops-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.mg-ops-kpi {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 112px;
    grid-template-columns: 42px minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    gap: 2px 11px;
    overflow: hidden;
    padding: 15px 38px 14px 15px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 17px;
    color: var(--mg-ink);
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.92);
    text-decoration: none;
    transition: transform 170ms ease, box-shadow 170ms ease;
}

.mg-ops-kpi::after {
    position: absolute;
    right: -31px;
    bottom: -42px;
    width: 92px;
    height: 92px;
    border-radius: 50%;
    background: var(--mg-kpi-soft);
    content: "";
}

.mg-ops-kpi:hover {
    color: var(--mg-ink);
    box-shadow: 0 17px 34px rgba(105, 86, 119, 0.14);
    transform: translateY(-2px);
}

.mg-ops-kpi.is-blue { --mg-kpi: var(--mg-accent); --mg-kpi-soft: rgba(var(--mg-accent-rgb), 0.12); }
.mg-ops-kpi.is-danger { --mg-kpi: var(--mg-pink); --mg-kpi-soft: rgba(237, 71, 125, 0.13); }
.mg-ops-kpi.is-healthy { --mg-kpi: var(--mg-green); --mg-kpi-soft: rgba(46, 185, 118, 0.12); }
.mg-ops-kpi.is-purple { --mg-kpi: var(--mg-purple); --mg-kpi-soft: rgba(134, 89, 230, 0.12); }
.mg-ops-kpi.is-teal { --mg-kpi: #398981; --mg-kpi-soft: rgba(21, 169, 164, 0.12); }

.mg-ops-kpi-icon {
    display: grid;
    width: 42px;
    height: 42px;
    grid-row: 1 / 4;
    place-items: center;
    border-radius: 13px;
    color: var(--mg-kpi);
    font-size: 19px;
    background: var(--mg-kpi-soft);
}

.mg-ops-kpi-label {
    overflow: hidden;
    color: var(--mg-muted);
    font-size: 10px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-ops-kpi > strong {
    overflow: hidden;
    color: var(--mg-ink);
    font-size: clamp(18px, 1.7vw, 24px);
    font-weight: 800;
    letter-spacing: -0.045em;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-ops-kpi > small {
    align-self: end;
    overflow: hidden;
    color: var(--mg-subtle);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-ops-kpi-arrow {
    position: absolute;
    z-index: 1;
    top: 18px;
    right: 15px;
    color: var(--mg-kpi);
    font-size: 12px;
}

.mg-ops-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(310px, 0.75fr);
    gap: 12px;
}

.mg-ops-card {
    min-width: 0;
    border: 1px solid var(--mg-glass-border);
    border-radius: 17px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(18px);
}

.mg-ops-recent,
.mg-ops-cash,
.mg-ops-insight { padding: 16px 18px; }

.mg-ops-card-head {
    display: flex;
    min-height: 34px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.mg-ops-card-head h2 {
    margin: 0;
    color: var(--mg-ink);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.mg-ops-card-head > a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--mg-muted);
    font-size: 9px;
    font-weight: 700;
    text-decoration: none;
}

.mg-ops-card-head > a:hover { color: var(--mg-accent); }
.mg-ops-card-head > a i { font-size: 9px; }

.mg-ops-card-kicker {
    margin-bottom: 2px;
    font-size: 8px;
}

.mg-ops-document-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mg-ops-document-row {
    display: grid;
    min-height: 49px;
    grid-template-columns: 34px minmax(140px, 1.35fr) minmax(105px, 0.8fr) 68px minmax(92px, 0.65fr) 12px;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 12px;
    color: var(--mg-ink);
    text-decoration: none;
    transition: background 150ms ease, transform 150ms ease;
}

.mg-ops-document-row:hover {
    color: var(--mg-ink);
    background: rgba(255, 255, 255, 0.46);
    transform: translateX(2px);
}

.mg-ops-document-row + .mg-ops-document-row { border-top: 1px solid var(--mg-line); }

.mg-ops-document-icon {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 10px;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.11);
}

.mg-ops-document-icon.is-invoice {
    color: #20a26d;
    background: rgba(48, 199, 115, 0.12);
}

.mg-ops-document-main,
.mg-ops-document-meta,
.mg-ops-document-money,
.mg-ops-overdue-list a > span {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.mg-ops-document-main strong,
.mg-ops-document-meta strong,
.mg-ops-document-money strong {
    overflow: hidden;
    color: var(--mg-ink);
    font-size: 10px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-ops-document-main small,
.mg-ops-document-meta small,
.mg-ops-document-money small {
    overflow: hidden;
    color: var(--mg-subtle);
    font-size: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-ops-document-money { text-align: right; }

.mg-ops-status {
    display: inline-flex;
    min-height: 22px;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    border-radius: 999px;
    color: #9a6a00;
    font-size: 8px;
    font-weight: 800;
    background: rgba(255, 185, 50, 0.13);
}

.mg-ops-status.is-final {
    color: #158757;
    background: rgba(48, 199, 115, 0.12);
}

.mg-ops-row-arrow { color: var(--mg-subtle); font-size: 10px; }

.mg-ops-empty {
    display: flex;
    min-height: 214px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.mg-ops-empty > span {
    display: grid;
    width: 46px;
    height: 46px;
    margin-bottom: 10px;
    place-items: center;
    border-radius: 14px;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.11);
}

.mg-ops-empty h3 { margin: 0; color: var(--mg-ink); font-size: 13px; }
.mg-ops-empty p { max-width: 330px; margin: 5px 0 10px; color: var(--mg-muted); font-size: 9px; }
.mg-ops-empty a { color: var(--mg-accent); font-size: 9px; font-weight: 800; text-decoration: none; }

.mg-ops-rate {
    padding: 5px 9px;
    border-radius: 999px;
    color: #17885a;
    font-size: 8px;
    font-weight: 800;
    background: rgba(48, 199, 115, 0.12);
}

.mg-ops-cash-total {
    display: flex;
    flex-direction: column;
    margin: 4px 0 10px;
}

.mg-ops-cash-total span { color: var(--mg-muted); font-size: 9px; }
.mg-ops-cash-total strong { color: var(--mg-ink); font-size: 24px; font-weight: 800; letter-spacing: -0.045em; }

.mg-ops-progress {
    display: block;
    width: 100%;
    height: 7px;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    color: var(--mg-green);
    background: rgba(171, 158, 181, 0.15);
    appearance: none;
}

.mg-ops-progress::-webkit-progress-bar { border-radius: 999px; background: rgba(171, 158, 181, 0.15); }
.mg-ops-progress::-webkit-progress-value { border-radius: 999px; background: linear-gradient(90deg, #26b876, #53d492); }
.mg-ops-progress::-moz-progress-bar { border-radius: 999px; background: linear-gradient(90deg, #26b876, #53d492); }
.mg-ops-progress.is-purple::-webkit-progress-value { background: linear-gradient(90deg, var(--mg-accent), #8860e9); }
.mg-ops-progress.is-purple::-moz-progress-bar { background: linear-gradient(90deg, var(--mg-accent), #8860e9); }

.mg-ops-cash-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 12px;
}

.mg-ops-cash-split > div {
    display: grid;
    grid-template-columns: 7px 1fr;
    gap: 1px 7px;
    padding: 8px 9px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.32);
}

.mg-ops-cash-split i {
    width: 7px;
    height: 7px;
    grid-row: 1 / 3;
    margin-top: 3px;
    border-radius: 50%;
}

.mg-ops-cash-split i.is-paid { background: var(--mg-green); }
.mg-ops-cash-split i.is-open { background: var(--mg-accent); }
.mg-ops-cash-split span { color: var(--mg-subtle); font-size: 8px; }
.mg-ops-cash-split strong { color: var(--mg-ink); font-size: 9px; }

.mg-ops-due-summary {
    display: flex;
    min-height: 35px;
    align-items: center;
    justify-content: space-between;
    margin-top: 11px;
    padding: 0 10px;
    border: 1px solid var(--mg-line);
    border-radius: 10px;
    color: var(--mg-muted);
    font-size: 9px;
}

.mg-ops-due-summary span { display: flex; align-items: center; gap: 7px; }
.mg-ops-due-summary i { color: var(--mg-accent); font-size: 13px; }
.mg-ops-due-summary strong { color: var(--mg-ink); }

.mg-ops-overdue-list { margin-top: 10px; }
.mg-ops-overdue-title { color: #c93869; font-size: 8px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }

.mg-ops-overdue-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--mg-line);
    color: var(--mg-ink);
    text-decoration: none;
}

.mg-ops-overdue-list a:last-child { border-bottom: 0; }
.mg-ops-overdue-list a > span:last-child { text-align: right; }
.mg-ops-overdue-list a strong { overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.mg-ops-overdue-list a small { overflow: hidden; color: var(--mg-subtle); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }

.mg-ops-insights-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.mg-ops-card-icon {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 10px;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.11);
}

.mg-ops-card-icon.is-purple { color: var(--mg-purple); background: rgba(132, 91, 234, 0.11); }
.mg-ops-card-icon.is-orange { color: #d98722; background: rgba(244, 165, 126, 0.17); }

.mg-ops-pipeline-total {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 4px 0 10px;
}

.mg-ops-pipeline-total strong { color: var(--mg-ink); font-size: 25px; font-weight: 800; letter-spacing: -0.04em; }
.mg-ops-pipeline-total span { color: var(--mg-muted); font-size: 9px; }
.mg-ops-pipeline-total small { margin-left: auto; color: var(--mg-green); font-size: 8px; font-weight: 800; }

.mg-ops-pipeline-legend {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-top: 12px;
}

.mg-ops-pipeline-legend > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 7px 8px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.3);
}

.mg-ops-pipeline-legend span { color: var(--mg-subtle); font-size: 7px; }
.mg-ops-pipeline-legend strong { color: var(--mg-ink); font-size: 11px; }

.mg-ops-checklist {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mg-ops-checklist a {
    display: grid;
    min-height: 42px;
    grid-template-columns: 29px 1fr auto;
    align-items: center;
    gap: 9px;
    padding: 4px 5px;
    border-radius: 10px;
    color: var(--mg-ink);
    text-decoration: none;
}

.mg-ops-checklist a:hover { background: rgba(255, 255, 255, 0.4); }

.mg-ops-checklist a > span {
    display: grid;
    width: 29px;
    height: 29px;
    place-items: center;
    border-radius: 9px;
    color: #d98722;
    background: rgba(244, 165, 126, 0.17);
}

.mg-ops-checklist a > span.is-ok { color: #209963; background: rgba(48, 199, 115, 0.12); }
.mg-ops-checklist a > div { display: flex; min-width: 0; flex-direction: column; }
.mg-ops-checklist a strong { overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.mg-ops-checklist a small { overflow: hidden; color: var(--mg-subtle); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.mg-ops-checklist a b { min-width: 23px; color: var(--mg-ink); font-size: 12px; text-align: center; }

.mg-ops-health-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.mg-ops-health-grid a {
    display: flex;
    min-height: 49px;
    flex-direction: column;
    justify-content: center;
    padding: 7px 10px;
    border-radius: 10px;
    color: var(--mg-ink);
    background: rgba(255, 255, 255, 0.3);
    text-decoration: none;
}

.mg-ops-health-grid a:hover { background: rgba(255, 255, 255, 0.52); }
.mg-ops-health-grid strong { font-size: 14px; font-weight: 800; }
.mg-ops-health-grid span { color: var(--mg-subtle); font-size: 8px; }

.mg-ops-ai-status {
    display: flex;
    min-height: 42px;
    align-items: center;
    gap: 9px;
    margin-top: 8px;
    padding: 7px 10px;
    border-radius: 10px;
    color: #168658;
    background: rgba(48, 199, 115, 0.1);
}

.mg-ops-ai-status.is-warning { color: #bd6f16; background: rgba(244, 165, 126, 0.16); }
.mg-ops-ai-status > i { font-size: 15px; }
.mg-ops-ai-status > span { display: flex; min-width: 0; flex-direction: column; }
.mg-ops-ai-status strong { color: inherit; font-size: 9px; }
.mg-ops-ai-status small { color: var(--mg-subtle); font-size: 8px; }

.mg-ops a:focus-visible {
    outline: 3px solid rgba(var(--mg-accent-rgb), 0.28);
    outline-offset: 2px;
}

body[data-mg-theme="dark"] .mg-ops-hero,
body[data-mg-theme="dark"] .mg-ops-card,
body[data-mg-theme="dark"] .mg-ops-kpi {
    border-color: rgba(235, 229, 240, 0.13);
    background: linear-gradient(145deg, rgba(66, 53, 75, 0.8), rgba(50, 40, 58, 0.64));
    box-shadow: 0 15px 35px rgba(16, 11, 19, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

body[data-mg-theme="dark"] .mg-ops-action,
body[data-mg-theme="dark"] .mg-ops-live,
body[data-mg-theme="dark"] .mg-ops-document-row:hover,
body[data-mg-theme="dark"] .mg-ops-cash-split > div,
body[data-mg-theme="dark"] .mg-ops-pipeline-legend > div,
body[data-mg-theme="dark"] .mg-ops-health-grid a {
    background: rgba(255, 255, 255, 0.05);
}

body[data-mg-theme="dark"] .mg-ops-action.is-primary {
    background: linear-gradient(135deg, #ab8ec0, var(--mg-accent));
}

@media (max-width: 1250px) {
    .mg-ops-hero { align-items: flex-start; }
    .mg-ops-hero-actions { flex-wrap: wrap; max-width: 430px; }
    .mg-ops-live { width: 100%; justify-content: flex-end; }
    .mg-ops-document-row { grid-template-columns: 34px minmax(140px, 1.4fr) 68px minmax(88px, 0.7fr) 12px; }
    .mg-ops-document-meta { display: none; }
}

@media (max-width: 1050px) {
    .mg-ops-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mg-ops-main-grid { grid-template-columns: 1fr; }
    .mg-ops-insights-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mg-ops-insight:last-child { grid-column: 1 / -1; }
    .mg-ops-health-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 700px) {
    .mg-ops-hero { flex-direction: column; }
    .mg-ops-hero-actions { width: 100%; max-width: none; justify-content: flex-start; }
    .mg-ops-live { justify-content: flex-start; }
    .mg-ops-kpis,
    .mg-ops-insights-grid { grid-template-columns: 1fr; }
    .mg-ops-insight:last-child { grid-column: auto; }
    .mg-ops-document-row { grid-template-columns: 34px minmax(0, 1fr) 64px 12px; }
    .mg-ops-document-money { display: none; }
    .mg-ops-health-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 460px) {
    .mg-ops-hero-actions { align-items: stretch; flex-direction: column; }
    .mg-ops-action { justify-content: center; }
    .mg-ops-document-row { grid-template-columns: 34px minmax(0, 1fr) 12px; }
    .mg-ops-status { display: none; }
    .mg-ops-pipeline-legend { grid-template-columns: 1fr 1fr; }
}

/* ── IMMONI AI chat ─────────────────────────────────────────────── */
.mg-chat {
    --mg-chat-col: 860px;
    --mg-chat-gutter: 28px;
    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);
    gap: 18px;
    height: 100%;
    min-height: 0;
}

.mg-page-content-chat {
    overflow: hidden;
}

/* Header, thread and composer all share one centred column so the whole
   conversation reads on a single axis. */
.mg-chat-col {
    width: 100%;
    max-width: var(--mg-chat-col);
    margin-inline: auto;
}

.mg-chat-sidebar,
.mg-chat-main {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid var(--mg-glass-border);
    border-radius: 22px;
    background: var(--mg-card);
    box-shadow: var(--mg-card-shadow);
    backdrop-filter: blur(18px);
}

.mg-chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 62px;
    padding: 0 16px;
    border-bottom: 1px solid var(--mg-line);
}

.mg-chat-sidebar-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--mg-subtle);
}

.mg-chat-new {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
    background: var(--mg-accent);
    text-decoration: none;
    transition: background 0.18s ease;
}

.mg-chat-new:hover { background: var(--mg-accent-deep); color: #fff; }

.mg-chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.mg-chat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 14px;
    transition: background 0.18s ease;
}

.mg-chat-item:hover { background: var(--mg-card-strong); }
.mg-chat-item.is-active { background: var(--mg-card-strong); box-shadow: inset 0 0 0 1px var(--mg-line); }

.mg-chat-item-link {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 12px;
    text-decoration: none;
    color: var(--mg-ink);
}

.mg-chat-item-title {
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-chat-item-meta { font-size: 0.72rem; color: var(--mg-subtle); }

.mg-chat-item-delete {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin-right: 8px;
    border: 0;
    border-radius: 9px;
    color: var(--mg-subtle);
    background: transparent;
    opacity: 0;
    cursor: pointer;
    transition: opacity 0.18s ease, color 0.18s ease;
}

.mg-chat-item:hover .mg-chat-item-delete,
.mg-chat-item-delete:focus-visible { opacity: 1; }
.mg-chat-item-delete:hover { color: var(--mg-pink); }

.mg-chat-empty-list {
    margin: 10px 12px;
    font-size: 0.8rem;
    color: var(--mg-subtle);
}

.mg-chat-head {
    padding: 18px var(--mg-chat-gutter) 16px;
    border-bottom: 1px solid var(--mg-line);
}

.mg-chat-heading { margin: 0; font-size: 1.05rem; font-weight: 800; color: var(--mg-ink); }

.mg-chat-subheading {
    margin: 4px 0 0;
    font-size: 0.8rem;
    color: var(--mg-muted);
}

.mg-chat-badge {
    display: inline-block;
    margin-right: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--mg-purple);
    background: rgba(131, 87, 231, 0.14);
}

.mg-chat-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 26px var(--mg-chat-gutter);
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

/* No auto top margin: in a scroll container it pushes overflowing content
   above the scrollable area, making the start of the thread unreachable. */
.mg-chat-stream {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.mg-chat-welcome {
    margin: auto;
    padding: 32px 0;
    max-width: 460px;
    text-align: center;
    color: var(--mg-muted);
}

.mg-chat-welcome-mark {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin: 0 auto 16px;
    border-radius: 18px;
    font-size: 1.5rem;
    color: #fff;
    background: linear-gradient(135deg, var(--mg-accent), var(--mg-purple));
}

.mg-chat-welcome h2 { margin: 0 0 6px; font-size: 1.25rem; font-weight: 800; color: var(--mg-ink); }
.mg-chat-welcome p { margin: 0; font-size: 0.88rem; color: var(--mg-muted); }

.mg-chat-message { display: flex; gap: 12px; align-items: flex-start; }
.mg-chat-message.is-user { flex-direction: row-reverse; }
.mg-chat-message.is-assistant { padding-right: 46px; }
.mg-chat-message.is-user { padding-left: 46px; }

.mg-chat-avatar {
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--mg-accent), var(--mg-purple));
}

.mg-chat-message.is-user .mg-chat-avatar {
    background: linear-gradient(135deg, #807687, #615669);
}

.mg-chat-bubble {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    padding: 13px 17px;
    border: 1px solid var(--mg-line);
    border-radius: 18px;
    background: var(--mg-card-strong);
}

.mg-chat-message.is-user .mg-chat-bubble {
    border-color: transparent;
    color: #fff;
    background: linear-gradient(135deg, var(--mg-accent), var(--mg-accent-deep));
}

.mg-chat-message.is-failed .mg-chat-bubble {
    border-color: rgba(245, 31, 118, 0.4);
    background: rgba(245, 31, 118, 0.08);
}

.mg-chat-author {
    display: block;
    margin-bottom: 3px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    opacity: 0.65;
}

.mg-chat-text { font-size: 0.9rem; line-height: 1.62; overflow-wrap: anywhere; }

.mg-chat-composer {
    padding: 16px var(--mg-chat-gutter) 20px;
    border-top: 1px solid var(--mg-line);
}

.mg-chat-error {
    margin-bottom: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--mg-pink);
}

.mg-chat-input-shell {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 9px 9px 9px 12px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 20px;
    background: var(--mg-card-strong);
    transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.mg-chat-input-shell:focus-within { box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.18); }

.mg-chat-input-shell textarea {
    flex: 1;
    min-height: 26px;
    max-height: 220px;
    padding: 4px 0;
    border: 0;
    resize: none;
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--mg-ink);
    background: transparent;
}

.mg-chat-input-shell textarea:focus { outline: none; }

#ia_message:focus-visible,
#mg_chat_message:focus-visible { outline: none; }

@media (min-width: 701px) {
    #ia_message,
    #mg_chat_message { min-height: 37px; }
}

.mg-chat-send {
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 13px;
    font-size: 1rem;
    color: #fff;
    background: var(--mg-accent);
    cursor: pointer;
    transition: background 0.18s ease, opacity 0.18s ease;
}

.mg-chat-send:hover { background: var(--mg-accent-deep); }
.mg-chat-send:disabled,
.mg-chat-send.is-busy { opacity: 0.55; cursor: progress; }

.mg-chat-prompts {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}

.mg-chat-prompt {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    font-size: 0.79rem;
    font-weight: 600;
    color: var(--mg-muted);
    background: var(--mg-card);
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.mg-chat-prompt:hover {
    color: var(--mg-accent);
    border-color: rgba(var(--mg-accent-rgb), 0.45);
    background: var(--mg-card-strong);
}

@media (max-width: 1400px) {
    .mg-chat { --mg-chat-col: 100%; --mg-chat-gutter: 22px; }
    .mg-chat-message.is-assistant { padding-right: 24px; }
    .mg-chat-message.is-user { padding-left: 24px; }
}

@media (max-width: 991px) {
    .mg-page-content-chat { overflow: auto; }

    .mg-chat {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        min-height: 100%;
    }

    .mg-chat-sidebar { max-height: 260px; }
    .mg-chat-main { min-height: 60vh; }
    .mg-chat-item-delete { opacity: 1; }
}

/* Dashboard → IMMONI AI call to action */
.mg-ai-cta {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding: 18px 22px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 20px;
    color: var(--mg-ink);
    text-decoration: none;
    background: var(--mg-card);
    box-shadow: var(--mg-card-shadow);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.mg-ai-cta:hover { transform: translateY(-2px); box-shadow: var(--mg-shadow); color: var(--mg-ink); }

.mg-ai-cta-mark {
    display: grid;
    place-items: center;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    border-radius: 15px;
    font-size: 1.25rem;
    color: #fff;
    background: linear-gradient(135deg, var(--mg-accent), var(--mg-purple));
}

.mg-ai-cta-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mg-ai-cta-body strong { font-size: 0.98rem; font-weight: 800; }
.mg-ai-cta-body span { font-size: 0.83rem; color: var(--mg-muted); }

.mg-ai-cta-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    background: var(--mg-accent);
    white-space: nowrap;
}

@media (max-width: 767px) {
    .mg-ai-cta { flex-wrap: wrap; }
    .mg-ai-cta-action { margin-left: 0; }
}

/* Chat: attachments, mode selector, composer toolbar */
.mg-chat-attach {
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin-bottom: 2px;
    border: 0;
    border-radius: 11px;
    font-size: 0.95rem;
    color: var(--mg-muted);
    background: transparent;
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease;
}

.mg-chat-attach:hover { color: var(--mg-accent); background: rgba(var(--mg-accent-rgb), 0.1); }

.mg-chat-input-shell { padding-left: 8px; }

/* Dragging a file over the conversation: the whole panel becomes the target. */
.mg-chat-drop {
    position: absolute;
    z-index: 5;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    border-radius: 22px;
    background: rgba(247, 245, 249, 0.86);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.mg-chat-drop[hidden] { display: none; }

.mg-chat-drop-card {
    display: grid;
    justify-items: center;
    gap: 6px;
    max-width: 420px;
    padding: 28px 34px;
    border: 2px dashed rgba(var(--mg-accent-rgb), 0.45);
    border-radius: 20px;
    color: var(--mg-ink);
    text-align: center;
    background: var(--mg-card-strong);
}

.mg-chat-drop-card i {
    font-size: 30px;
    color: var(--mg-accent);
}

.mg-chat-drop-card strong { font-size: 1rem; font-weight: 700; }
.mg-chat-drop-card span { font-size: 0.8rem; color: var(--mg-subtle); }

body[data-mg-theme="dark"] .mg-chat-drop {
    background: rgba(35, 28, 41, 0.86);
}

.mg-chat-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.mg-chat-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 12px;
    border: 1px solid var(--mg-line);
    border-radius: 12px;
    font-size: 0.78rem;
    color: var(--mg-ink);
    background: var(--mg-card-strong);
}

.mg-chat-file-name { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.mg-chat-file-size { color: var(--mg-subtle); }

.mg-chat-file-remove {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 7px;
    font-size: 0.68rem;
    color: var(--mg-subtle);
    background: transparent;
    cursor: pointer;
}

.mg-chat-file-remove:hover { color: var(--mg-pink); background: rgba(245, 31, 118, 0.1); }

.mg-chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
}

.mg-chat-modes {
    display: inline-flex;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    background: var(--mg-card);
}

.mg-chat-mode input { position: absolute; opacity: 0; pointer-events: none; }

.mg-chat-mode span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--mg-muted);
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease;
}

.mg-chat-mode span i { font-size: 0.9rem; }
.mg-chat-mode:hover span { color: var(--mg-accent); }

.mg-chat-mode input:checked + span {
    color: #fff;
    background: var(--mg-accent);
}

.mg-chat-mode input:focus-visible + span {
    outline: 2px solid var(--mg-accent);
    outline-offset: 2px;
}

.mg-chat-hint { font-size: 0.74rem; color: var(--mg-subtle); }

.mg-chat-mode-tag {
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.62rem;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.13);
}

.mg-chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.mg-chat-attachment {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--mg-line);
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    color: inherit;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.14);
    transition: border-color 0.18s ease;
}

.mg-chat-attachment:hover { border-color: var(--mg-accent); color: inherit; }
.mg-chat-attachment-name { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-chat-attachment-size { opacity: 0.7; font-weight: 500; }

.mg-chat-attachment.is-image { padding: 0; border-radius: 14px; overflow: hidden; }
.mg-chat-attachment.is-image img { display: block; max-width: 240px; max-height: 200px; object-fit: cover; }

@media (max-width: 767px) {
    .mg-chat-toolbar { flex-direction: column; align-items: flex-start; }
    .mg-chat-modes { width: 100%; justify-content: space-between; }
    .mg-chat-hint { display: none; }
}

/*
 * Dropdown positioning: KTMenu positions its menus with position:fixed and a
 * Popper transform in viewport coordinates. Any ancestor with backdrop-filter,
 * filter or transform becomes their containing block and shifts them down by
 * that ancestor's offset. Keep such properties off .mg-page-content and the
 * cards inside it — .mg-app-window is inset:0, so it stays harmless.
 */

/*
 * Dark theme: Metronic's utility classes (.text-gray-*, .text-dark, .form-label,
 * .badge-light, .btn-light, table borders) read from Bootstrap custom properties
 * that only carry light-theme values, so they stayed near-black on the dark
 * ground. Remap those tokens onto the --mg-* palette so every usage flips at
 * once instead of per-class patches.
 */
body.mg-admin-body[data-mg-theme="dark"] {
    --bs-body-color: var(--mg-ink);
    --bs-heading-color: var(--mg-ink);
    --bs-text-dark: var(--mg-ink);
    --bs-dark: var(--mg-ink);

    --bs-text-gray-900: #ffffff;
    --bs-text-gray-800: var(--mg-ink);
    --bs-text-gray-700: #e6deeb;
    --bs-text-gray-600: var(--mg-muted);
    --bs-text-gray-500: var(--mg-subtle);
    --bs-text-gray-400: var(--mg-subtle);
    --bs-text-muted: var(--mg-subtle);

    --bs-gray-900: #ffffff;
    --bs-gray-800: var(--mg-ink);
    --bs-gray-700: #e6deeb;
    --bs-gray-600: var(--mg-muted);
    --bs-gray-500: var(--mg-subtle);
    --bs-gray-400: rgba(214, 202, 223, 0.4);
    --bs-gray-300: rgba(214, 202, 223, 0.26);
    --bs-gray-200: rgba(214, 202, 223, 0.16);
    --bs-gray-100: rgba(214, 202, 223, 0.1);

    --bs-border-color: var(--mg-line);
    --bs-table-border-color: var(--mg-line);
    --bs-table-color: var(--mg-ink);

    --bs-light: rgba(214, 202, 223, 0.14);
    --bs-light-inverse: var(--mg-ink);
}

body[data-mg-theme="dark"] .mg-page-content .btn-light {
    --bs-btn-color: var(--mg-ink);
    --bs-btn-bg: rgba(214, 202, 223, 0.12);
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--mg-ink);
    --bs-btn-hover-bg: rgba(214, 202, 223, 0.2);
    --bs-btn-active-color: var(--mg-ink);
    --bs-btn-active-bg: rgba(214, 202, 223, 0.24);
}

body[data-mg-theme="dark"] .mg-page-content .table,
body[data-mg-theme="dark"] .mg-page-content .table thead th {
    color: var(--mg-muted);
}

body[data-mg-theme="dark"] .mg-page-content .menu-sub-dropdown {
    border: 1px solid var(--mg-line);
    background: #2b2331;
    box-shadow: var(--mg-shadow);
}

body[data-mg-theme="dark"] .mg-page-content .menu-sub-dropdown .menu-link {
    color: var(--mg-muted);
}

body[data-mg-theme="dark"] .mg-page-content .menu-sub-dropdown .menu-link:hover {
    color: var(--mg-ink);
    background: rgba(214, 202, 223, 0.1);
}

body[data-mg-theme="dark"] .mg-page-content .border-dashed {
    border-color: var(--mg-line) !important;
}

/*
 * CKEditor ships its own light chrome, which renders as a white island inside
 * the dark theme. Map its CSS variables onto the --mg-* palette.
 */
body[data-mg-theme="dark"] .ck.ck-editor {
    --ck-color-base-background: #2b2331;
    --ck-color-base-foreground: #2b2331;
    --ck-color-base-border: var(--mg-line);
    --ck-color-base-text: var(--mg-ink);
    --ck-color-text: var(--mg-ink);
    --ck-color-toolbar-background: #32283a;
    --ck-color-toolbar-border: var(--mg-line);
    --ck-color-button-default-background: transparent;
    --ck-color-button-default-hover-background: rgba(214, 202, 223, 0.14);
    --ck-color-button-default-active-background: rgba(214, 202, 223, 0.2);
    --ck-color-button-on-background: rgba(var(--mg-accent-rgb), 0.28);
    --ck-color-button-on-hover-background: rgba(var(--mg-accent-rgb), 0.36);
    --ck-color-button-on-color: var(--mg-ink);
    --ck-color-dropdown-panel-background: #32283a;
    --ck-color-dropdown-panel-border: var(--mg-line);
    --ck-color-panel-background: #32283a;
    --ck-color-panel-border: var(--mg-line);
    --ck-color-list-background: #32283a;
    --ck-color-list-button-hover-background: rgba(214, 202, 223, 0.14);
    --ck-color-list-button-on-background: rgba(var(--mg-accent-rgb), 0.3);
    --ck-color-list-button-on-text: var(--mg-ink);
    --ck-color-input-background: #2b2331;
    --ck-color-input-border: var(--mg-line);
    --ck-color-input-text: var(--mg-ink);
    --ck-color-labeled-field-label-background: #2b2331;
}

body[data-mg-theme="dark"] .ck.ck-editor__main > .ck-editor__editable,
body[data-mg-theme="dark"] .ck.ck-editor__main > .ck-editor__editable.ck-focused {
    color: var(--mg-ink);
    background: #2b2331;
    border-color: var(--mg-line);
}

body[data-mg-theme="dark"] .ck.ck-toolbar {
    background: #32283a;
    border-color: var(--mg-line);
}

body[data-mg-theme="dark"] .ck.ck-button,
body[data-mg-theme="dark"] .ck.ck-button__label,
body[data-mg-theme="dark"] .ck.ck-toolbar .ck-button .ck-icon {
    color: var(--mg-ink);
}

body[data-mg-theme="dark"] .ck.ck-toolbar .ck-button .ck-icon * {
    fill: currentColor;
}

/*
 * .btn-light sets background-color/color literally (not only via --bs-btn-*),
 * so the token overrides above are not enough — set the properties directly.
 */
body[data-mg-theme="dark"] .mg-page-content .btn-light,
body[data-mg-theme="dark"] .mg-page-content .btn.btn-light {
    color: var(--mg-ink);
    background-color: rgba(214, 202, 223, 0.12);
    border-color: transparent;
}

body[data-mg-theme="dark"] .mg-page-content .btn-light:hover,
body[data-mg-theme="dark"] .mg-page-content .btn.btn-light:hover,
body[data-mg-theme="dark"] .mg-page-content .btn-light:focus,
body[data-mg-theme="dark"] .mg-page-content .btn.btn-light:active {
    color: var(--mg-ink);
    background-color: rgba(214, 202, 223, 0.2);
}

/* Options inside multi-selects render as a list box and inherit an unthemed grey. */
body[data-mg-theme="dark"] .mg-page-content .form-select option,
body[data-mg-theme="dark"] .mg-page-content .form-control option,
body[data-mg-theme="dark"] .mg-page-content select option {
    color: var(--mg-ink);
    background-color: #2b2331;
}

body[data-mg-theme="dark"] .mg-page-content select option:checked {
    color: #ffffff;
    background-color: rgba(var(--mg-accent-rgb), 0.55);
}

/*
 * .badge-light-* / .btn-light-* / .bg-light-* all take their background from
 * --bs-{color}-light, which are fixed pale tints (#dfffea, #fff8dd, …). On the
 * dark ground they render as bright chips with weak text contrast, so swap them
 * for translucent tints of the same accent.
 */
body.mg-admin-body[data-mg-theme="dark"] {
    --bs-primary-light: rgba(146, 109, 173, 0.18);
    --bs-success-light: rgba(23, 198, 83, 0.18);
    --bs-warning-light: rgba(246, 192, 0, 0.18);
    --bs-danger-light: rgba(241, 65, 108, 0.18);
    --bs-info-light: rgba(166, 132, 255, 0.2);
    --bs-secondary-light: rgba(214, 202, 223, 0.14);
    --bs-dark-light: rgba(214, 202, 223, 0.14);
    --bs-light-light: rgba(214, 202, 223, 0.1);

    --bs-info: #a684ff;
    --bs-info-active: #b79bff;
    --bs-secondary-inverse: var(--mg-ink);
    --bs-dark-inverse: var(--mg-ink);
}

/* ── Document wizard ─────────────────────────────────────────────── */
.mg-wizard-steps {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.mg-wizard-step {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border: 1px solid var(--mg-line);
    border-radius: 16px;
    background: var(--mg-card);
    color: var(--mg-ink);
    text-decoration: none;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.mg-wizard-step:hover:not(.is-locked) { border-color: rgba(var(--mg-accent-rgb), 0.45); color: var(--mg-ink); transform: translateY(-1px); }
.mg-wizard-step.is-current { border-color: var(--mg-accent); background: var(--mg-card-strong); box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.14); }
.mg-wizard-step.is-locked { opacity: 0.5; pointer-events: none; }

.mg-wizard-step-mark {
    flex: 0 0 30px;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--mg-muted);
    background: rgba(154, 137, 166, 0.14);
}

.mg-wizard-step.is-done .mg-wizard-step-mark { color: #fff !important; background: #85febb; }
/* The current step keeps the accent mark even when it has already been completed. */
.mg-wizard-step.is-current .mg-wizard-step-mark,
.mg-wizard-step.is-current.is-done .mg-wizard-step-mark { color: #fff !important; background: var(--mg-accent); }

.mg-wizard-step-text { display: flex; flex-direction: column; min-width: 0; }
.mg-wizard-step-text strong { font-size: 0.82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-wizard-step-text span { font-size: 0.71rem; color: var(--mg-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Customer cards (step 2) */
.mg-customer-card,
.mg-picked-card {
    height: 100%;
    padding: 16px;
    border: 1px solid var(--mg-line);
    border-radius: 16px;
    background: var(--mg-card);
}

.mg-customer-card-head,
.mg-picked-card-head { display: flex; align-items: flex-start; gap: 11px; margin-bottom: 12px; }

.mg-picked-card-order {
    flex: 0 0 28px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    background: var(--mg-accent);
}

.mg-picked-card-preview {
    max-height: 132px;
    overflow: hidden;
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--mg-muted);
    -webkit-mask-image: linear-gradient(180deg, #000 68%, transparent);
    mask-image: linear-gradient(180deg, #000 68%, transparent);
}

.mg-picked-card-preview > *:first-child { margin-top: 0; }
.mg-customer-card-body { display: flex; flex-direction: column; gap: 7px; margin: 0; font-size: 0.79rem; }
.mg-customer-card-body > div { display: flex; gap: 10px; }
.mg-customer-card-body dt { flex: 0 0 84px; margin: 0; color: var(--mg-subtle); font-weight: 600; }
.mg-customer-card-body dd { margin: 0; color: var(--mg-ink); overflow-wrap: anywhere; }

/* Layout picker (step 5) */
.mg-layout-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100%;
    padding: 16px;
    border: 1px solid var(--mg-line);
    border-radius: 16px;
    background: var(--mg-card);
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.mg-layout-option:hover { border-color: rgba(var(--mg-accent-rgb), 0.45); }
.mg-layout-option.is-selected { border-color: var(--mg-accent); box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.14); }
.mg-layout-option input { position: absolute; opacity: 0; pointer-events: none; }
.mg-layout-option strong { font-size: 0.88rem; }

.mg-layout-preview {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 66px;
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 10px;
    background: rgba(154, 137, 166, 0.1);
}

.mg-layout-preview span { display: block; height: 6px; border-radius: 3px; background: rgba(154, 137, 166, 0.4); }
.mg-layout-preview span:first-child { width: 46%; background: var(--mg-accent); }
.mg-layout-preview-compact span { height: 4px; }
.mg-layout-preview-letterhead span:first-child { width: 100%; height: 20px; background: rgba(154, 137, 166, 0.18); }

@media (max-width: 1199px) {
    .mg-wizard-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mg-wizard-step-text span { display: none; }
}

/* Chat → wizard handoff card */
.mg-chat-handoff {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.35);
    border-radius: 14px;
    background: rgba(var(--mg-accent-rgb), 0.08);
}

.mg-chat-handoff-facts { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.78rem; color: var(--mg-muted); }
.mg-chat-handoff-facts strong { color: var(--mg-ink); }

.mg-chat-handoff-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
    padding: 8px 15px;
    border: 0;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
    background: var(--mg-accent);
    cursor: pointer;
    transition: background 0.18s ease;
}

.mg-chat-handoff-btn:hover { background: var(--mg-accent-deep); }
.mg-chat-message.is-user .mg-chat-handoff { border-color: rgba(255, 255, 255, 0.4); background: rgba(255, 255, 255, 0.14); }

/* Next-step buttons on a reply: the client clicks instead of typing. */
.mg-chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.mg-chat-action {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.35);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.08);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.mg-chat-action:hover { background: rgba(var(--mg-accent-rgb), 0.16); border-color: var(--mg-accent); }
.mg-chat-action.is-primary { color: #fff; border-color: var(--mg-accent); background: var(--mg-accent); }
.mg-chat-action.is-primary:hover { background: var(--mg-accent-deep, var(--mg-accent)); }
.mg-chat-starters { justify-content: center; margin-top: 18px; }
.mg-chat-action:disabled { opacity: 0.5; cursor: not-allowed; }

/* Language switch in the account menu */
.mg-locale-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    margin-right: 9px;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.12);
}

/* Inline markdown inside chat bubbles */
.mg-chat-text code {
    padding: 1px 5px;
    border-radius: 6px;
    font-size: 0.86em;
    background: rgba(154, 137, 166, 0.16);
}

.mg-chat-message.is-user .mg-chat-text code { background: rgba(255, 255, 255, 0.22); }
.mg-chat-text strong { font-weight: 700; }

/* ── Chat processing state ───────────────────────────────────────── */
.mg-chat-send { position: relative; }

.mg-chat-send.is-busy .mg-chat-send-icon { opacity: 0; }

.mg-chat-spinner {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 17px;
    height: 17px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    opacity: 0;
    animation: mg-chat-spin 0.7s linear infinite;
}

.mg-chat-send.is-busy .mg-chat-spinner { opacity: 1; }

@keyframes mg-chat-spin {
    to { transform: rotate(360deg); }
}

/* "Thinking…" bubble appended while the reply is on its way */
.mg-chat-message.is-pending .mg-chat-bubble { border-style: dashed; }

.mg-chat-pending {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.86rem;
    color: var(--mg-muted);
}

.mg-chat-dots { display: inline-flex; align-items: center; gap: 4px; }

.mg-chat-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mg-accent);
    animation: mg-chat-bounce 1.15s ease-in-out infinite;
}

.mg-chat-dots i:nth-child(2) { animation-delay: 0.15s; }
.mg-chat-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes mg-chat-bounce {
    0%, 70%, 100% { transform: translateY(0); opacity: 0.45; }
    35% { transform: translateY(-5px); opacity: 1; }
}

/* The composer is inert while a reply is in flight */
.mg-chat-composer form.is-busy .mg-chat-input-shell { opacity: 0.65; }
.mg-chat-composer form.is-busy textarea { cursor: progress; }
.mg-chat-prompt:disabled,
.mg-chat-attach:disabled { opacity: 0.45; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
    .mg-chat-spinner { animation-duration: 1.6s; }
    .mg-chat-dots i { animation: none; opacity: 0.7; }
}

/* Banner shown while the OCR service finishes structured extraction */
.mg-chat-processing {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 0 var(--mg-chat-gutter);
    padding: 10px 14px;
    border: 1px solid rgba(246, 192, 0, 0.35);
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--mg-muted);
    background: rgba(246, 192, 0, 0.09);
}

.mg-chat-processing .mg-chat-dots i { background: #f6c000; }

/* OCR actions beside the mode selector */
.mg-chat-ocr-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.mg-chat-ocr-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.35);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.08);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.mg-chat-ocr-btn:hover { background: rgba(var(--mg-accent-rgb), 0.16); border-color: var(--mg-accent); }
.mg-chat-ocr-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mg-chat-ocr-wait { font-size: 0.74rem; color: var(--mg-subtle); }

/* Sidebar group headings */
.mg-menu-group {
    display: block;
    margin: 16px 12px 6px;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--mg-subtle);
}

.mg-menu-list > .mg-menu-group:first-child { margin-top: 4px; }

/* Matching separators on the collapsed icon rail */
.mg-rail-divider {
    display: block;
    width: 22px;
    height: 1px;
    margin: 8px auto;
    background: var(--mg-line);
}

/* Billing plan cards */
.mg-plan-card {
    height: 100%;
    padding: 18px;
    border: 1px solid var(--mg-line);
    border-radius: 16px;
    background: var(--mg-card);
}

.mg-plan-card.is-current { border-color: var(--mg-accent); box-shadow: 0 0 0 3px rgba(var(--mg-accent-rgb), 0.12); }

.mg-plan-features { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }

.mg-plan-features li {
    position: relative;
    padding-left: 20px;
    font-size: 0.8rem;
    color: var(--mg-muted);
}

.mg-plan-features li::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mg-accent);
}

/* Settings tabs */
.mg-settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    background: var(--mg-card);
    width: fit-content;
}

.mg-settings-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 999px;
    font-size: 0.83rem;
    font-weight: 700;
    color: var(--mg-muted);
    text-decoration: none;
    transition: color 0.18s ease, background 0.18s ease;
}

.mg-settings-tab:hover { color: var(--mg-accent); }
.mg-settings-tab.is-active { color: #fff; background: var(--mg-accent); }

/* ---------------------------------------------------------------- inline position editing */

.mg-position-edit > td {
    background: rgba(245, 241, 247, 0.44);
}

.mg-position-inline {
    padding: 18px 16px;
    border-left: 3px solid var(--mg-accent);
}

.mg-position-inline .form-label {
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.mg-position-inline-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.mg-position-inline-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    color: #897e91;
    font-size: 12px;
}

.mg-position-inline-totals strong {
    color: var(--mg-ink);
}

body[data-mg-theme="dark"] .mg-position-edit > td {
    background: rgba(69, 57, 77, 0.5);
}

body[data-mg-theme="dark"] .mg-position-inline-totals {
    color: #ada1b5;
}

.mg-discount-list {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px dashed rgba(127, 109, 140, 0.32);
    border-radius: 10px;
}

.mg-discount-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    color: var(--mg-ink);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.mg-discount-row {
    display: grid;
    grid-template-columns: 150px 130px minmax(0, 1fr) 34px;
    gap: 8px;
    margin-bottom: 8px;
}

body[data-mg-theme="dark"] .mg-discount-list {
    border-color: rgba(241, 236, 245, 0.2);
}

@media (max-width: 860px) {
    .mg-discount-row {
        grid-template-columns: 1fr 1fr;
    }
}

.mg-document-discount {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
    padding: 14px 16px;
    border: 1px dashed rgba(127, 109, 140, 0.32);
    border-radius: 11px;
    background: rgba(245, 241, 247, 0.32);
}

.mg-document-discount-label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--mg-accent);
}

.mg-document-discount-label strong {
    display: block;
    color: var(--mg-ink);
    font-size: 13px;
}

.mg-document-discount-label span {
    color: #897e91;
    font-size: 11.5px;
}

.mg-document-discount-fields {
    display: grid;
    grid-template-columns: 150px 120px minmax(160px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

body[data-mg-theme="dark"] .mg-document-discount {
    border-color: rgba(241, 236, 245, 0.18);
    background: rgba(69, 57, 77, 0.42);
}

body[data-mg-theme="dark"] .mg-document-discount-label span {
    color: #ada1b5;
}

@media (max-width: 900px) {
    .mg-document-discount-fields {
        grid-template-columns: 1fr 1fr;
    }
}

/* ------------------------------------------------- construction catalogue */

.mg-catalogue-results {
    margin-top: 10px;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid rgba(127, 109, 140, 0.28);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
}

.mg-catalogue-result {
    display: block;
    width: 100%;
    padding: 9px 13px;
    border: 0;
    border-bottom: 1px solid rgba(127, 109, 140, 0.14);
    text-align: left;
    background: transparent;
    cursor: pointer;
}

.mg-catalogue-result:last-child { border-bottom: 0; }
.mg-catalogue-result:hover { background: rgba(var(--mg-accent-rgb), 0.09); }

.mg-catalogue-result strong {
    display: block;
    color: var(--mg-ink);
    font-size: 12.5px;
}

.mg-catalogue-result span {
    color: #897e91;
    font-size: 11px;
}

.mg-catalogue-chosen {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.32);
    border-radius: 10px;
    background: rgba(var(--mg-accent-rgb), 0.07);
}

.mg-catalogue-chosen strong {
    display: block;
    color: var(--mg-ink);
    font-size: 13px;
}

.mg-catalogue-chosen span {
    color: #897e91;
    font-size: 11.5px;
}

.mg-catalogue-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 90px 110px 34px;
    gap: 8px;
    margin-bottom: 8px;
}

.mg-catalogue-row.is-detail {
    grid-template-columns: 190px minmax(0, 1fr) 34px;
}

body[data-mg-theme="dark"] .mg-catalogue-results {
    border-color: rgba(241, 236, 245, 0.18);
    background: rgba(59, 49, 66, 0.6);
}

body[data-mg-theme="dark"] .mg-catalogue-result {
    border-bottom-color: rgba(241, 236, 245, 0.1);
}

body[data-mg-theme="dark"] .mg-catalogue-chosen {
    background: rgba(var(--mg-accent-rgb), 0.16);
}

body[data-mg-theme="dark"] .mg-catalogue-result span,
body[data-mg-theme="dark"] .mg-catalogue-chosen span {
    color: #ada1b5;
}

@media (max-width: 900px) {
    .mg-catalogue-row,
    .mg-catalogue-row.is-detail {
        grid-template-columns: 1fr 1fr;
    }
}

/* ------------------------------------------------------------- pagination */

.mg-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.mg-pagination-summary {
    margin: 0;
    color: #897e91;
    font-size: 12px;
}

.mg-pagination-summary strong {
    color: var(--mg-ink);
}

.mg-pagination-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mg-page {
    display: inline-flex;
    min-width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 11px;
    border: 1px solid rgba(127, 109, 140, 0.28);
    border-radius: 9px;
    color: var(--mg-ink);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.55);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

a.mg-page:hover {
    border-color: var(--mg-accent);
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.09);
}

.mg-page.is-current {
    border-color: transparent;
    color: #fff;
    background: var(--mg-accent);
    box-shadow: 0 6px 16px rgba(var(--mg-accent-rgb), 0.28);
}

.mg-page.is-disabled {
    color: #b7aebe;
    background: rgba(255, 255, 255, 0.32);
    cursor: not-allowed;
}

.mg-page.is-gap {
    border-color: transparent;
    background: transparent;
    color: #b7aebe;
}

.mg-page i {
    font-size: 14px;
}

body[data-mg-theme="dark"] .mg-page {
    border-color: rgba(241, 236, 245, 0.16);
    color: #dcd3e3;
    background: rgba(59, 49, 66, 0.54);
}

body[data-mg-theme="dark"] a.mg-page:hover {
    color: #f0ebf3;
    background: rgba(144, 112, 167, 0.35);
}

body[data-mg-theme="dark"] .mg-page.is-current {
    color: #fff;
}

body[data-mg-theme="dark"] .mg-page.is-disabled {
    color: #867a8e;
    background: rgba(59, 49, 66, 0.3);
}

body[data-mg-theme="dark"] .mg-pagination-summary {
    color: #ada1b5;
}

@media (max-width: 600px) {
    .mg-pagination {
        justify-content: center;
    }
}

.mg-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.mg-row-actions form {
    display: inline-flex;
    margin: 0;
}

/* ── Immoni OCR ───────────────────────────────────────────────────
   Fill a tender's prices into its own layout: the upload conversation,
   the run, the two documents side by side, and the price review. */
.mg-ocr { display: flex; flex-direction: column; gap: 18px; }

.mg-ocr-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.mg-ocr-title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--mg-ink);
}

.mg-ocr-sub { margin: 6px 0 0; max-width: 62ch; font-size: 0.86rem; color: var(--mg-muted); }

.mg-ocr-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.3);
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.08);
}

.mg-ocr-panel {
    padding: 20px 22px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 18px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
    box-shadow: var(--mg-card-shadow);
}

.mg-ocr-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.mg-ocr-panel-title {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--mg-ink);
}

.mg-ocr-panel-title i { color: var(--mg-accent); }
.mg-ocr-panel-note { font-size: 0.74rem; color: var(--mg-subtle); }

.mg-ocr-badge {
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.12);
}

/* The conversation that starts the run */
.mg-ocr-thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }

.mg-ocr-bubble {
    max-width: 78%;
    padding: 13px 16px;
    font-size: 0.87rem;
    line-height: 1.6;
}

.mg-ocr-bubble small {
    display: block;
    margin-bottom: 5px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mg-accent);
}

.mg-ocr-bubble.is-assistant {
    border-radius: 4px 16px 16px 16px;
    color: var(--mg-ink);
    background: rgba(var(--mg-accent-rgb), 0.07);
}

.mg-ocr-bubble.is-user {
    align-self: flex-end;
    border-radius: 16px 4px 16px 16px;
    color: #fff;
    background: var(--mg-accent);
}

.mg-ocr-bubble-file {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.76rem;
    background: rgba(255, 255, 255, 0.18);
}

.mg-ocr-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--mg-subtle);
}

.mg-ocr-textarea {
    width: 100%;
    min-height: 76px;
    padding: 12px 14px;
    border: 1px solid var(--mg-line);
    border-radius: 12px;
    font: inherit;
    font-size: 0.87rem;
    color: var(--mg-ink);
    background: rgba(255, 255, 255, 0.72);
    resize: vertical;
}

.mg-ocr-textarea:focus { outline: 2px solid rgba(var(--mg-accent-rgb), 0.35); outline-offset: 1px; }

.mg-ocr-compose-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }

.mg-ocr-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 15px;
    border: 1px dashed rgba(var(--mg-accent-rgb), 0.4);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--mg-accent);
    cursor: pointer;
}

.mg-ocr-file input { display: none; }

.mg-ocr-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--mg-ink);
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.mg-ocr-btn:hover { border-color: var(--mg-accent); }
.mg-ocr-btn.is-primary { border-color: var(--mg-accent); color: #fff; background: var(--mg-accent); }
.mg-ocr-btn.is-primary:hover { background: var(--mg-accent-deep); }
.mg-ocr-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mg-ocr-compose-actions .is-primary { margin-left: auto; }

.mg-ocr-selected { margin: 12px 0 0; font-size: 0.76rem; color: var(--mg-muted); overflow-wrap: anywhere; }
.mg-ocr-error { display: block; margin-top: 6px; font-size: 0.72rem; color: var(--mg-pink); }

/* The five steps */
.mg-ocr-steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }

.mg-ocr-step {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.76rem;
    color: var(--mg-subtle);
}

.mg-ocr-step-dot {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    background: rgba(154, 137, 166, 0.12);
}

.mg-ocr-step.is-active { color: var(--mg-accent); }
.mg-ocr-step.is-active .mg-ocr-step-dot { color: var(--mg-accent); background: rgba(var(--mg-accent-rgb), 0.16); box-shadow: 0 0 0 4px rgba(var(--mg-accent-rgb), 0.08); }
.mg-ocr-step.is-done { color: var(--mg-ink); }
.mg-ocr-step.is-done .mg-ocr-step-dot { color: var(--mg-green); background: rgba(48, 199, 115, 0.16); }

/* The two documents. Paper stays white in both themes — it is paper. */
.mg-ocr-docs { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.mg-ocr-doc { min-width: 0; }

.mg-ocr-doc-label {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 9px;
    font-size: 0.74rem;
    color: var(--mg-muted);
}

.mg-ocr-doc-label b { color: var(--mg-ink); }

.mg-ocr-paper {
    position: relative;
    min-height: 360px;
    padding: 24px 22px;
    overflow: hidden;
    border: 1px solid rgba(154, 137, 166, 0.25);
    border-radius: 6px;
    color: #3b3042;
    background: #fff;
    box-shadow: 0 10px 26px rgba(65, 52, 75, 0.07);
}

.mg-ocr-paper-brand {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 11px;
    border-bottom: 2px solid #493e51;
    font-size: 0.66rem;
    letter-spacing: 0.12em;
}

.mg-ocr-paper-title { margin: 20px 0 0; font-size: 1.05rem; font-weight: 700; color: #392f40; }
.mg-ocr-paper-sub { margin: 4px 0 0; font-size: 0.68rem; color: #89828e; }

.mg-ocr-paper-table { width: 100%; margin-top: 20px; border-collapse: collapse; table-layout: fixed; font-size: 0.68rem; }

.mg-ocr-paper-table th {
    padding: 7px 3px;
    border-bottom: 1px solid #d7d2da;
    font-size: 0.62rem;
    font-weight: 600;
    text-align: right;
    color: #8c8491;
}

.mg-ocr-paper-table th:first-child { width: 42%; text-align: left; }
.mg-ocr-paper-table th:nth-child(2) { width: 18%; }

.mg-ocr-paper-table td {
    padding: 11px 3px;
    border-bottom: 1px solid #eae8ec;
    text-align: right;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}

.mg-ocr-paper-table td:first-child { text-align: left; }
.mg-ocr-paper-table small { display: block; margin-bottom: 3px; font-size: 0.6rem; color: #97909c; }
.mg-ocr-paper-table tr.is-edited { background: rgba(var(--mg-accent-rgb), 0.06); }
.mg-ocr-paper.is-plain .mg-ocr-paper-table tr.is-edited { background: transparent; }

.mg-ocr-field {
    display: block;
    min-height: 17px;
    border-bottom: 1px dotted #c4bec8;
    white-space: nowrap;
    transition: background 0.3s ease, color 0.3s ease;
}

.mg-ocr-paper .mg-ocr-field.is-detected {
    border-bottom-color: transparent;
    border-radius: 3px;
    outline: 1px dashed rgba(var(--mg-accent-rgb), 0.45);
    background: rgba(var(--mg-accent-rgb), 0.05);
}

.mg-ocr-paper .mg-ocr-field.is-filled {
    border-bottom-color: transparent;
    border-radius: 3px;
    outline: 0;
    color: var(--mg-accent-deep);
    background: rgba(var(--mg-accent-rgb), 0.1);
    animation: mg-ocr-pop 0.4s ease-out;
}

.mg-ocr-paper.is-plain .mg-ocr-field { color: #3b3042; background: transparent; outline: 0; }

.mg-ocr-paper-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 18px;
    padding-top: 11px;
    border-top: 1px solid #534a59;
    font-size: 0.74rem;
    font-weight: 700;
}

.mg-ocr-paper-total .mg-ocr-field { min-width: 82px; text-align: right; }

.mg-ocr-paper-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 24px;
    font-size: 0.62rem;
    color: #97919b;
}

.mg-ocr-scan {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--mg-accent);
    box-shadow: 0 -10px 27px 8px rgba(var(--mg-accent-rgb), 0.18);
    animation: mg-ocr-scan 3s linear infinite;
}

.mg-ocr-paper.is-scanning .mg-ocr-scan { display: block; }

/* What the run is doing right now */
.mg-ocr-live { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }

.mg-ocr-live-avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    color: var(--mg-accent);
    background: rgba(var(--mg-accent-rgb), 0.12);
}

.mg-ocr-live-text { flex: 1 1 240px; font-size: 0.85rem; color: var(--mg-ink); }

.mg-ocr-live-text small {
    display: block;
    margin-bottom: 3px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mg-subtle);
}

.mg-ocr-live-actions { display: flex; gap: 8px; }

/* The demo's own chrome: brand bar, intro row, live pulse */
.mg-ocr-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border: 1px solid var(--mg-glass-border);
    border-radius: 16px;
    background: linear-gradient(145deg, var(--mg-card-strong), var(--mg-card));
}

.mg-ocr-brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--mg-ink);
}

.mg-ocr-brand i { color: var(--mg-accent); }

.mg-ocr-intro {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.mg-ocr-intro-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }

.mg-ocr-pulse {
    width: 9px;
    height: 9px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--mg-accent);
    animation: mg-ocr-pulse 1.4s infinite;
}

@keyframes mg-ocr-pulse { 50% { opacity: 0.3; transform: scale(0.7); } }

.mg-ocr-frame-wrap { position: relative; }

.mg-ocr-frame-empty {
    display: grid;
    place-items: center;
    height: 78vh;
    min-height: 520px;
    margin: 0;
    padding: 0 32px;
    border: 1px dashed rgba(154, 137, 166, 0.35);
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.6;
    text-align: center;
    color: var(--mg-muted);
    background: rgba(255, 255, 255, 0.5);
}

/* The document beside the inputs it produced */
.mg-ocr-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }

.mg-ocr-frame {
    width: 100%;
    height: 78vh;
    min-height: 520px;
    border: 1px solid rgba(154, 137, 166, 0.25);
    border-radius: 10px;
    background: #fff;
}

.mg-ocr-sheet {
    max-height: 62vh;
    overflow-y: auto;
    margin: 0 -6px;
    padding: 0 10px 4px 6px;
}

.mg-ocr-chapter + .mg-ocr-chapter { margin-top: 18px; }

.mg-ocr-chapter-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--mg-ink);
    background: rgba(245, 241, 247, 0.94);
    backdrop-filter: blur(6px);
}

.mg-ocr-chapter-total { color: var(--mg-accent); font-variant-numeric: tabular-nums; }

.mg-ocr-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 92px 130px 104px;
    gap: 12px;
    align-items: center;
    padding: 11px 14px;
    border-bottom: 1px solid var(--mg-line);
}

.mg-ocr-line.is-priced { background: rgba(var(--mg-accent-rgb), 0.05); }
.mg-ocr-line.is-invalid { background: rgba(245, 31, 118, 0.06); }
.mg-ocr-line-text { min-width: 0; }
.mg-ocr-line-code { display: block; font-size: 0.72rem; font-weight: 700; color: var(--mg-accent); }
/* The tender's own wording, line breaks included — never shortened. */
.mg-ocr-line-title { display: block; margin-top: 2px; font-size: 0.82rem; color: var(--mg-ink); white-space: pre-line; overflow-wrap: anywhere; }

.mg-ocr-line-group {
    display: block;
    margin-top: 2px;
    font-size: 0.7rem;
    color: var(--mg-subtle);
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.mg-ocr-line-qty { font-size: 0.78rem; text-align: right; color: var(--mg-muted); font-variant-numeric: tabular-nums; }
.mg-ocr-line-cat {
    display: block;
    margin-bottom: 4px;
    overflow: hidden;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--mg-purple);
    text-overflow: ellipsis;
}

.mg-ocr-line-cat i { margin-right: 5px; font-size: 0.72rem; }

.mg-ocr-line-price .mg-ocr-label { margin-bottom: 3px; font-size: 0.62rem; }
.mg-ocr-line-price .mg-ocr-price { padding: 7px 10px; font-size: 0.86rem; }
/* Eine Totalzeile der Ausschreibung: gerechnet, nicht ausgefüllt. */
.mg-ocr-total {
    grid-template-columns: minmax(0, 1fr) auto;
    background: var(--mg-card-strong);
}

.mg-ocr-total .mg-ocr-line-code { color: var(--mg-ink); text-transform: uppercase; letter-spacing: 0.04em; }
.mg-ocr-total .mg-ocr-line-title { font-weight: 700; }
.mg-ocr-total .mg-ocr-line-amount { font-size: 1rem; font-weight: 700; color: var(--mg-accent); }
.mg-ocr-total.is-open .mg-ocr-line-amount { color: var(--mg-muted); }

.mg-ocr-line-amount { text-align: right; font-size: 0.86rem; color: var(--mg-ink); font-variant-numeric: tabular-nums; }
.mg-ocr-line-amount .mg-ocr-label { margin-bottom: 3px; font-size: 0.62rem; text-align: right; }

.mg-ocr-tab {
    padding: 3px 10px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    margin-right: 5px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--mg-muted);
    background: transparent;
    cursor: pointer;
}

.mg-ocr-tab.is-active { color: #fff; border-color: var(--mg-accent); background: var(--mg-accent); }

.mg-ocr-empty { margin: 18px 4px; font-size: 0.84rem; line-height: 1.6; color: var(--mg-muted); }

.mg-ocr-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; padding: 12px 14px; }

.mg-ocr-field-row { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.mg-ocr-field-label {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--mg-ink);
}

.mg-ocr-field-label em { font-size: 0.68rem; font-style: normal; color: var(--mg-subtle); }
.mg-ocr-price.is-text { text-align: left; font-size: 0.82rem; }

/* Abzüge und MWST: the rows under the positions that turn their sum into
   what the client pays. */
.mg-ocr-sum { display: grid; gap: 2px; padding: 10px 14px 14px; }

.mg-ocr-sum-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px 140px;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--mg-line);
}

.mg-ocr-sum-row:last-of-type { border-bottom: 0; }

.mg-ocr-sum-label { font-size: 0.8rem; font-weight: 600; color: var(--mg-ink); }
.mg-ocr-sum-control { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.mg-ocr-sum-input { max-width: 96px; }
.mg-ocr-sum-unit { font-size: 0.76rem; color: var(--mg-muted); }
.mg-ocr-sum-fixed { font-size: 0.8rem; font-weight: 600; color: var(--mg-ink); }
.mg-ocr-sum-label em { display: block; font-size: 0.68rem; font-style: normal; font-weight: 500; color: var(--mg-subtle); }

.mg-ocr-sum-value {
    font-size: 0.9rem;
    font-weight: 700;
    text-align: right;
    color: var(--mg-ink);
    font-variant-numeric: tabular-nums;
}

/* The two totals stand out from the deductions between them. */
.mg-ocr-sum-row[data-mg-ocr-sum-row="net"],
.mg-ocr-sum-row[data-mg-ocr-sum-row="total"] {
    border-top: 1px solid var(--mg-line);
    border-bottom: 0;
}

.mg-ocr-sum-row[data-mg-ocr-sum-row="total"] .mg-ocr-sum-label,
.mg-ocr-sum-row[data-mg-ocr-sum-row="total"] .mg-ocr-sum-value {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--mg-accent);
}

.mg-ocr-editor-gross strong { color: var(--mg-accent); }

@media (max-width: 700px) {
    .mg-ocr-sum-row { grid-template-columns: minmax(0, 1fr) 110px; }
    .mg-ocr-sum-label { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
    .mg-ocr-fields { grid-template-columns: 1fr; }
}

.mg-ocr-search {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
}

.mg-ocr-search input { width: 150px; border: 0; background: none; font: inherit; font-size: 0.78rem; color: var(--mg-ink); outline: 0; }
.mg-ocr-search i { color: var(--mg-subtle); }

.mg-ocr-summary {
    position: sticky;
    bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

@media (max-width: 1200px) {
    .mg-ocr-docs { grid-template-columns: 1fr; }
    .mg-ocr-frame, .mg-ocr-frame-empty { height: 60vh; min-height: 0; }
    .mg-ocr-sheet { max-height: none; }
}

@media (max-width: 700px) {
    .mg-ocr-line { grid-template-columns: minmax(0, 1fr) 110px; }
    .mg-ocr-line-text { grid-column: 1 / -1; }
    .mg-ocr-search input { width: 110px; }
}

/* The price review */
.mg-ocr-editor-hint { margin: 0 0 14px; font-size: 0.78rem; color: var(--mg-muted); }

.mg-ocr-editor-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 190px 150px;
    gap: 16px;
    align-items: start;
    padding: 15px 0;
    border-top: 1px solid var(--mg-line);
}

.mg-ocr-editor-name { display: block; font-size: 0.88rem; font-weight: 700; color: var(--mg-ink); }
.mg-ocr-editor-meta { display: block; margin-top: 3px; font-size: 0.74rem; color: var(--mg-muted); }

.mg-ocr-price {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid rgba(var(--mg-accent-rgb), 0.35);
    border-radius: 10px;
    font: inherit;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--mg-accent-deep);
    background: rgba(255, 255, 255, 0.78);
}

.mg-ocr-price[aria-invalid="true"] { border-color: var(--mg-pink); background: rgba(245, 31, 118, 0.06); }
.mg-ocr-price:disabled { opacity: 0.7; }

.mg-ocr-editor-row .mg-ocr-editor-hint { margin: 6px 0 0; font-size: 0.72rem; }
.mg-ocr-editor-amount { text-align: right; font-size: 0.95rem; font-variant-numeric: tabular-nums; color: var(--mg-ink); }
.mg-ocr-editor-amount .mg-ocr-label { text-align: right; }

.mg-ocr-editor-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 4px;
    padding-top: 16px;
    border-top: 1px solid var(--mg-line);
}

.mg-ocr-editor-total small { display: block; font-size: 0.7rem; color: var(--mg-muted); }
.mg-ocr-editor-total strong { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; color: var(--mg-ink); }
.mg-ocr-editor-change { display: block; margin-top: 3px; font-size: 0.72rem; color: var(--mg-accent); }

.mg-ocr-review {
    padding: 13px 16px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #1c6b57;
    background: rgba(48, 199, 115, 0.12);
}

.mg-ocr-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.74rem;
    color: var(--mg-muted);
}

.mg-ocr-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.mg-ocr-toggle input { width: 15px; height: 15px; accent-color: var(--mg-accent); }

.mg-ocr.is-paused *, .mg-ocr.is-paused *::after { animation-play-state: paused !important; }
.mg-ocr [hidden] { display: none !important; }

@keyframes mg-ocr-scan { from { top: 0; } to { top: 100%; } }
@keyframes mg-ocr-pop { from { transform: translateY(4px); opacity: 0.3; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 1100px) {
    .mg-ocr-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .mg-ocr-editor-row { grid-template-columns: minmax(0, 1fr) 150px; }
    .mg-ocr-editor-row > div:first-child { grid-column: 1 / -1; }
    /* A price field is a number, not a paragraph — keep it that width. */
    .mg-ocr-editor-row > div:nth-child(2) { width: 100%; max-width: 220px; }
}

@media (max-width: 860px) {
    .mg-ocr-docs { grid-template-columns: 1fr; }
    .mg-ocr-steps { grid-template-columns: 1fr 1fr; }
    .mg-ocr-bubble { max-width: 100%; }
    .mg-ocr-compose-actions .is-primary { margin-left: 0; }
}

body[data-mg-theme="dark"] .mg-ocr-textarea,
body[data-mg-theme="dark"] .mg-ocr-price,
body[data-mg-theme="dark"] .mg-ocr-btn { background: rgba(255, 255, 255, 0.06); }

body[data-mg-theme="dark"] .mg-ocr-btn.is-primary { background: var(--mg-accent); color: #fff; }
body[data-mg-theme="dark"] .mg-ocr-review { color: #8ff0c4; }
body[data-mg-theme="dark"] .mg-ocr-frame-empty { background: rgba(255, 255, 255, 0.04); }

/* The accent reads as ink on light surfaces and disappears on dark ones. */
body[data-mg-theme="dark"] .mg-ocr-price { color: #e2d9e9; border-color: rgba(205, 188, 217, 0.38); }
body[data-mg-theme="dark"] .mg-ocr-price:disabled { opacity: 1; color: #d2c2dd; }
body[data-mg-theme="dark"] .mg-ocr-editor-change,
body[data-mg-theme="dark"] .mg-ocr-file,
body[data-mg-theme="dark"] .mg-ocr-chip,
body[data-mg-theme="dark"] .mg-ocr-badge,
body[data-mg-theme="dark"] .mg-ocr-panel-title i { color: #dbcee4; }

/* Shared Metronic controls use the same palette as the custom admin components. */
body.mg-admin-body {
    --bs-primary: var(--mg-accent);
    --bs-primary-rgb: var(--mg-accent-rgb);
    --bs-primary-active: var(--mg-accent-deep);
    --bs-primary-light: rgba(var(--mg-accent-rgb), 0.08);
    --bs-primary-inverse: #fff;
    --bs-text-primary: var(--mg-accent);
    --bs-link-color: var(--mg-accent);
    --bs-link-color-rgb: var(--mg-accent-rgb);
    --bs-link-hover-color: var(--mg-accent-deep);
    --bs-link-hover-color-rgb: var(--mg-accent-rgb);
    --bs-success: #288064;
    --bs-success-rgb: 40, 128, 100;
    --bs-success-active: #20664f;
    --bs-success-light: rgba(40, 128, 100, 0.1);
    --bs-text-success: #288064;
    --bs-danger: #b44464;
    --bs-danger-rgb: 180, 68, 100;
    --bs-danger-active: #983953;
    --bs-danger-light: rgba(180, 68, 100, 0.1);
    --bs-text-danger: #b44464;
    --bs-info: #8866a6;
    --bs-info-rgb: 136, 102, 166;
    --bs-info-active: #70518b;
    --bs-info-light: rgba(136, 102, 166, 0.1);
    --bs-text-info: #8866a6;
    --bs-warning: #a36d20;
    --bs-warning-rgb: 163, 109, 32;
    --bs-warning-active: #855818;
    --bs-warning-light: rgba(163, 109, 32, 0.1);
    --bs-text-warning: #a36d20;
}

body.mg-admin-body .btn-primary {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--mg-accent);
    --bs-btn-border-color: var(--mg-accent);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--mg-accent-deep);
    --bs-btn-hover-border-color: var(--mg-accent-deep);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--mg-accent-deep);
    --bs-btn-active-border-color: var(--mg-accent-deep);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--mg-accent);
    --bs-btn-disabled-border-color: var(--mg-accent);
    --bs-btn-focus-shadow-rgb: var(--mg-accent-rgb);
    color: #fff;
    background: var(--mg-accent);
    border-color: var(--mg-accent);
}

body.mg-admin-body .btn-primary:is(:hover, :active, :focus-visible),
.mg-ops-action.is-primary:hover {
    background: var(--mg-accent-deep);
    border-color: var(--mg-accent-deep);
}

body.mg-admin-body :is(a, button, input, select, textarea):focus-visible {
    outline: 2px solid var(--mg-accent);
    outline-offset: 3px;
}

body.mg-admin-body[data-mg-theme="dark"] {
    --bs-text-primary: #d9bfea;
    --bs-link-color: #d9bfea;
    --bs-link-hover-color: #eadbf3;
    --bs-text-success: #85cdb3;
    --bs-text-danger: #f0a2b9;
    --bs-text-warning: #e6bd7d;
    --bs-text-info: #cbb1e0;
}

body[data-mg-theme="dark"] :is(.mg-ops-eyebrow, .mg-ops-card-kicker, .mg-ops-card-icon, .mg-ring-value, .mg-chat-attach, .mg-ocr-step.is-active .mg-ocr-step-dot) {
    color: #d9bfea;
}

body.mg-admin-body {
    --bs-heading-color: var(--mg-ink);
}

body[data-mg-theme="dark"] .badge-light-primary,
body[data-mg-theme="dark"] .btn.btn-light-primary {
    color: var(--bs-text-primary);
}

body[data-mg-theme="dark"] .badge-light-success { color: var(--bs-text-success); }
body[data-mg-theme="dark"] .badge-light-warning { color: var(--bs-text-warning); }
body[data-mg-theme="dark"] .badge-light-danger { color: var(--bs-text-danger); }
body[data-mg-theme="dark"] .badge-light-info { color: var(--bs-text-info); }
body[data-mg-theme="dark"] .table th { color: var(--mg-muted); }

body[data-mg-theme="dark"] .mg-page-content,
body[data-mg-theme="dark"] .mg-page-content .card {
    box-shadow: var(--mg-card-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

body[data-mg-theme="dark"] .mg-ops-action.is-primary {
    background: var(--mg-accent);
}

body[data-mg-theme="dark"] .mg-ops-action.is-primary:hover {
    background: var(--mg-accent-deep);
}
