/**
 * Auction-setup modal — opens from the cog on /catalogue/.
 * Full-screen on mobile (≤640px), centered card on desktop.
 */

body.aiv2-modal-open { overflow: hidden; }

.aiv2-modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    font-family: var(--aiv2-font, 'Inter', sans-serif);
    color: var(--aiv2-text, #2C363D);
}
.aiv2-modal-overlay.is-open {
    display: flex;
    animation: aiv2FadeIn 0.15s ease-out;
}
@keyframes aiv2FadeIn { from { opacity: 0 } to { opacity: 1 } }

.aiv2-modal-card {
    background: var(--aiv2-card, #fff);
    border-radius: var(--aiv2-radius-lg, 16px);
    box-shadow: var(--aiv2-shadow-card, 0 14px 40px rgba(15,23,42,0.18));
    width: 100%;
    max-width: 720px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.aiv2-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--aiv2-border, #E5E7EB);
}
.aiv2-modal-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    flex: 1;
    color: var(--aiv2-text, #2C363D);
}
.aiv2-modal-saved {
    font-size: 13px;
    color: var(--aiv2-success, #16A34A);
    font-weight: 500;
}
.aiv2-modal-close {
    background: none;
    border: 0;
    font-size: 26px;
    line-height: 1;
    color: var(--aiv2-text-muted, #6B7280);
    cursor: pointer;
    padding: 0;
    width: 32px; height: 32px;
    border-radius: 50%;
    transition: background 0.12s;
}
.aiv2-modal-close:hover { background: var(--aiv2-bg, #F5F7FA); color: var(--aiv2-text, #2C363D); }

.aiv2-modal-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Left rail (desktop) — becomes top bar on mobile */
.aiv2-modal-rail {
    flex: 0 0 200px;
    background: var(--aiv2-bg, #F5F7FA);
    border-right: 1px solid var(--aiv2-border, #E5E7EB);
    padding: 12px;
    overflow-y: auto;
}
.aiv2-modal-rail-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 0;
    border-radius: var(--aiv2-radius-md, 10px);
    font-family: inherit;
    font-size: 14px;
    color: var(--aiv2-text-muted, #6B7280);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, color 0.12s;
}
.aiv2-modal-rail-item:hover { background: rgba(154,110,86,0.06); color: var(--aiv2-text, #2C363D); }
.aiv2-modal-rail-item.is-active {
    background: var(--aiv2-card, #fff);
    color: var(--aiv2-brown, #9A6E56);
    font-weight: 600;
    box-shadow: var(--aiv2-shadow-soft, 0 2px 8px rgba(15,23,42,0.04));
}
.aiv2-rail-icon { font-size: 16px; }

.aiv2-modal-section {
    flex: 1;
    padding: 24px 28px;
    overflow-y: auto;
}
.aiv2-section-title {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
    color: var(--aiv2-text, #2C363D);
}
.aiv2-section-sub {
    margin: 0 0 20px;
    font-size: 13px;
    color: var(--aiv2-text-muted, #6B7280);
}

.aiv2-field { margin-bottom: 18px; }
.aiv2-field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}
.aiv2-field-hint {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--aiv2-text-muted, #6B7280);
}
.aiv2-input {
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--aiv2-border-hover, #D1D5DB);
    border-radius: var(--aiv2-radius-sm, 6px);
    background: #FAFAFA;
    color: var(--aiv2-text, #2C363D);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.12s, background 0.12s;
}
.aiv2-input:focus {
    outline: none;
    border-color: var(--aiv2-brown, #9A6E56);
    background: #fff;
    box-shadow: 0 0 0 3px var(--aiv2-focus, rgba(154,110,86,0.15));
}

.aiv2-tiny { font-size: 12px; color: var(--aiv2-text-muted, #6B7280); }
.aiv2-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.aiv2-slider {
    flex: 1;
    accent-color: var(--aiv2-brown, #9A6E56);
}

/* Toggle grid + iOS-style toggle */
.aiv2-toggle-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 24px;
}
@media (max-width: 640px) {
    .aiv2-toggle-grid { grid-template-columns: 1fr; }
}
.aiv2-toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
}
.aiv2-toggle-row input[type="checkbox"] {
    position: absolute; opacity: 0; pointer-events: none;
}
.aiv2-toggle-track {
    flex: 0 0 38px;
    height: 22px;
    background: #CBD5E1;
    border-radius: 11px;
    position: relative;
    transition: background 0.15s;
}
.aiv2-toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.15s;
}
.aiv2-toggle-row input[type="checkbox"]:checked ~ .aiv2-toggle-track {
    background: var(--aiv2-brown, #9A6E56);
}
.aiv2-toggle-row input[type="checkbox"]:checked ~ .aiv2-toggle-track .aiv2-toggle-thumb {
    transform: translateX(16px);
}
.aiv2-toggle-label {
    font-size: 14px;
    color: var(--aiv2-text, #2C363D);
}

.aiv2-modal-error {
    padding: 12px 16px;
    background: var(--aiv2-danger-bg, #FEE2E2);
    border: 1px solid var(--aiv2-danger, #FCA5A5);
    border-radius: var(--aiv2-radius-sm, 6px);
    color: var(--aiv2-danger, #991B1B);
    font-size: 14px;
}

/* Mobile: full-screen modal, rail becomes horizontal scroller */
@media (max-width: 640px) {
    .aiv2-modal-overlay { padding: 0; align-items: stretch; }
    .aiv2-modal-card {
        border-radius: 0;
        max-height: 100vh;
        max-width: 100%;
    }
    .aiv2-modal-body { flex-direction: column; }
    .aiv2-modal-rail {
        flex: 0 0 auto;
        display: flex;
        flex-direction: row;
        gap: 8px;
        border-right: 0;
        border-bottom: 1px solid var(--aiv2-border, #E5E7EB);
        overflow-x: auto;
        white-space: nowrap;
        padding: 10px 12px;
    }
    .aiv2-modal-rail-item {
        flex: 0 0 auto;
        min-width: max-content;
    }
    .aiv2-rail-label { display: inline; }
    .aiv2-modal-section { padding: 18px 16px 32px; }
}

/* Cog button on the catalogue page */
.aiv2-cog-btn {
    background: var(--aiv2-card, #fff);
    border: 1px solid var(--aiv2-border-hover, #D1D5DB);
    border-radius: var(--aiv2-radius-md, 10px);
    width: 38px; height: 38px;
    cursor: pointer;
    font-size: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.12s, border-color 0.12s;
}
.aiv2-cog-btn:hover {
    background: var(--aiv2-bg, #F5F7FA);
    border-color: var(--aiv2-brown, #9A6E56);
}

/* Per-field grid (Lot fields section) — paired AI+Manual toggles */
.aiv2-fieldgrid-head,
.aiv2-fieldgrid-row {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 16px;
    align-items: center;
    padding: 8px 0;
}
.aiv2-fieldgrid-head {
    border-bottom: 1px solid var(--aiv2-border, #E5E7EB);
    padding-bottom: 10px;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--aiv2-text-muted, #6B7280);
}
.aiv2-fieldgrid-head > div:not(:first-child) { text-align: center; }
.aiv2-fieldgrid-row {
    border-bottom: 1px solid #F3F4F6;
}
.aiv2-fieldgrid-row:last-child { border-bottom: 0; }
.aiv2-fieldgrid-name {
    font-size: 14px;
    color: var(--aiv2-text, #2C363D);
    font-weight: 500;
}
.aiv2-fieldgrid-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.aiv2-fieldgrid-toggle.is-dimmed {
    opacity: 0.4;
    cursor: not-allowed;
}
.aiv2-fieldgrid-toggle input[type="checkbox"] {
    position: absolute; opacity: 0; pointer-events: none;
}
.aiv2-fieldgrid-toggle input[type="checkbox"]:disabled ~ .aiv2-toggle-track {
    cursor: not-allowed;
}
.aiv2-fieldgrid-toggle .aiv2-toggle-track {
    flex: 0 0 38px;
    height: 22px;
    background: #CBD5E1;
    border-radius: 11px;
    position: relative;
    transition: background 0.15s;
}
.aiv2-fieldgrid-toggle .aiv2-toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.15s;
}
.aiv2-fieldgrid-toggle input[type="checkbox"]:checked ~ .aiv2-toggle-track {
    background: var(--aiv2-brown, #9A6E56);
}
.aiv2-fieldgrid-toggle input[type="checkbox"]:checked ~ .aiv2-toggle-track .aiv2-toggle-thumb {
    transform: translateX(16px);
}
