/*
    ui.css contains general UI component styles used throughout the application.

 */


@layer ui {


    input, select, textarea, button {
        border: 1.5px outset var(--border-outset-color);
        border-bottom: 3px outset var(--border-outset-color);
        /* Top/left are solid: 'outset' lightens those sides, and this light translucent
           color then disappears on white. Bottom/right stay outset for the 3D look. */
        border-top: 1px solid var(--border-outset-color);
        border-left: 1px solid var(--border-outset-color);
        padding: 0.5rem;
        padding-inline: 1em;
        border-radius: var(--border-minimal);
        text-box-trim: trim-both;
    }


    button, input[type=submit] {
        cursor: pointer;
        border-bottom-width: 5px;
        border-style: solid outset outset solid;  /* top right bottom left — see note above */
        position: relative;
        margin-top: 0;
        min-width: 100px;
        padding-inline: 1.25rem;
        text-box-trim: trim-both;
        user-select: none;
        font-weight: 500;
        height: 48px;
        display: inline-flex;
        gap: 0.25em;
        align-items: center;
        justify-content: center;

        transition:
                border-bottom-width 0.1s ease-out,
                margin-top 0.1s ease-out,
                height 0.1s ease-out,
                filter 0.1s;

        img {
            margin-left: -0.375rem;
            width: 1.5rem;
            height: 1.5rem;
        }

        &[color=green] {
            background-color: var(--md-green);
        }

        &[color=red] {
            background-color: var(--md-red);
        }

        &[color=blue] {
            background-color: var(--md-blue);
        }

        &[color=yellow] {
            background-color: var(--md-yellow);
        }

        &[color=orange] {
            background-color: var(--md-orange);
        }

        &[color=purple] {
            background-color: var(--madave-purple);
            color: var(--white);

            img { filter: invert(1); }
        }

        &:hover {
            filter: brightness(1.1);
        }

        &:active {
            border-bottom-width: 1.5px;
            margin-top: 2.5px;
            height: 45.5px;
            border-style: inset;
            transition: none;
        }

        &.secondary {
            border: 1.5px outset #00000040;
            background-color: transparent;
            margin-top: 2.5px;
            height: 45.5px;

            transition: background-color 0.1s, border-style 0s;

            &:active {
                border-style: inset;
                transition: none;
            }

            &:hover {
                background-color: #FFFFFF99;
            }
        }
    }



    textarea {
        padding: 1rem 1.5rem;
    }



    grouped-section {
        display: flex;
        gap: 1em;
        margin-block: 2em;

        &:first-child {
            margin-block-start: 0;
        }

        &:last-child {
            margin-block-end: 0;
        }

        &.right {
            justify-content: flex-end;
        }
    }


    section {
        margin-block: 2rem;

        &:first-child {
            margin-block-start: 0;
        }

        &:last-child {
            margin-block-end: 0;
        }

    }


    hud-table {

        border-radius: var(--border-large);
        overflow: hidden;
        border: 1px solid var(--color-border);
        background: var(--color-surface-muted);
    }



    tray {
        position: fixed;
        bottom: 1.75em;
        right: 1.75em;
        z-index: 10;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-end;
        user-select: none;

        &:has( > [shade]) + shade {
            display: block;
            position: fixed;
            background-color: #424242c7;
            height: 100%;
            width: 100%;
            top: 0;
            left: 0;
        }

        hud-notification {
            background-color: var(--lt-yellow);
            border-radius: var(--border-minimal);
            display:inline-flex;
            gap: 1em;
            padding: .5em 1em;
            box-shadow: 0 3px 3px #7373737d;

            .close-btn {
                cursor: pointer;
                opacity: 0.5;

                &:hover {
                    opacity: 1;
                }
            }
        }
    }


    hud-card-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
        gap: 2rem;
        padding: 0;
    }


    details {

        summary {

            cursor: pointer;

            h3 {
                display: inline-block;
                padding-left: .5em;
                text-box: ex alphabetic;
                top: 1px;
                position: relative;
                margin-bottom: 0 !important;
            }
        }

    }




    stats {
        display: flex;
        gap: 1.5rem;
        flex-wrap: wrap;
    }


    .brief-content {

        li {
            margin-bottom: 0.5em;
        }
    }


    detail-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1.5rem;
    }

    /* Compact label/value rows grouped into columns: a denser alternative to detail-grid tiles. */
    detail-columns {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 1.25rem 2.5rem;
    }

    detail-group {
        display: flex;
        flex-direction: column;

        > h4 {
            margin: 0 0 0.25rem;
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            opacity: 0.55;
        }
    }

    detail-row {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--color-border);

        &:last-child {
            border-bottom: none;
        }

        > label {
            font-size: 0.9rem;
            opacity: 0.65;
            white-space: nowrap;
        }

        > span {
            font-weight: 500;
            text-align: right;
        }

        &.strong > span {
            font-weight: 700;
        }
    }

    comment-thread {
        display: block;
        margin-bottom: 1rem;
    }

    .comment-form {
        display: flex;
        gap: 1rem;
        align-items: flex-end;

        textarea {
            flex: 1;
            margin-bottom: 0;
        }

        button {
            flex-shrink: 0;
        }
    }


    /* File list styles (shared with file-drop component) */

    .existing-attachments file-list {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;

        &:empty {
            display: none;
        }
    }

    .existing-attachments file-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.5rem 0.75rem;
        background: var(--white);
        border: 1.5px solid var(--color-border);
        border-radius: var(--border-minimal);

        &[data-status="complete"] {
            border-color: var(--md-blue);
        }
    }

    .existing-attachments file-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.5rem;
        height: 1.5rem;
        opacity: 0.6;

        svg {
            width: 100%;
            height: 100%;
        }
    }

    .existing-attachments file-info {
        flex: 1;
        min-width: 0;
    }

    .existing-attachments file-name {
        display: block;
        font-size: 0.9rem;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;

        a {
            color: inherit;
            text-decoration: none;

            &:hover {
                text-decoration: underline;
            }
        }
    }

    .existing-attachments file-size {
        display: block;
        font-size: 0.75rem;
        color: var(--color-text-muted);
    }

    .existing-attachments file-remove {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.5rem;
        height: 1.5rem;
        cursor: pointer;
        opacity: 0.5;
        border-radius: 50%;
        transition: opacity 0.15s ease, background 0.15s ease;

        &:hover {
            opacity: 1;
            background: rgba(0, 0, 0, 0.1);
        }

        svg {
            width: 0.875rem;
            height: 0.875rem;
        }
    }

    .existing-attachments file-visibility {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.5rem;
        height: 1.5rem;
        cursor: pointer;
        opacity: 0.5;
        border-radius: 50%;
        transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;

        &:hover {
            opacity: 1;
            background: rgba(0, 0, 0, 0.1);
        }

        &.locked {
            color: var(--black);
        }

        &.unlocked {
            opacity: 1;
            color: var(--black);
        }

        svg {
            width: 0.875rem;
            height: 0.875rem;
        }
    }


    /* View-only file list (for job view page) */

    file-list.view-only {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;

        &:empty {
            display: none;
        }

        file-item {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            padding: 0.5rem 0.75rem;
            background: var(--white);
            border: 1.5px solid var(--color-border);
            border-radius: var(--border-minimal);
        }

        file-icon {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 1.5rem;
            height: 1.5rem;
            opacity: 0.6;

            svg {
                width: 100%;
                height: 100%;
            }
        }

        file-info {
            flex: 1;
            min-width: 0;
        }

        file-name {
            display: block;
            font-size: 0.9rem;
            font-weight: 500;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            a {
                color: inherit;
                text-decoration: none;

                &:hover {
                    text-decoration: underline;
                }
            }
        }

        file-size {
            display: block;
            font-size: 0.75rem;
            color: var(--color-text-muted);
        }
    }


    /* Batch Invoice Summary Table in Dialog */
    .invoice-summary-table {
        margin: 1.5rem 0;
        max-height: 400px;
        overflow-y: auto;
        border: 1px solid var(--lt-gray);
        border-radius: var(--border-minimal);
    }

    .invoice-summary-table table {
        width: 100%;
        border-collapse: collapse;
    }

    .invoice-summary-table th {
        position: sticky;
        top: 0;
        background: var(--color-surface-muted);
        padding: 0.75rem;
        text-align: left;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }

    .invoice-summary-table td {
        padding: 0.75rem;
        border-bottom: 1px solid var(--lt-gray);
    }

    .invoice-summary-table .amount {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    .invoice-summary-table tfoot {
        background: var(--color-surface-muted);
        font-weight: bold;
    }

    .invoice-summary-table tfoot td {
        border-top: 2px solid var(--color-border);
        border-bottom: none;
    }

    /* Batch button disabled state */
    #batch-invoice-btn[disabled] {
        opacity: 0.5;
        cursor: not-allowed;
    }

    /* Compact icon-only button (e.g. approve/check actions in card footers). */
    button.small-icon-button {
        min-width: 60px;
        padding: 0.4rem;
        padding-right: 0;
    }


}

/* Keyboard shortcuts (assets/js/shortcuts.js): key caps, inline hints, g-navigation badges, cheat sheet */
@layer ui {

    kbd {
        display: inline-block;
        min-width: 1.5em;
        padding: 0.15em 0.45em;
        font-family: inherit;
        font-size: 0.75rem;
        font-weight: 600;
        line-height: 1.2;
        text-align: center;
        border: 1px solid var(--color-border);
        border-bottom-width: 2px;
        border-radius: var(--border-minimal);
        background: var(--color-surface-muted);
    }

    /* Quiet inline hint on a control (e.g. Edit Job · E, Send · ⌘↵) */
    kbd.kbd-hint {
        margin-left: 0.6em;
        opacity: 0.55;
        font-size: 0.7rem;
        vertical-align: 0.1em;
    }
    /* Inside a button the hint is plain text: a key cap would read as a button within a button */
    button kbd.kbd-hint {
        min-width: 0;
        padding: 0;
        border: 0;
        background: transparent;
        font-size: 0.8em;
        font-weight: 500;
        opacity: 0.5;
    }

    /* Sidebar: key badges appear only while the "g" prefix is pressed */
    /* Same key-cap look as the search bar's ⌘K hint (SearchBar.groovy kbd.shortcut-hint) */
    body.kbd-g-active nav a[data-kbd]::after {
        content: attr(data-kbd);
        flex: none;
        margin-left: auto;
        min-width: 1.4em;
        text-align: center;
        font-family: inherit;
        font-size: 0.75rem;
        font-weight: 600;
        line-height: 1;
        padding: 0.3em 0.5em;
        border: 1px solid var(--color-border);
        border-bottom-width: 2px;
        border-radius: var(--border-minimal);
        background: var(--color-surface-muted);
        opacity: 0.7;
    }

    a.kbd-help-link {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        margin: auto 0 1rem 0;  /* pushed to the bottom of the nav; bottom space keeps it off the Updates pane */
        justify-self: end;
        align-self: start;
        font-size: 0.8rem;
        opacity: 0.55;
        text-decoration: none;
        color: inherit;

        &:hover { opacity: 0.9; }
        kbd { font-size: 0.7rem; }
    }

    /* Cheat sheet: compact; every section is full width and its list flows into columns,
       so the layout is tight whether or not the page has its own shortcuts */
    dialog.kbd-help {
        position: fixed;
        inset: 0;
        margin: auto;
        width: min(50rem, 92vw);
        max-height: 85vh;
        overflow-y: auto;
        padding: 1.5rem;
        font-size: 0.9rem;
        border: 1px solid var(--color-border);
        border-radius: var(--border);

        &::backdrop { background: rgb(0 0 0 / 0.35); }

        /* the dialog itself takes focus (no buttons inside); no focus ring around the whole sheet */
        &:focus, &:focus-visible { outline: none; }

        header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin: 0;
            padding-right: 2.5rem;  /* room for the close icon */
            h2 {
                margin: 0.33rem 0 1.5rem 0;  /* HudDialog uses 2.25rem below; tighter here on purpose */
                font-size: 1.5rem;
                font-weight: 600;
                text-box-trim: trim-both;
                user-select: none;
            }
        }

        /* Same close icon as HudDialog; the backdrop click and Esc also dismiss */
        [for='close-button'] {
            position: absolute;
            top: 1.4rem;
            right: 1.5rem;
            width: 2rem;
            height: 2rem;
            cursor: pointer;
            opacity: 0.5;
            transition: opacity 0.2s ease-in-out;
            user-select: none;
            &:hover { opacity: 0.9; }
        }

        /* Every key cap is a uniform box: single characters are all exactly the same size,
           longer labels (Enter, Esc) grow from that minimum */
        kbd {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;
            min-width: 1.85em;
            height: 1.85em;
            padding: 0 0.4em;
            line-height: 1;

            &.kbd-1 { width: 1.85em; min-width: 0; padding: 0; }
        }

        .kbd-help-grid {
            display: flex;
            flex-direction: column;
            gap: 0.9rem;
        }

        /* app-wide <section> spacing doesn't belong in this compact dialog */
        section { margin: 0; padding: 0; }
        section ul { columns: 3 13rem; column-gap: 1.75rem; }
        section li { break-inside: avoid; }

        h3 {
            margin: 0 0 0.25rem;
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            opacity: 0.55;
        }

        ul { list-style: none; margin: 0; padding: 0; }

        li {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.75rem;
            padding: 0.28rem 0;
            border-bottom: 1px solid var(--color-border);
        }

        .kbd-keys { display: inline-flex; gap: 0.2rem; white-space: nowrap; order: 2; }

        .kbd-help-foot {
            margin: 0.75rem 0 0;
            font-size: 0.75rem;
            opacity: 0.6;
        }
    }
}
