/*
 * Quick Create Popup — Reusable inline entity creation popup styles
 */

/* Backdrop */
.quick-create-popup-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.quick-create-popup-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Prevent underlying page scroll while popup is open */
body.qc-popup-open {
    overflow: hidden;
}

/* Always keep the popup inside the viewport, even on zoom */
.quick-create-popup {
    /* JS sets top/left/width; ensure sizing stays correct across zoom */
    transform-origin: top left;
}


/* Popup container */
.quick-create-popup {
    position: fixed;
    z-index: 1501;
    width: 380px;
    max-width: calc(100vw - 16px);
    max-height: 70vh;
    background: var(--surface-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg, 0 8px 32px rgba(0,0,0,0.15));
    display: none;
    flex-direction: column;
    animation: qc-popup-in 0.15s ease-out;
}

/* Ensure popup can scroll when content exceeds max-height */
.quick-create-popup.active {
    display: flex;
}

/* The form sits between popup and body/footer — needs flex to pass space down */
.quick-create-popup-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Body scrolls when content overflows; footer stays pinned at bottom */
.quick-create-popup-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

@keyframes qc-popup-in {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Arrow indicator */
.quick-create-popup::before {
    content: '';
    position: absolute;
    left: 24px;
    width: 12px;
    height: 12px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-default);
    transform: rotate(45deg);
    z-index: -1;
}

.quick-create-popup:not(.open-upward)::before {
    top: -7px;
    border-bottom: none;
    border-right: none;
}

.quick-create-popup.open-upward::before {
    bottom: -7px;
    border-top: none;
    border-left: none;
}

/* Header */
.quick-create-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.quick-create-popup-title {
    margin: 0;
    font-size: var(--font-title, 1rem);
    font-weight: var(--font-weight-semibold, 600);
    color: var(--text-primary);
}

.quick-create-popup-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.quick-create-popup-close:hover {
    background: var(--surface-input);
    color: var(--text-primary);
}

/* Body */
.quick-create-popup-body {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow-x: hidden;
}

/* Ensure smooth scrolling at all zoom levels */
.quick-create-popup-body::-webkit-scrollbar {
    width: 8px;
}

.quick-create-popup-body::-webkit-scrollbar-track {
    background: transparent;
}

.quick-create-popup-body::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-sm);
}

.quick-create-popup-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.quick-create-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quick-create-field label {
    font-size: var(--font-caption, 0.8rem);
    font-weight: var(--font-weight-medium, 500);
    color: var(--text-secondary);
}

.quick-create-field .required-asterisk {
    color: var(--status-danger);
}

.quick-create-field .form-input {
    width: 100%;
    box-sizing: border-box;
}

.quick-create-field.is-invalid .form-input,
.quick-create-field.is-invalid select {
    border-color: var(--status-danger);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.12);
}

/* Footer */
.quick-create-popup-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* Error */
.quick-create-popup-error {
    padding: var(--space-1) var(--space-3);
    background: var(--status-danger-subtle, #fdecea);
    color: var(--status-danger, #b42318);
    font-size: var(--font-caption, 0.8rem);
    border-top: 1px solid var(--border-default);
}

.quick-create-popup-error.hidden {
    display: none;
}

/* "+" button attached to selectors */
.quick-create-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}

.quick-create-wrapper .form-input {
    flex: 1;
}

.quick-create-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.quick-create-btn:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
    background: var(--brand-primary-subtle, rgba(37, 99, 235, 0.06));
}

/* Edit state: once an entity is selected, the "+" becomes a pencil icon.
   Use a solid border to signal that this now edits an existing record. */
.quick-create-btn.is-edit {
    border-style: solid;
    color: var(--brand-primary);
    background: var(--brand-primary-subtle, rgba(37, 99, 235, 0.08));
}

.quick-create-btn.is-edit:hover {
    border-color: var(--brand-primary);
    color: #fff;
    background: var(--brand-primary);
}

.quick-create-btn svg {
    display: block;
}

/* Stacking: subsequent popups get higher z-index */
.quick-create-popup[data-stack-level="1"] { z-index: 1503; }
.quick-create-popup[data-stack-level="2"] { z-index: 1505; }
.quick-create-popup[data-stack-level="3"] { z-index: 1507; }

/* Responsive */
@media (max-width: 480px) {
    .quick-create-popup {
        position: fixed;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100%;
        max-height: 85vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        animation: qc-popup-up 0.2s ease-out;
    }

    .quick-create-popup::before {
        display: none;
    }

    @keyframes qc-popup-up {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}

/* Override for select-with-icon to accommodate the button */
.select-with-icon.quick-create-wrapper .quick-create-btn {
    margin-left: auto;
}

/* Dark theme — via prefers-color-scheme, tokens handle colors automatically via CSS variables */
@media (prefers-color-scheme: dark) {
    .quick-create-popup {
        border-color: var(--border-default);
        box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    }

    .quick-create-popup-error {
        background: #3b1c1a;
        color: #fca5a5;
        border-color: #5c2c2a;
    }
}