/* =============================================================================
   LOGIN VARIABLES
   This block is a standalone copy of tokens from _variables.css — required because
   the login page is served as an isolated bundle (no core.css). Keep in sync with
   _variables.css when updating: font sizes, font weights, colors, borders, shadows.
   ============================================================================= */
:root {
    --input-height: 36px;

    --font-family-default: 'Inter', Arial, sans-serif;

    --border-primary: #D0D2D5;
    --border-secondary: #E2E4E5;

    --text-primary: #181D27;
    --text-secondary: #414651;
    --text-tertiary: #535862;
    --font-size-sm: 14px;
    --font-size-md: 16px;

    /* Inter variable font optical sizes — must match _variables.css */
    --font-weight-semibold: 590;
    --font-weight-medium: 490;
    --font-weight-regular: 390;

    --shadow-underline-2: 0px -2px 0px 0px #0a0d1215 inset;
    --shadow-xs: 0px 1px 2px 0px #0A0D120D;

    --border-shadow-tertiary: 0px 0px 0px 1px var(--border-secondary);
    --border-shadow-secondary: 0px 0px 0px 1px color-mix(in srgb, var(--border-primary), var(--border-secondary) 50%);
    --border-shadow-primary: 0px 0px 0px 1px var(--border-primary);

    --theme-color-600: #669F2A;

    --error-600: #D92D20;
}

/* =============================================================================
       LOGIN BASE
       ============================================================================= */
html,
body {
    font-family: var(--font-family-default);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-regular);
    font-feature-settings: "liga", "calt";
    margin: 0;
    overflow: hidden;
    color: var(--text-secondary);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    scrollbar-width: none !important;

    &:has(#connection-error.error) {
        pointer-events: none;
    }
}

html {
    overflow: hidden;
    min-width: 500px;
    min-height: 500px;
}

/* =============================================================================
       LOAD OVERLAY
       ============================================================================= */
#load-overlay {
    position: absolute;
    inset: 0px;
    background-color: #ececec;
    opacity: 1;
    z-index: 50;
    overflow: hidden;
    display: block;
    transition: 200ms;
}

#connection-error-overlay {
    display: none;
    position: absolute;
    inset: 0px;
    background-color: #000000b3;
    opacity: 1;
    z-index: 999999;
    overflow: hidden;

    > i {
        margin: auto;
        font-size: 78px;
        color: #efcaca;
        opacity: 0.7;
    }

    &.visible {
        display: flex;

        > i {
            animation: connection-error-animation 6s infinite 1s ease-in-out, connection-error-color-transition 90s 1s forwards;
        }
    }
}

@keyframes connection-error-animation {
    0% {
        opacity: 0.7;
    }

    20% {
        opacity: 1;
        transform: rotate(0deg);
    }

    23% {
        transform: rotate(7deg);
    }

    26% {
        transform: rotate(-7deg);
    }

    29% {
        transform: rotate(12deg);
    }

    32% {
        transform: rotate(-7deg);
    }

    36% {
        opacity: 1;
        transform: rotate(0deg);
    }

    51% {
        opacity: 0.7;
    }
}

@keyframes connection-error-color-transition {
    0% {
        color: #efcaca;
    }

    100% {
        color: #FF0000;
    }
}

#login {
    background-color: #ffffff;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    z-index: 90;
    display: none;
    overflow: hidden;
    opacity: 0;

    /* =============================================================================
           FORM ELEMENTS
           ============================================================================= */
    input {
        box-sizing: border-box !important;
        border: none !important;
        color: var(--text-primary);
        font-size: var(--font-size-sm);
        font-family: 'Inter', Arial, sans-serif;
        height: var(--input-height);
        padding: 6px 5px 6px 12px;
        background: white;
        border-radius: 8px;
        box-shadow: var(--shadow-xs), var(--border-shadow-secondary) inset;
    }

    input.large {
        height: 44px;
        font-size: var(--font-size-md);
    }

    :focus-visible {
        outline: var(--theme-color-600) 2px solid !important;
        outline-offset: 2px;
    }

    input[type=text]:focus-visible,
    input[type=password]:focus-visible {
        outline-offset: -2px;
    }

    label {
        display: block;
        font-size: var(--font-size-sm);
        line-height: 17px;
        font-weight: var(--font-weight-medium);
        font-family: var(--font-family-default);
        margin-bottom: 5px;
    }

    button {
        border: none;
        transition: opacity 250ms, background-color 250ms;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
        min-width: fit-content;
        font-size: var(--font-size-sm);
        font-weight: var(--font-weight-medium);
        box-shadow: var(--shadow-underline-2), var(--shadow-xs), var(--border-shadow-secondary) inset;
        background-color: white;
        color: var(--text-secondary);
        height: 40px;
        border-radius: 8px;
        padding: 0px 18px;
        font-family: var(--font-family-default);
        cursor: pointer;

        &:not(:disabled):hover {
            background-color: #F7F7F7;
            color: var(--text-primary);
        }

        &:disabled {
            filter: grayscale(0.5) opacity(0.6);
            cursor: default;
        }

        &.primary {
            background-color: var(--theme-color-600);
            font-weight: var(--font-weight-semibold);
            color: white;
            box-shadow: var(--shadow-underline-2), var(--shadow-xs), 0 0 0 1px #0A0D122E inset, 0px 2px 0px 0px #ffffff20 inset;

            &:not(:disabled):hover {
                color: white;
                background-color: color-mix(in srgb, var(--theme-color-600), #000 9%);
            }
        }

        &.large {
            height: 44px;
            font-size: var(--font-size-md);
        }
    }

    /* =============================================================================
       LOGIN TITLE
       ============================================================================= */
    #tsd-logo {
        width: 85px;
        position: absolute;
        top: 11px;
        left: 12px;
    }

    #login-title-container {
        width: 360px;
        text-align: center;
        place-self: center;
        position: relative;
        display: grid;
        margin-bottom: 32px;
    }

    #login-title1 {
        font-size: 36px;
        font-weight: var(--font-weight-semibold);
        color: var(--text-primary);
        margin-bottom: 10px;
    }

    #login-tagline {
        font-size: var(--font-size-md);
        color: var(--text-tertiary);
    }

    #login-logo-container {
        height: 62px;
        position: relative;
        display: flex;
        place-items: center;
        place-content: center;
        margin-bottom: 24px;

        #login-logo {
            height: 95%;
            position: absolute;
        }

        #login-background-grid {
            position: absolute;
            z-index: -1;
            opacity: 0.7;
        }
    }

    /* =============================================================================
       LOGIN CONTENT
       ============================================================================= */
    #login-content-container {
        width: 35%;
        height: 100%;
        position: absolute;
        left: 0px;
        top: 0px;
        background-color: white;
        min-width: 500px;
        min-height: 600px;
        z-index: 1;
        display: flex;
        flex-direction: column;
        place-content: center;
    }

    #login-content {
        box-sizing: border-box;
        width: 360px;
        position: relative;
        place-self: center;
        margin-bottom: 30px;

        input {
            width: 100%;
        }
    }

    #login-username,
    #login-password {
        margin-bottom: 20px;
    }

    #login-db-license-container {
        display: flex;
        gap: 12px;
        margin-bottom: 30px;

        #login-db-container {
            flex: 2;
        }

        #login-license-container {
            flex: 1;
        }
    }

    #login-lang-container {
        display: flex;
        gap: 8px;
        justify-content: right;
        margin: 12px 16px;
        position: absolute;
        right: 0px;
        top: 0px;

        button {
            height: 42px;
            padding-left: 8px !important;
            padding-right: 10px;
            border-radius: 12px;
            box-shadow: var(--shadow-underline-2), var(--shadow-xs), var(--border-shadow-tertiary) inset !important;
        }

        button.active {
            box-shadow: var(--shadow-underline-2), var(--shadow-xs), 0px 0px 0px 2px var(--theme-color-600) inset !important;
        }

        div {
            height: 28px;
            width: 28px;
            box-shadow: var(--border-shadow-primary) inset !important;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 6px;
            margin-right: 2px;
        }

        div > img {
            height: 18px;
        }
    }

    #login-submit {
        width: 100%;
        height: 48px;
    }

    /* Anchored by its top so a long server message wraps downward under the button instead of running off the panel */
    #login-error {
        position: absolute;
        top: calc(100% + 10px);
        text-align: center;
        color: var(--error-600);
        visibility: hidden;
        font-size: var(--font-size-md);
        left: 0px;
        right: 0px;
    }

    /* =============================================================================
       LOGIN IMAGE
       ============================================================================= */
    #login-image-container {
        top: 0px;
        left: 35%;
        width: 65%;
        height: 100%;
        position: absolute
    }

    /* Cropped mostly from the top so the forest floor stays in view; the default centre crop cut it off */
    #login-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center 75%;
    }

    /* =============================================================================
       LOGIN MODAL (generic)
       ============================================================================= */
    .login-modal {
        position: absolute;
        inset: 0px;
        display: none;
        align-items: center;
        justify-content: center;
        background-color: rgba(0, 0, 0, 0.4);
        z-index: 1008;

        &.open {
            display: flex;
        }
    }

    .login-modal .login-modal-main {
        position: relative;
        display: flex;
        flex-direction: column;
        width: 460px;
        max-width: 90%;
        background-color: white;
        border-radius: 16px;
        overflow: hidden;
    }

    .login-modal-dismiss {
        font-size: 16px;
        position: absolute;
        padding: 4px;
        right: 16px;
        top: 16px;
        user-select: none;
        cursor: pointer;
        color: var(--text-tertiary);
        z-index: 2;
    }

    .login-modal-header {
        box-shadow: 0px -1px 0px 0px var(--border-secondary) inset;
        padding: 15px 20px;
        display: flex;
        gap: 16px;
        align-items: center;
        position: relative;
    }

    .login-modal-header > .login-modal-decoration {
        position: absolute;
        transform: translate(-50%, -50%);
        height: 325px;
        width: 325px;
        left: 41.5px;
        top: 37.5px;
        z-index: 1;
        clip: rect(0px, 1000px, 220px, 0px);
    }

    .login-modal-header > .login-modal-icon-container {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 44px;
        height: 44px;
        background-color: white;
        border-radius: 10px;
        box-shadow: var(--border-shadow-primary);
        font-size: 20px;
        color: var(--text-secondary);
        z-index: 2;
    }

    .login-modal-header > .login-modal-title {
        font-size: var(--font-size-md);
        font-weight: var(--font-weight-semibold);
        color: var(--theme-color-600);
        padding-right: 35px;
        z-index: 2;
    }

    .login-modal-content {
        padding: 18px 24px 0px 24px;
        z-index: 2;
        margin-bottom: 20px;
        background-color: white;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }

    .login-modal-content > span {
        font-size: var(--font-size-md);
        color: var(--text-tertiary);
        margin-bottom: 12px;
    }

    .login-modal-content input {
        width: 100%;
    }

    /* =============================================================================
       ENGINE MODAL SPINNER
       ============================================================================= */
    .engine-modal-spinner {
        display: none;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 12px 0px 4px 0px;
        color: var(--text-tertiary);

        &.visible {
            display: flex;
        }
    }

    .engine-modal-spinner-icon {
        font-size: 20px;
        color: var(--theme-color-600);
        animation: engine-modal-spin 0.9s linear infinite;
    }

    .engine-modal-spinner-label {
        font-size: var(--font-size-sm);
    }

    .engine-modal-duration-hint {
        display: none;
        font-size: var(--font-size-sm);
        color: var(--text-tertiary);
        text-align: center;
        margin-top: 4px;

        &.visible {
            display: block;
        }
    }

    /* The technical reason under the load error (Login.showLoadError): small, so a screenshot carries it without
       it reading as the message itself; long URLs must wrap inside the 460px modal. */
    .load-error-detail {
        display: block;
        font-size: var(--font-size-sm);
        color: var(--text-tertiary);
        margin-top: 8px;
        overflow-wrap: anywhere;
    }

    .login-modal-footer {
        background-color: white;
        padding: 0px 24px 16px 24px;
        flex-direction: row-reverse;
        gap: 8px;
        z-index: 1;
        display: flex;

        > button {
            flex-grow: 1;
        }
    }
}

@keyframes engine-modal-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* =============================================================================
       DOCUMENT WAITING PAGE
       The tab a document preview opens on the click, until its PDF replaces it (the offerte mail dialog's
       Voorbeeld). It is styled here because the page loads only index.html's stylesheets, which every environment
       serves over plain HTTP. The opener copies its --theme-color-* values onto the tab's root. Where a gateway serves
       its own copy of the webroot, a rule added here shows only once that copy is redeployed.
       ============================================================================= */
body.document-waiting {
    align-items: center;
    justify-content: center;
    background: #F7F7F7;
}

.document-waiting-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 360px;
    padding: 32px 28px 28px;
    border-radius: 16px;
    background: #FFFFFF;
    box-shadow: var(--border-shadow-tertiary), 0px 4px 6px -1px #0A0D121A, 0px 2px 4px -2px #0A0D120F;
    text-align: center;
}

.document-waiting-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--theme-color-50, #F2F6ED);
    color: var(--theme-color-600);
    font-size: 22px;

    > i {
        animation: engine-modal-spin 1s linear infinite;
    }
}

.document-waiting-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.document-waiting-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.document-waiting-subtitle {
    color: var(--text-tertiary);
}
