/* ===== Responsive ===== */
@media (max-width: 768px) {
    html,
    body {
        overflow-x: hidden;
    }

    .layout {
        grid-template-columns: 1fr;
        min-height: calc(100vh - 50px);
    }

    .sidebar {
        position: fixed;
        top: 50px;
        left: 0;
        bottom: 0;
        z-index: 90;
        width: min(86vw, 340px) !important;
        max-width: min(86vw, 340px);
        height: auto;
        max-height: none;
        padding: 0.85rem !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        overflow-y: auto;
        overflow-x: hidden;
        border-right: 1px solid var(--pico-muted-border-color);
        border-bottom: none;
        box-shadow: 16px 0 38px rgba(15, 23, 42, 0.18);
        transform: translateX(0);
        transition: transform 0.2s ease, opacity 0.15s ease;
    }

    [data-sidebar-open="false"] .sidebar {
        display: block;
        transform: translateX(-105%);
        opacity: 0 !important;
        pointer-events: none !important;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 50px 0 0 0;
        z-index: 85;
        background: rgba(15, 23, 42, 0.28);
        opacity: 1;
        pointer-events: auto;
        transition: opacity 0.15s ease;
    }

    [data-sidebar-open="false"] .sidebar-backdrop {
        opacity: 0;
        pointer-events: none;
    }

    .content {
        padding: 0.65rem;
        overflow-x: hidden;
    }

    .sidebar-toggle {
        display: flex !important;
        top: 58px;
        right: 0.45rem;
        left: auto !important;
        width: 38px;
        height: 34px;
        transform: none;
        border: 1px solid var(--pico-muted-border-color);
        border-radius: 8px;
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
    }

    [data-sidebar-open="false"] .sidebar-toggle svg {
        transform: rotate(180deg);
    }

    .top-nav {
        height: 50px;
        gap: 0.45rem;
        padding: 0 0.55rem;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .top-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-brand {
        font-size: 0.9rem;
        flex: 0 0 auto;
    }

    .nav-logo {
        height: 1.15rem;
    }

    .nav-links {
        flex: 0 0 auto;
        gap: 0.2rem;
        overflow: visible;
    }

    .nav-link {
        padding: 0.32rem 0.5rem;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .nav-right {
        flex: 0 0 auto;
        margin-left: 0;
    }

    .nav-user {
        display: none;
    }

    .tab-bar,
    .filter-row,
    .table-controls {
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .filter-row {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .filter-row select,
    .filter-row input,
    .search-container {
        width: 100%;
        max-width: none;
    }

    .table-wrapper {
        max-height: none;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .data-table {
        min-width: max-content;
        font-size: 0.76rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.34rem 0.45rem;
    }

    .content .btn-primary,
    .content .btn-secondary,
    .content button,
    .sidebar button {
        min-height: 2.15rem;
    }

    h1 {
        font-size: 1.12rem;
    }

    h2 {
        font-size: 1rem;
    }
}

@media (max-width: 520px) {
    .nav-brand {
        max-width: 6.8rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-link {
        font-size: 0.74rem;
        padding: 0.3rem 0.42rem;
    }

    .content {
        padding: 0.5rem;
    }
}

/* Dashboard may be entered through HTMX-boosted navigation, which does not
   reload page-specific head styles. */
.dashboard-sidebar-action {
    width: 100%;
    margin: 0 0 0.35rem;
    border: 1px solid #6b7280;
    border-radius: 5px;
    font-weight: 700;
    box-shadow: none;
    text-align: center;
    text-decoration: none;
}

.dashboard-sidebar-action-primary {
    border-color: #374151;
    background: #374151;
    color: #fff !important;
}

.dashboard-sidebar-action-primary:hover,
.dashboard-sidebar-action-primary:focus-visible {
    border-color: #1f2937;
    background: #1f2937;
    color: #fff !important;
}

.dashboard-sidebar-action-secondary {
    border-color: #6b7280;
    background: transparent;
    color: #374151 !important;
}

.dashboard-sidebar-action-secondary:hover,
.dashboard-sidebar-action-secondary:focus-visible {
    border-color: #4b5563;
    background: #f3f4f6;
    color: #1f2937 !important;
}

[data-theme="dark"] .dashboard-sidebar-action-primary {
    border-color: #6b7280;
    background: #4b5563;
}

[data-theme="dark"] .dashboard-sidebar-action-primary:hover,
[data-theme="dark"] .dashboard-sidebar-action-primary:focus-visible {
    border-color: #9ca3af;
    background: #6b7280;
}

[data-theme="dark"] .dashboard-sidebar-action-secondary {
    border-color: #6b7280;
    color: #e5e7eb !important;
}

[data-theme="dark"] .dashboard-sidebar-action-secondary:hover,
[data-theme="dark"] .dashboard-sidebar-action-secondary:focus-visible {
    border-color: #9ca3af;
    background: #272f3b;
    color: #fff !important;
}

.dashboard-recent-jobs {
    margin-top: 0.65rem;
    font-size: 0.72rem;
}

.dashboard-recent-jobs summary {
    cursor: pointer;
    font-weight: 700;
}

.dashboard-recent-jobs details > small {
    display: block;
    margin: 0.25rem 0;
    color: var(--pico-muted-color);
}

.dashboard-recent-jobs-list {
    display: grid;
    gap: 0.4rem;
    max-height: 16rem;
    overflow-y: auto;
    list-style: none;
    padding: 0 0.2rem 0 0;
    margin: 0.3rem 0 0;
}

.dashboard-recent-job {
    border-top: 1px solid var(--pico-muted-border-color);
    padding-top: 0.3rem;
    overflow-wrap: anywhere;
}

.dashboard-recent-job-error {
    display: block;
    color: var(--pico-del-color);
}

.posthoc-environment-field {
    margin: 0 0 0.45rem;
}

.posthoc-environment-field > label {
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr);
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    color: var(--pico-muted-color);
    font-size: 0.78rem;
}

.posthoc-environment-field > label > span {
    white-space: nowrap;
}

.environment-autocomplete-wrap {
    position: relative;
    display: block;
    min-width: 0;
}

.posthoc-environment-field input {
    width: 100%;
    min-width: 0;
    min-height: 1.9rem;
    margin: 0;
    padding: 0.28rem 0.45rem;
    font-size: 0.8rem;
    padding-right: 1.8rem;
}

.posthoc-environment-field.is-loading .environment-autocomplete-wrap::after {
    content: "";
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    width: 0.72rem;
    height: 0.72rem;
    border: 2px solid color-mix(in srgb, #0f766e 25%, transparent);
    border-top-color: #0f766e;
    border-radius: 50%;
    animation: object-id-spin 0.7s linear infinite;
    pointer-events: none;
}

.environment-suggestion-list {
    position: absolute;
    z-index: 90;
    top: calc(100% + 0.22rem);
    left: 0;
    right: 0;
    max-height: 15rem;
    overflow-y: auto;
    padding: 0.3rem;
    border: 1px solid color-mix(in srgb, #0f766e 50%, var(--pico-muted-border-color));
    border-radius: 6px;
    background: var(--pico-form-element-background-color, #fff);
    box-shadow: 0 10px 24px color-mix(in srgb, #0f172a 18%, transparent);
}

.environment-suggestion-list[hidden] {
    display: none;
}

.environment-suggestion-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    min-height: 2.15rem;
    margin: 0;
    padding: 0.4rem 0.52rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--pico-form-element-color, #1f2937) !important;
    text-align: left;
    box-shadow: none;
}

.environment-suggestion-option + .environment-suggestion-option {
    margin-top: 0.16rem;
}

.environment-suggestion-option:hover,
.environment-suggestion-option:focus-visible,
.environment-suggestion-option.is-active {
    border-color: color-mix(in srgb, #0f766e 35%, transparent);
    background: color-mix(in srgb, #0f766e 14%, var(--pico-form-element-background-color));
    color: var(--pico-form-element-color, #1f2937) !important;
}

.environment-suggestion-name {
    display: inline-block !important;
    min-width: 0;
    overflow: hidden;
    color: var(--pico-form-element-color, #1f2937) !important;
    font-size: 0.76rem;
    font-weight: 650;
    opacity: 1 !important;
    text-overflow: ellipsis;
    visibility: visible !important;
    white-space: nowrap;
}

.environment-suggestion-count {
    display: inline-flex !important;
    align-items: center;
    flex: 0 0 auto;
    min-height: 1.25rem;
    padding: 0.08rem 0.34rem;
    border: 1px solid color-mix(in srgb, #0f766e 24%, var(--pico-muted-border-color));
    border-radius: 999px;
    background: color-mix(in srgb, #0f766e 8%, var(--pico-form-element-background-color));
    color: var(--pico-muted-color) !important;
    font-size: 0.64rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    opacity: 1 !important;
    visibility: visible !important;
}

@media (max-width: 620px) {
    .posthoc-environment-field > label {
        grid-template-columns: 1fr;
        gap: 0.2rem;
    }

}

.object-id-autocomplete-wrap {
    position: relative;
    display: block;
    flex: 1 1 auto;
    min-width: 140px;
}

.object-id-value-input {
    display: none !important;
}

.object-id-combobox {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
    width: 100%;
    min-height: 2.25rem;
    padding: 0.22rem 1.85rem 0.22rem 0.28rem;
    border: 1px solid color-mix(in srgb, #0891b2 45%, var(--pico-muted-border-color));
    border-radius: 6px;
    background: var(--pico-form-element-background-color, #fff);
    cursor: text;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.object-id-combobox:focus-within {
    border-color: #0891b2;
    box-shadow: 0 0 0 2px color-mix(in srgb, #22d3ee 22%, transparent);
}

.object-id-autocomplete-wrap.is-loading::after {
    content: "";
    position: absolute;
    top: 0.69rem;
    right: 0.6rem;
    width: 0.8rem;
    height: 0.8rem;
    border: 2px solid #a5f3fc;
    border-top-color: #0e7490;
    border-radius: 50%;
    animation: object-id-spin 0.7s linear infinite;
}

@keyframes object-id-spin {
    to { transform: rotate(360deg); }
}

.object-id-badges {
    display: contents;
}

.object-id-badge {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 0.28rem;
    max-width: min(390px, 100%);
    min-height: 1.62rem;
    padding: 0.1rem 0.15rem 0.1rem 0.38rem;
    border: 1px solid #67e8f9;
    border-radius: 4px;
    background: #ecfeff;
    color: #164e63;
    font-size: 0.7rem;
    line-height: 1.15;
}

.object-id-badge-id {
    flex: 0 0 auto;
    color: #0e7490;
    font-variant-numeric: tabular-nums;
}

.object-id-badge-name {
    display: inline-block !important;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 160px;
    overflow: hidden;
    color: #334155 !important;
    font-weight: 600;
    opacity: 1 !important;
    text-overflow: ellipsis;
    visibility: visible !important;
    white-space: nowrap;
}

.object-id-badge-region,
.object-id-option-region {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 1.15rem;
    padding: 0.06rem 0.28rem;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    background: #f8fafc;
    color: #475569;
    font-size: 0.61rem;
    font-weight: 750;
    line-height: 1;
    white-space: nowrap;
}

.object-id-badge-region.is-seoul,
.object-id-option-region.is-seoul {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.object-id-badge-region.is-hanoi,
.object-id-option-region.is-hanoi {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #15803d;
}

.object-id-badge-region.is-withdrawn,
.object-id-option-region.is-withdrawn {
    border-color: #fde68a;
    background: #fffbeb;
    color: #a16207;
}

.object-id-role-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 4.3rem !important;
    min-height: 1.2rem !important;
    margin: 0 !important;
    padding: 0.08rem 0.34rem !important;
    border-radius: 3px !important;
    font-size: 0.61rem !important;
    font-weight: 750 !important;
    line-height: 1 !important;
    white-space: nowrap;
}

.object-id-role-toggle.is-required {
    border: 1px solid #86efac !important;
    background: #f0fdf4 !important;
    color: #166534 !important;
}

.object-id-role-toggle.is-distractor {
    border: 1px solid #fdba74 !important;
    background: #fff7ed !important;
    color: #c2410c !important;
}

.object-id-role-toggle:hover,
.object-id-role-toggle:focus-visible {
    box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 20%, transparent) !important;
}

.object-id-role-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.72;
    box-shadow: none !important;
}

.object-id-count-control {
    display: inline-grid;
    grid-template-columns: 1.2rem 1.7rem 1.2rem;
    align-items: center;
    flex: 0 0 auto;
    min-height: 1.2rem;
    overflow: hidden;
    border: 1px solid #a5b4fc;
    border-radius: 3px;
    background: #eef2ff;
}

.object-id-count-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 1.2rem !important;
    height: 1.2rem !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #3730a3 !important;
    font-size: 0.82rem !important;
    font-weight: 800 !important;
    line-height: 1 !important;
}

.object-id-count-button:hover,
.object-id-count-button:focus-visible {
    background: #c7d2fe !important;
}

.object-id-count-button:disabled {
    color: #94a3b8 !important;
    cursor: default;
}

.object-id-count-input {
    width: 1.7rem !important;
    height: 1.2rem !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-right: 1px solid #c7d2fe !important;
    border-left: 1px solid #c7d2fe !important;
    border-radius: 0 !important;
    background: var(--pico-form-element-background-color, #fff) !important;
    color: var(--pico-color) !important;
    font-size: 0.66rem !important;
    font-variant-numeric: tabular-nums;
    font-weight: 750 !important;
    line-height: 1 !important;
    text-align: center;
    appearance: textfield;
}

.object-id-count-input::-webkit-inner-spin-button,
.object-id-count-input::-webkit-outer-spin-button {
    margin: 0;
    appearance: none;
}

.object-id-badge-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 1.22rem !important;
    height: 1.22rem !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 0 0.06rem !important;
    border: 0 !important;
    border-radius: 3px !important;
    background: transparent !important;
    color: #0e7490 !important;
    font-size: 1rem !important;
    line-height: 1 !important;
}

.object-id-badge-remove:hover,
.object-id-badge-remove:focus-visible {
    background: #cffafe !important;
    color: #9f1239 !important;
}

.object-id-search {
    flex: 1 1 150px;
    width: auto !important;
    min-width: 120px;
    min-height: 1.62rem !important;
    height: 1.62rem !important;
    margin: 0 !important;
    padding: 0 0.2rem !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--pico-color) !important;
    font-size: 0.74rem !important;
}

.object-id-search:focus {
    box-shadow: none !important;
}

.object-id-search::placeholder {
    color: color-mix(in srgb, var(--pico-muted-color) 82%, transparent);
}

.object-id-suggestion-list {
    position: absolute;
    z-index: 80;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    background: var(--pico-card-background-color);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
}

.object-id-suggestion-list[hidden] {
    display: none;
}

.object-id-suggestion-header,
.object-id-suggestion-empty {
    padding: 0.44rem 0.58rem;
    color: var(--pico-muted-color);
    font-size: 0.7rem;
}

.object-id-suggestion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    background: color-mix(in srgb, #ecfeff 55%, var(--pico-card-background-color));
}

.object-id-suggestion-header strong {
    color: #155e75;
    font-size: 0.7rem;
}

.object-id-suggestion-header small {
    color: var(--pico-muted-color);
    font-size: 0.66rem;
    font-weight: 600;
}

.object-id-suggestion-empty {
    display: block;
    line-height: 1.35;
}

button.object-id-suggestion {
    display: grid;
    grid-template-columns: minmax(90px, max-content) minmax(0, 1fr) max-content max-content;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: 2.45rem !important;
    margin: 0;
    padding: 0.42rem 0.58rem;
    border: 0 !important;
    border-bottom: 1px solid var(--pico-muted-border-color);
    border-radius: 0 !important;
    background: var(--pico-card-background-color) !important;
    color: var(--pico-color) !important;
    text-align: left;
    font-size: 0.76rem;
}

button.object-id-suggestion:last-child {
    border-bottom: 0;
}

button.object-id-suggestion:hover,
button.object-id-suggestion.is-active {
    background: #ecfeff !important;
    color: #164e63 !important;
}

button.object-id-suggestion.is-selected {
    background: #f0fdf4 !important;
    color: #166534 !important;
}

.object-id-option-id {
    display: inline-flex;
    align-items: center;
    min-height: 1.35rem;
    padding: 0.08rem 0.3rem;
    border: 1px solid #a5f3fc;
    border-radius: 3px;
    background: #ecfeff;
    color: #0e7490;
    font-variant-numeric: tabular-nums;
}

.object-id-option-name {
    display: block !important;
    min-width: 0;
    overflow: hidden;
    color: #334155 !important;
    font-weight: 600;
    opacity: 1 !important;
    text-overflow: ellipsis;
    visibility: visible !important;
    white-space: nowrap;
}

button.object-id-suggestion:hover .object-id-option-name,
button.object-id-suggestion.is-active .object-id-option-name,
button.object-id-suggestion.is-selected .object-id-option-name {
    color: #1f2937 !important;
}

.object-id-option-action {
    color: #0284c7;
    font-size: 0.65rem;
    font-weight: 800;
}

button.object-id-suggestion.is-selected .object-id-option-action {
    color: #15803d;
}

button.object-id-custom-distractor {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    min-height: 2.7rem !important;
    margin: 0;
    padding: 0.45rem 0.58rem;
    border: 0 !important;
    border-radius: 0 0 5px 5px !important;
    background: #fff7ed !important;
    color: #7c2d12 !important;
    text-align: left;
}

button.object-id-custom-distractor:hover,
button.object-id-custom-distractor:focus-visible {
    background: #ffedd5 !important;
    box-shadow: inset 3px 0 0 #f97316 !important;
}

.object-id-custom-distractor-label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 0.08rem;
}

.object-id-custom-distractor-label strong {
    color: #9a3412;
    font-size: 0.72rem;
}

.object-id-custom-distractor-label small {
    overflow: hidden;
    color: #7c2d12;
    font-size: 0.68rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.object-id-custom-distractor-role {
    flex: 0 0 auto;
    padding: 0.12rem 0.38rem;
    border: 1px solid #fdba74;
    border-radius: 3px;
    background: #ffffff;
    color: #c2410c;
    font-size: 0.62rem;
    font-weight: 800;
}

.object-id-thumbnail-preview {
    position: fixed;
    z-index: 1200;
    display: block;
    width: 224px;
    overflow: hidden;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.24);
    color: #1f2937;
    pointer-events: none;
}

.object-id-thumbnail-preview[hidden] {
    display: none;
}

.object-id-thumbnail-image {
    display: block;
    width: 100%;
    height: 168px;
    margin: 0;
    border: 0;
    background: #f8fafc;
    object-fit: contain;
}

.object-id-thumbnail-caption {
    display: flex;
    gap: 0.18rem;
    flex-direction: column;
    padding: 0.48rem 0.58rem 0.52rem;
    border-top: 1px solid #e2e8f0;
}

.object-id-thumbnail-caption strong {
    overflow: hidden;
    color: #1f2937;
    font-size: 0.74rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.object-id-thumbnail-caption small {
    color: #64748b;
    font-size: 0.64rem;
    font-weight: 650;
}

.object-id-thumbnail-unavailable {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4.25rem;
    padding: 0.65rem;
    color: #64748b;
    font-size: 0.7rem;
    text-align: center;
}

@media (max-width: 640px) {
    button.object-id-suggestion {
        grid-template-columns: max-content minmax(0, 1fr) max-content;
    }

    .object-id-option-action {
        display: none;
    }
}
