/* ============================================================================
   Archive Modal — two-column "Manage Studies" workspace
   Drag-and-drop between Active and Archived columns.
   ============================================================================ */

.archive-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10200;
    padding: 1rem;
}
.archive-modal-backdrop.visible {
    display: flex;
}

.archive-modal {
    background: var(--surface, #fff);
    color: var(--text-primary, #2a2621);
    width: min(920px, 100%);
    max-height: 90vh;
    border-radius: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
}

.archive-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border, #e2e8f0);
}
.archive-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}
.archive-close-btn {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary, #6B5D54);
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}
.archive-close-btn:hover {
    background: var(--background, #FAF9F6);
    color: var(--text-primary, #2a2621);
}

.archive-modal-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.archive-column {
    display: flex;
    flex-direction: column;
    background: var(--background, #FAF9F6);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    min-height: 0;
    overflow: hidden;
}
.archive-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.85rem;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--border, #e2e8f0);
    font-weight: 600;
    font-size: 0.9rem;
}
.archive-column-title {
    color: var(--text-primary, #2a2621);
}
.archive-column-count {
    display: inline-block;
    min-width: 1.4rem;
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e2e8f0);
    color: var(--text-secondary, #6B5D54);
    font-size: 0.8rem;
    text-align: center;
}

.archive-column-list {
    flex: 1;
    min-height: 160px;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    transition: background 0.15s ease;
}
.archive-column-list.drop-target {
    background: rgba(91, 75, 138, 0.08);
    outline: 2px dashed var(--primary, #5B4B8A);
    outline-offset: -6px;
}

.archive-empty {
    padding: 1.25rem 0.5rem;
    text-align: center;
    color: var(--text-secondary, #6B5D54);
    font-size: 0.9rem;
    font-style: italic;
}

.archive-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    cursor: grab;
    transition: box-shadow 0.15s ease, opacity 0.15s ease;
    min-height: 32px;
}
.archive-row:active { cursor: grabbing; }
.archive-row:hover  { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06); }
.archive-row.dragging { opacity: 0.4; }

/* Currently-open study — disabled from move/delete to prevent state confusion.
   Rename input stays interactive (renaming is safe). */
.archive-row.is-current {
    cursor: default;
    background: var(--background, #FAF9F6);
    border-color: var(--primary, #5B4B8A);
    border-style: dashed;
}
.archive-row.is-current .archive-row-meta {
    color: var(--primary, #5B4B8A);
    font-weight: 600;
    font-style: italic;
}
.archive-row.is-current .archive-row-move[disabled],
.archive-row.is-current .archive-row-delete[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: auto; /* keep tooltip working */
}
.archive-row.is-current .archive-row-move[disabled]:hover,
.archive-row.is-current .archive-row-delete[disabled]:hover {
    background: none;
    color: var(--text-secondary, #6B5D54);
    border-color: var(--border, #e2e8f0);
}

.archive-row-body {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.archive-row-name {
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    background: transparent;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #2a2621);
    outline: none;
    text-overflow: ellipsis;
}
.archive-row-name:hover:not(:focus) {
    border-color: var(--border, #e2e8f0);
    background: var(--background, #FAF9F6);
    cursor: text;
}
.archive-row-name:focus {
    border-color: var(--primary, #5B4B8A);
    background: var(--surface);
}
.archive-row-meta {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-secondary, #6B5D54);
    white-space: nowrap;
}

.archive-row-actions {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    flex-shrink: 0;
}
.archive-row-move,
.archive-row-delete {
    width: 22px;
    height: 22px;
    background: none;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--text-secondary, #6B5D54);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.archive-row-move:hover {
    background: var(--primary, #5B4B8A);
    color: #fff;
    border-color: var(--primary, #5B4B8A);
}
.archive-row-delete:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.archive-modal-hint {
    padding: 0.55rem 1.25rem 0.85rem;
    text-align: center;
    color: var(--text-secondary, #6B5D54);
    font-size: 0.8rem;
    border-top: 1px solid var(--border, #e2e8f0);
    background: var(--background, #FAF9F6);
}
.archive-hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
    .archive-hint-desktop { display: none; }
    .archive-hint-touch { display: inline; }
}

/* Tablet / small laptop — keep two columns but shrink chrome slightly */
@media (max-width: 900px) {
    .archive-modal { width: 100%; max-height: 95vh; }
    .archive-modal-columns { gap: 0.5rem; padding: 0.5rem; }
    .archive-row-meta { display: none; }  /* meta first to drop when space tight */
}

/* Mobile: stack columns vertically */
@media (max-width: 700px) {
    .archive-modal-columns {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
    .archive-column-list { max-height: 35vh; }
    .archive-modal-header { padding: 0.75rem 1rem; }
    .archive-modal-header h2 { font-size: 1rem; }
    .archive-modal-hint {
        padding: 0.5rem 0.75rem;
        font-size: 0.7rem;
    }
}

/* Small phones (iPhone SE etc.) — ensure single-line rows still work */
@media (max-width: 400px) {
    .archive-row {
        padding: 0.3rem 0.4rem;
        gap: 0.35rem;
    }
    .archive-row-name { font-size: 0.8rem; }
    .archive-row-move,
    .archive-row-delete {
        width: 26px;   /* larger tap target on touch */
        height: 26px;
    }
    /* Touch users can't drag reliably — show move/delete buttons more prominently */
    .archive-column-list { padding: 0.35rem; }
}

/* Touch devices at any width: disable native drag (unreliable on touch) and
   rely on the arrow button. Also enlarge tap targets. */
@media (hover: none) and (pointer: coarse) {
    .archive-row { cursor: default; }
    .archive-row-move,
    .archive-row-delete {
        width: 28px;
        height: 28px;
    }
    .archive-modal-hint::after {
        content: '';
    }
}

/* ============================================================================
   Confirm-Delete submodal
   ============================================================================ */
.archive-confirm-backdrop,
.archive-cap-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    /* 10650: must beat the reading modals (harmony/ISBE/library/intro at
       10200-10250) and the study gate (10600) — the cap dialog can fire
       from a send inside any of them and must never be buried (BUG-010
       sibling). Below signed-out toast 10700 and dialogs 25000. */
    z-index: 10650;
    padding: 1rem;
}
.archive-confirm,
.archive-cap {
    background: var(--surface, #fff);
    color: var(--text-primary, #2a2621);
    width: min(420px, 100%);
    border-radius: 10px;
    padding: 1.25rem 1.4rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.archive-confirm h3,
.archive-cap h3 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 700;
}
.archive-confirm p,
.archive-cap p {
    margin: 0 0 1rem;
    color: var(--text-secondary, #6B5D54);
    font-size: 0.9rem;
    line-height: 1.4;
}
.archive-confirm-actions,
.archive-cap-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.archive-confirm-cancel,
.archive-cap-close {
    background: var(--background, #FAF9F6);
    color: var(--text-primary, #2a2621);
    border: 1px solid var(--border, #e2e8f0);
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
}
.archive-confirm-cancel:hover,
.archive-cap-close:hover {
    background: var(--surface);
}
.archive-confirm-delete {
    background: var(--danger);
    color: #fff;
    border: 1px solid var(--danger);
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
}
.archive-confirm-delete:hover { background: var(--danger);
    filter: brightness(0.85); }

.archive-cap-upgrade {
    background: var(--primary, #5B4B8A);
    color: #fff;
    border: 1px solid var(--primary, #5B4B8A);
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
}
.archive-cap-upgrade:hover { filter: brightness(0.92); }
