/* =============================================================================
   Warp Modals
   Agera-style modal dialogs
   ============================================================================= */

/* -------------------------------------------------------------------------
   Modal Backdrop and Container
   ------------------------------------------------------------------------- */

.warp-modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: var(--warp-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--warp-spacing-4);
}

/* A <dialog> opened with showModal() has its own backdrop */
dialog.warp-modal {
    padding: 0;
    border: 0;

    &::backdrop {
        background-color: rgba(0, 0, 0, 0.3);
    }
}

.warp-modal {
    background-color: white;
    border-radius: var(--warp-radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 420px;
    width: 100%;
    overflow: hidden;
}

/* -------------------------------------------------------------------------
   Modal Header (Agera-style: orange stripe left, white title area, orange border bottom)
   ------------------------------------------------------------------------- */

.warp-modal-header {
    display: flex;
    align-items: stretch;
    background-color: white;
    border-bottom: 2px solid var(--warp-color-primary-500);
    min-height: 36px;
}

/* Orange vertical stripe on the left containing the icon */
.warp-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    background-color: var(--warp-color-primary-500);
    flex-shrink: 0;

    /* White circle with icon inside */
    & i {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        background-color: white;
        border-radius: var(--warp-radius-full);
        color: var(--warp-color-primary-600);
        font-size: 11px;
    }
}

.warp-modal-title {
    display: flex;
    align-items: center;
    padding: 0 var(--warp-spacing-3);
    font-size: var(--warp-font-size-sm);
    font-weight: var(--warp-font-weight-medium);
    color: var(--warp-color-gray-900);
    margin: 0;
    flex: 1;
}

.warp-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    border-radius: var(--warp-radius-default);
    transition: all var(--warp-transition-default);

    &:hover {
        background-color: rgba(255, 255, 255, 0.2);
        color: white;
    }
}

/* -------------------------------------------------------------------------
   Modal Body
   ------------------------------------------------------------------------- */

.warp-modal-body {
    padding: var(--warp-spacing-5) var(--warp-spacing-5);
    background-color: white;
}

.warp-modal-description {
    font-size: var(--warp-font-size-sm);
    color: var(--warp-color-gray-700);
    margin-bottom: var(--warp-spacing-4);
    line-height: var(--warp-line-height-relaxed);
}

/* Agera-style horizontal form layout in modal */
.warp-modal-form-row {
    display: flex;
    align-items: center;
    gap: var(--warp-spacing-4);
}

.warp-modal-form-row .warp-modal-label {
    flex: 0 0 auto;
    margin-bottom: 0;
}

.warp-modal-form-row .warp-select,
.warp-modal-form-row .warp-input {
    flex: 1;
}

/* -------------------------------------------------------------------------
   Modal Footer (Agera-style: no border, text buttons with icons)
   ------------------------------------------------------------------------- */

.warp-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--warp-spacing-5);
    padding: var(--warp-spacing-4) var(--warp-spacing-5);
    background-color: white;
}

/* Agera-style text buttons with icons */
.warp-modal-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--warp-spacing-2);
    padding: var(--warp-spacing-2) var(--warp-spacing-2);
    font-size: var(--warp-font-size-sm);
    font-weight: var(--warp-font-weight-medium);
    background: none;
    border: none;
    border-radius: var(--warp-radius-default);
    cursor: pointer;
    transition: all var(--warp-transition-default);
}

.warp-modal-btn-cancel {
    color: var(--warp-color-danger-600);

    &:hover {
        color: var(--warp-color-danger-700);
    }

    & i {
        color: var(--warp-color-danger-500);
    }
}

.warp-modal-btn-confirm {
    color: var(--warp-color-success-700);

    &:hover {
        color: var(--warp-color-success-800);
    }

    & i {
        color: var(--warp-color-success-500);
    }

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
}

/* Primary action variant (filled button) */
.warp-modal-btn-primary {
    background-color: var(--warp-color-primary-500);
    color: white;
    padding: var(--warp-spacing-2) var(--warp-spacing-4);

    &:hover {
        background-color: var(--warp-color-primary-600);
    }

    & i {
        color: inherit;
    }
}

/* -------------------------------------------------------------------------
   Form elements inside modal
   ------------------------------------------------------------------------- */

.warp-modal-form-group {
    margin-bottom: var(--warp-spacing-4);

    &:last-child {
        margin-bottom: 0;
    }
}

.warp-modal-label {
    display: block;
    font-size: var(--warp-font-size-sm);
    font-weight: var(--warp-font-weight-medium);
    color: var(--warp-color-gray-700);
    margin-bottom: var(--warp-spacing-2);

    &.required::after {
        content: ' *';
        color: var(--warp-color-danger-500);
    }
}

/* -------------------------------------------------------------------------
   Empty state in modal (all options used)
   ------------------------------------------------------------------------- */

.warp-modal-empty {
    text-align: center;
    padding: var(--warp-spacing-6) var(--warp-spacing-4);

    & i {
        font-size: var(--warp-font-size-3xl);
        color: var(--warp-color-success-500);
        margin-bottom: var(--warp-spacing-3);
    }

    & p {
        color: var(--warp-color-gray-600);
        margin: 0;
    }
}

/* =============================================================================
   Dialog: <twig:Warp:Dialog>, as wide as its content within its size and the
   window; content higher than the window scrolls with the title and the
   buttons in place, and a shadow at the edge that has more (warp--dialog)
   ============================================================================= */

dialog.warp-dialog {
    --warp-dialog-margin: var(--warp-spacing-4);
    width: fit-content;
    max-width: min(var(--warp-dialog-width), calc(100vw - 2 * var(--warp-dialog-margin)));
    max-height: calc(100dvh - 2 * var(--warp-dialog-margin));

    &[open] {
        display: flex;
        flex-direction: column;
    }
}

.warp-dialog--sm { --warp-dialog-width: 420px; }
.warp-dialog--md { --warp-dialog-width: 640px; }
.warp-dialog--lg { --warp-dialog-width: 960px; }

/* A dialog with frame: the frame's content, the body and the buttons, is laid out as the dialog's own. */
.warp-dialog > turbo-frame {
    display: contents;
}

.warp-dialog > .warp-modal-header,
.warp-dialog > .warp-dialog-buttons,
.warp-dialog > turbo-frame > .warp-dialog-buttons {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    transition: box-shadow var(--warp-transition-fast);
}

.warp-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;

    /* A visible scrollbar, also where the system hides it until scrolling. */
    &::-webkit-scrollbar {
        width: 10px;
    }

    &::-webkit-scrollbar-thumb {
        background-color: var(--warp-color-gray-400);
        border: 2px solid white;
        border-radius: var(--warp-radius-full);
    }

    &::-webkit-scrollbar-track {
        background-color: var(--warp-color-gray-100);
    }
}

@supports not selector(::-webkit-scrollbar) {
    .warp-dialog-body {
        scrollbar-color: var(--warp-color-gray-400) var(--warp-color-gray-100);
    }
}

.warp-dialog:has(> .warp-dialog-body--more-above, > turbo-frame > .warp-dialog-body--more-above) > .warp-modal-header {
    box-shadow: 0 6px 6px -4px rgba(0, 0, 0, 0.2);
}

.warp-dialog:has(> .warp-dialog-body--more-below) > .warp-dialog-buttons,
.warp-dialog:has(> turbo-frame > .warp-dialog-body--more-below) > turbo-frame > .warp-dialog-buttons {
    box-shadow: 0 -6px 6px -4px rgba(0, 0, 0, 0.2);
}

/* Where a notice goes first in the content: the shortcut notice while the dialog is open. */
.warp-dialog-notice {
    &:empty {
        display: none;
    }

    & > .warp-notice {
        margin-bottom: var(--warp-spacing-4);
    }
}

/* The buttons: start on the far left, apart; the others on the right, the main action last. */
.warp-dialog-buttons {
    align-items: center;
    flex-wrap: wrap;
    gap: var(--warp-spacing-3);
}

.warp-dialog-start,
.warp-dialog-end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--warp-spacing-3);
}

/* A dangerous action in start stands apart from the others, also where the dialog is only as wide as its content. */
.warp-dialog-start:not(:empty) {
    margin-inline-end: var(--warp-spacing-8);
}

.warp-dialog-start {
    margin-right: auto;

    &:empty {
        display: none;
    }
}

.warp-dialog-end {
    margin-left: auto;
    justify-content: flex-end;
}

/* =============================================================================
   Tooltip: <twig:Warp:Tooltip>, a hint in the top layer, placed by
   warp--tooltip under or over the control it wraps
   ============================================================================= */

.warp-tooltip {
    display: inline-flex;
    max-width: 100%;

    &:focus-visible {
        outline: 2px solid var(--warp-color-primary-500);
        outline-offset: 2px;
    }

    /* A disabled control lets the wrapper have the pointer and the tap. */
    &.warp-tooltip--disabled > :first-child {
        pointer-events: none;
    }
}

/* An entry in a menu fills its line. */
.warp-list-actions-menu .warp-tooltip {
    display: block;
}

.warp-tooltip-text {
    position: fixed;
    inset: auto;
    /* A hint over the next control never takes its click. */
    pointer-events: none;
    margin: 0;
    width: max-content;
    max-width: min(18rem, calc(100vw - 16px));
    overflow: visible;
    padding: var(--warp-spacing-1-5) var(--warp-spacing-2);
    border: 0;
    border-radius: var(--warp-radius-default);
    background-color: var(--warp-color-gray-900);
    color: white;
    font-size: var(--warp-font-size-xs);
    font-weight: var(--warp-font-weight-normal);
    line-height: var(--warp-line-height-normal);
    text-align: left;
    white-space: normal;
}

/* -------------------------------------------------------------------------
   Tangentbord: the view's shortcuts by part, <twig:Warp:Keyboard>
   ------------------------------------------------------------------------- */

.warp-keyboard {
    display: inline-flex;
}

.warp-keyboard-part + .warp-keyboard-part {
    margin-top: var(--warp-spacing-5);
}

.warp-keyboard-list {
    display: grid;
    grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
    column-gap: var(--warp-spacing-4);
    row-gap: var(--warp-spacing-2);
    margin: 0;
    font-size: var(--warp-font-size-sm);
}

.warp-keyboard-row {
    display: contents;
}

.warp-keyboard-keys {
    color: var(--warp-color-gray-700);

    & kbd {
        display: inline-block;
        min-width: 1.6em;
        padding: 0 var(--warp-spacing-1);
        border: 1px solid var(--warp-color-gray-300);
        border-bottom-width: 2px;
        border-radius: var(--warp-radius-default);
        background-color: var(--warp-color-gray-50);
        font-family: inherit;
        font-size: var(--warp-font-size-xs);
        text-align: center;
        color: var(--warp-color-gray-900);
    }
}

.warp-keyboard-combination {
    white-space: nowrap;
}

.warp-keyboard-or {
    color: var(--warp-color-gray-500);
    font-size: var(--warp-font-size-xs);
}

.warp-keyboard-label {
    margin: 0;
    color: var(--warp-color-gray-900);
}
