/* Shared Magilex UI components. Existing .button, .pricing-button, .panel, .form-card
   and heading classes are the reusable component hooks; domain classes are aliases.
   ui-system.css supplies font/spacing foundations. View-specific layouts and illustrations
   stay in brand-interface.css. Paper/export typography remains independent. */

/* Theme tokens */
:root {
    --mx-paper: #f7faf7;
    --mx-card: #fcfefd;
    --mx-line: #d7e4dc;
    --mx-radius: 24px;
    --mx-radius-small: 16px;
    --mx-card-title-size: 22px;
    --mx-control-radius: 14px;
    --mx-shadow: 0 10px 28px #264c3e12;
    --mx-shadow-hover: 0 14px 32px #264c3e1d;
    --mx-gradient: linear-gradient(110deg, #00777b, #205c86);
    --mx-action-line: var(--mx-button-line);
    --mx-action-hover: #fff7f0;
    --mx-action-selected: #fff1e5;
    --mx-action-ink: #325b5b;
    --mx-action-focus: var(--mx-button-focus);
    /* Change this one accent to recolor filled actions and their emphasis lines. */
    --mx-action-color: #fff4cf;
    --mx-button-fill: var(--mx-action-color);
    --mx-button-fill-hover: color-mix(in srgb, var(--mx-action-color) 94%, black);
    --mx-button-line: color-mix(in srgb, var(--mx-action-color) 82%, black);
    --mx-button-line-hover: color-mix(in srgb, var(--mx-action-color) 72%, black);
    --mx-button-soft: color-mix(in srgb, var(--mx-action-color) 30%, white);
    --mx-button-ink: var(--ui-ink);
    --mx-button-focus: color-mix(in srgb, var(--mx-action-color) 45%, black);
    --mx-highlight-line: var(--mx-button-line);
    --mx-button-shadow: 0 3px 10px color-mix(in srgb, var(--mx-button-line) 10%, transparent);
}
@media screen {
    body[data-interface="magilex"] {
        --ui-radius: var(--mx-radius-small);
    }
    :root {
        --mx-control-radius: 999px;
    }
    body[data-interface="magilex"].workspace {
        --mx-paper: #e7f0f3;
        --mx-card: #fff;
        --mx-line: #c7d4da;
        --mx-shadow: 0 12px 24px #29344818;
        --mx-shadow-hover: 0 14px 28px #29344826;
        --mx-action-line: var(--mx-button-line);
        --mx-action-ink: #24676c;
        --mx-action-hover: #dceef0;
        --mx-action-selected: #d2e9e9;
        --line: #c7d4da;
        --soft: #edf5f7;
        --workspace-selection-bg: #d2e9e9;
        --workspace-selection-text: #235c61;
    }
}

/* Buttons: shared colors also cover domain-specific action hooks. Navigation,
   field selection and status colors use the separate mx-action tokens. */
@media screen {
    body[data-interface="magilex"] :is(.button, .pricing-button, .ms-button) {
        border-radius: 999px;
        min-height: 46px;
        white-space: normal;
        text-align: center;
        line-height: 1.4;
        transition: background .16s, box-shadow .16s, border-color .16s;
    }
    body[data-interface="magilex"] :is(.button, .pricing-button, .assistant-launcher, .file-upload-button, .back-to-top, .nav-account),
    body[data-interface="magilex"].workspace :is(.button, .pricing-button),
    body[data-interface="magilex"] #magilex-studio :is(.ms-button, .ms-choice) {
        border: 1px solid var(--mx-button-line);
        background: var(--mx-card);
        color: var(--mx-button-ink);
        box-shadow: none;
    }
    body[data-interface="magilex"] :is(.button, .pricing-button, .assistant-launcher, .file-upload-button, .back-to-top, .nav-account):hover,
    body[data-interface="magilex"].workspace :is(.button, .pricing-button):hover,
    body[data-interface="magilex"] #magilex-studio :is(.ms-button, .ms-choice):hover {
        border-color: var(--mx-button-line-hover);
        background: var(--mx-button-soft);
        color: var(--mx-button-ink);
        box-shadow: 0 3px 10px #8a6b2512;
    }
    body[data-interface="magilex"] :is(.button.primary, .button.lime, .pricing-button-primary, .radar-search-submit, .assistant-send, .workspace-create-menu>summary, .card-link, .tool-card-action, .radar-card-read),
    body[data-interface="magilex"].workspace :is(.button.primary, .button.lime, .pricing-button-primary),
    body[data-interface="magilex"] #magilex-studio :is(.ms-button:not(.ms-outline), .ms-query button) {
        border: 1px solid var(--mx-button-line);
        background: var(--mx-button-fill);
        color: var(--mx-button-ink);
        box-shadow: var(--mx-button-shadow);
    }
    body[data-interface="magilex"] :is(.button.primary, .button.lime, .pricing-button-primary, .radar-search-submit, .assistant-send, .workspace-create-menu>summary, .card-link, .tool-card-action, .radar-card-read):hover,
    body[data-interface="magilex"].workspace :is(.button.primary, .button.lime, .pricing-button-primary):hover,
    body[data-interface="magilex"] #magilex-studio :is(.ms-button:not(.ms-outline), .ms-query button):hover {
        background: var(--mx-button-fill-hover);
        border-color: var(--mx-button-line-hover);
        color: var(--mx-button-ink);
    }
    body[data-interface="magilex"] :is(.button, .pricing-button, .ms-button, .assistant-send):disabled,
    body[data-interface="magilex"].workspace :is(.button, .pricing-button):disabled {
        opacity: 1;
        color: var(--ui-muted);
        cursor: not-allowed;
        box-shadow: none;
    }
    body[data-interface="magilex"] :is(.button, .pricing-button) svg {
        flex: none;
    }
}
@media (prefers-reduced-motion: reduce) {
    body[data-interface="magilex"] :is(.button, .pricing-button, .ms-button) {
        transition: none;
    }
}

/* Form controls and focus */
@media screen {
    [data-interface="magilex"] :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]):not([type=color]):not([type=file]), select) {
        border-radius: var(--mx-control-radius);
        border-color: #c4d7cd;
    }
    [data-interface="magilex"] :is(input, select, textarea)[aria-invalid="true"] {
        border-color: #a33329;
    }
    [data-interface="magilex"] :is(input[type=checkbox], input[type=radio]) {
        accent-color: var(--mx-action-focus);
    }
    body[data-interface="magilex"] :is(a, button, input, select, textarea, summary):focus-visible {
        outline: 2px solid var(--mx-button-focus);
        outline-offset: 3px;
    }
    [data-interface="magilex"] textarea {
        border-radius: var(--mx-radius-small);
    }
    [data-interface="magilex"] textarea,
        [data-interface="magilex"] input[type="file"] {
        border-radius: 12px;
    }
    body[data-interface="magilex"].workspace :is(a, button, summary, input, select, textarea):focus-visible {
        outline: 3px solid var(--mx-button-focus);
        outline-offset: 3px;
    }
    body[data-interface="magilex"].workspace :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]):not([type=color]), select, textarea) {
        border-color: #b7cdd4;
        background-color: #fff;
    }
    body[data-interface="magilex"].workspace textarea,
        body[data-interface="magilex"].workspace input[type=file] {
        border-radius: 12px;
    }
    body[data-interface="magilex"].workspace :is(input, select, textarea)[aria-invalid="true"] {
        border-color: #a33329;
    }
    body[data-interface="magilex"].workspace :is(input[type=radio], input[type=checkbox]) {
        accent-color: #137c80;
    }
}
@media screen and (max-width:780px) {
    body[data-interface="magilex"] #main-content :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]):not([type=file]), select, textarea) {
        font-family: var(--ui-font);
        font-size: 16px;
    }
}

/* Cards and panels */
@media screen {
    [data-interface="magilex"] :is(.card, .form-card, .panel, .plan-card, .pricing-card, .purchase-card, .tool-card, .path-card, .document-info-card, .preview-card, .portal-health-card, .service-offer-card, .request-state-card, .request-original, .request-update, .account-profile-card, .account-preferences, .auth-card, .interest-panel, .case-search, .case-result, .case-ai, .consultation-option, .radar-source, .radar-empty) {
        border-radius: var(--mx-radius);
        border-color: var(--mx-line);
        box-shadow: var(--mx-shadow);
    }
    [data-interface="magilex"] :is(a.card, .tool-card, .path-card):hover {
        box-shadow: var(--mx-shadow-hover);
        border-color: var(--mx-highlight-line);
    }
    [data-interface="magilex"] :is(.card, .tool-card, .pricing-card, .portal-health-card, .radar-source) {
        background-color: var(--mx-card);
        background-image: url('/assets/radar-card-warmth.svg');
        background-repeat: no-repeat;
        background-position: right top;
        background-size: 175px auto;
    }
    [data-interface="magilex"] :is(.form-card, .panel, .auth-card, .interest-panel, .account-profile-card) {
        background-color: var(--mx-card);
    }
    [data-interface="magilex"] .pricing-card-featured {
        border-color: var(--mx-button-line);
        background-color: #edf6f3;
    }
    [data-interface="magilex"] :is(.card, .tool-card, .pricing-card, .path-card)>:is(h2,h3) {
        overflow-wrap: anywhere;
        hyphens: auto;
    }
    body[data-interface="magilex"].workspace :is(.card, .panel, .form-card, .tool-card, .account-profile-card, .account-preferences, .account-service, .account-empty, .purchase-empty, .account-history, .notification-card, .notification-settings, .notification-empty, .reminder-row, .case-search, .case-result, .case-empty, .case-conversation, .consultation-package, .consultation-request, .booking-calendar, .booking-details, .interest-panel, .request-state-card, .request-next-step, .request-update, .document-info-card, .document-preview, .preview-section, .service-option, .portal-health-card) {
        background-color: #fff;
        border: 1px solid #c7d4da;
        border-radius: 24px;
        box-shadow: var(--mx-shadow);
    }
    body[data-interface="magilex"].workspace :is(.card, .tool-card, .document-info-card, .account-service, .consultation-package, .service-option, .portal-health-card) {
        background-image: url('/assets/dashboard-card-flow.svg');
        background-repeat: no-repeat;
        background-position: right top;
        background-size: 140px auto;
    }
    body[data-interface="magilex"].workspace :is(a.card, .tool-card, .account-service):hover {
        border-color: var(--mx-highlight-line);
    }
    body[data-interface="magilex"].workspace .account-preferences+.account-preferences {
        margin-top: 20px;
    }
}

/* Page headings: archive, tool and workspace variants share one typography definition. */
@media screen {
    [data-interface="magilex"] :is(.page-heading, .article-content, .auth-layout, .document-heading, .builder-heading, .overview-hero)>h1 { overflow-wrap:anywhere; hyphens:auto; }
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title) h1 {
        display:flex; align-items:center; gap:12px; margin:0;
        font-family:var(--ui-font); font-weight:700; font-size:clamp(40px, 4vw, 56px); line-height:1.15;
    }
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title) h1>svg { flex:none; width:44px; height:44px; }
    [data-interface="magilex"] .radar-archive-title h1>svg { color:#00777b; }
    [data-interface="magilex"] .service-archive-title h1>svg { color:var(--service-accent, #405f9c); }
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title)>p { margin:9px 0 0; color:#436b68; font-size:20px; line-height:1.45; }
    [data-interface="magilex"] .service-archive-title h1 { max-width:none; text-wrap:balance; }
    [data-interface="magilex"] .service-archive-title h1>span { min-width:0; }
    [data-interface="magilex"] .service-archive-title>p { max-width:760px; }
    [data-interface="magilex"] .tool-heading .service-archive-title h1 { font-size:clamp(40px, 4vw, 56px); margin:0; overflow-wrap:normal; }
    body[data-interface="magilex"].workspace :is(.page-heading, .builder-heading, .builder-saved-heading, .request-heading, .consultation-heading, .document-heading, .purchase-result, .radar-archive-title) h1 {
        font-family:var(--ui-font); font-weight:700; font-size:clamp(30px, 2.4vw, 40px); line-height:1.2; letter-spacing:-.035em;
    }
    body[data-interface="magilex"].workspace :is(.service-archive-title, .radar-archive-title) h1>svg { width:32px; height:32px; }
    body[data-interface="magilex"].workspace :is(.service-archive-title, .radar-archive-title)>p { font-size:17px; line-height:1.55; }
}
@media screen and (max-width:700px) {
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title) h1 { font-size:40px; }
    [data-interface="magilex"] .service-archive-title h1 { gap:9px; }
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title) h1>svg { width:34px; height:34px; }
    [data-interface="magilex"] :is(.radar-archive-title, .service-archive-title)>p { font-size:17px; }
    [data-interface="magilex"] .library-heading .service-archive-title h1,
    [data-interface="magilex"] .tool-heading .service-archive-title h1 { font-size:clamp(28px, 8vw, 40px); }
}



/* Optional information */
@media screen {
    [data-interface="magilex"] .interface-help {
        margin: 18px 0;
        border-top: 1px solid var(--mx-line);
        padding-top: 14px;
        color: var(--ui-muted);
        font-size: 13px;
        line-height: 1.65;
    }
    [data-interface="magilex"] .interface-help>summary {
        cursor: pointer;
        color: var(--ui-ink);
        font-weight: 700;
        min-height: 32px;
    }
    [data-interface="magilex"] .interface-help>p {
        font-size: 13px;
        line-height: 1.65;
    }
    [data-interface="magilex"] .interface-help .steps {
        margin-top: 12px;
    }
}

/* Floating controls and navigation icons */
svg.ui-chevron {
    display: inline-block;
    width: 18px;
    height: 18px;
    flex: none;
    vertical-align: -.2em;
    pointer-events: none;
}
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 85;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border: 1px solid #a2c5cc;
    border-radius: 50%;
    background: #fff;
    color: #006c75;
    box-shadow: 0 6px 22px #24475921;
    cursor: pointer;
    transition: background .15s,box-shadow .15s;
}
.back-to-top[hidden] {
    display: none!important;
}
.back-to-top:hover {
    background: #e6f3f4;
    box-shadow: 0 8px 24px #2447592a;
}
.back-to-top:focus-visible {
    outline: 3px solid var(--mx-button-focus);
    outline-offset: 4px;
}
.back-to-top svg {
    pointer-events: none;
    flex: none;
}
.back-to-top--above-assistant {
    bottom: 92px;
}
@media(max-width:760px) {
    .back-to-top {
        right: 16px;
        bottom: 18px;
        width: 44px;
        height: 44px;
        min-height: 44px;
    }
    .back-to-top--above-assistant {
        bottom: 86px;
    }
}
@media(prefers-reduced-motion:reduce) {
    .back-to-top {
        transition: none;
    }
}
@media print {
    .back-to-top {
        display: none!important;
    }
}
@media screen and (max-width:780px) {
    [data-interface="magilex"] .assistant-launcher {
        width: 48px;
        height: 48px;
        padding: 0;
        gap: 0;
        justify-content: center;
        border-radius: 50%;
    }
    [data-interface="magilex"] .assistant-launcher>span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* Interactive cards keep their service colors; gold marks interaction. */
@media screen {
    body[data-interface="magilex"] :is(a.card, a.tool-card, a.path-card, a.account-service, a.account-shortcut, .account-create>a):is(:hover, :focus-visible) {
        border-color: var(--mx-highlight-line);
    }
    body[data-interface="magilex"] :is(.button, .pricing-button, .assistant-launcher, .assistant-send, .radar-search-submit, .workspace-create-menu>summary, .back-to-top, .nav-account, a.card, a.tool-card, a.path-card, a.account-service, a.account-shortcut, .account-create>a):focus-visible,
    body[data-interface="magilex"] #magilex-studio :is(.ms-button, .ms-choice, .ms-query button, .ms-solution-link):focus-visible {
        outline: 3px solid var(--mx-button-focus);
        outline-offset: 4px;
    }
}

/* Filter, disclosure and selection emphasis shares the action palette. */
@media screen {
    body[data-interface="magilex"] :is(.radar-public-topic-menu, .radar-filter-menu, .radar-share, .case-result-filters)>summary,
    body[data-interface="magilex"] .section-navigation-toggle {
        border: 1px solid var(--mx-button-line);
        background: var(--mx-card);
        color: var(--mx-button-ink);
        box-shadow: none;
    }
    body[data-interface="magilex"] :is(.radar-public-topic-menu, .radar-filter-menu, .radar-share, .case-result-filters)>summary:hover,
    body[data-interface="magilex"] :is(.radar-public-topic-menu, .radar-filter-menu, .radar-share, .case-result-filters)[open]>summary,
    body[data-interface="magilex"] .section-navigation-toggle:hover {
        border-color: var(--mx-button-line-hover);
        background: var(--mx-button-soft);
    }
    body[data-interface="magilex"] :is(.radar-searchbox, .file-upload-control, .vault-dropzone):focus-within,
    body[data-interface="magilex"] .consultation-package:has(input:focus-visible) {
        outline-color: var(--mx-button-focus);
    }
    body[data-interface="magilex"] .assistant-composer:focus-within {
        border-color: var(--mx-button-line);
        box-shadow: 0 0 0 2px color-mix(in srgb, var(--mx-highlight-line) 15%, transparent);
    }
    body[data-interface="magilex"] .interest-mode-buttons input:focus-visible+span {
        outline-color: var(--mx-button-focus);
    }
}

@media screen {
    body[data-interface="magilex"] .header nav a[aria-current=page] {
        text-decoration-color: var(--mx-button-line);
    }
}

/* A card remains one link; its action label uses the shared primary appearance. */
@media screen {
    body[data-interface="magilex"] :is(.card-link, .tool-card-action, .radar-card-read) {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        align-self: flex-start;
        gap: 8px;
        width: fit-content;
        min-height: 44px;
        padding: 8px 14px;
        border-radius: 999px;
        font-size: 14px;
        font-weight: 700;
        line-height: 1.4;
    }
    body[data-interface="magilex"] :is(.guide-introduction h3, .guide-instructions .card>h2) {
        font-family: var(--ui-font);
        font-size: var(--mx-card-title-size);
        font-weight: 700;
        line-height: 1.3;
        margin: 22px 0 14px;
        overflow-wrap: normal;
        hyphens: auto;
    }
}

@media screen {
    .guest-locked-action { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-block: 10px; }
    .guest-locked-action .text-link { font-size: 12px; }
    .guest-locked-fields { min-width: 0; padding: 0; margin: 0; border: 0; }
    .guest-locked-fields:disabled :is(input, textarea, select) { cursor: not-allowed; background: #f1f4f4; color: var(--ui-muted); }
}

/* Quiet reading labels inside a card that is already one complete link. */
@media screen {
    body[data-interface="magilex"] .card-text-link {
        display: inline-flex; align-items: center; align-self: flex-start; gap: 8px;
        margin-top: auto; padding: 18px 0 0; color: var(--mx-action-ink);
        font-size: 14px; font-weight: 600; line-height: 1.4;
    }
    body[data-interface="magilex"] .card:hover .card-text-link { text-decoration: underline; text-underline-offset: 4px; }
    body[data-interface="magilex"] .pricing-feature-note { font-size: 13px; line-height: 1.65; margin: 0 0 24px; }
}
