/* ─── Manage Panel ─────────────────────────────────────────────────── */
.manage-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.manage-panel.show {
    display: flex;
}
.manage-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.manage-panel-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: 1rem;
    width: 95%;
    max-width: 1000px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.3s ease;
    display: flex;
    flex-direction: column;
}
.manage-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
}
.manage-panel-header h3 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin: 0;
}
.manage-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.2s;
    background: none;
    border: none;
}
.manage-panel-close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* Tabs */
.manage-tabs {
    display: flex;
    gap: 0;
    padding: 0 2rem;
    border-bottom: 1px solid var(--border-color);
    background: white;
}
.manage-tab {
    padding: 0.875rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.manage-tab:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}
.manage-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.tool-sub-tab {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -2px;
}
.tool-sub-tab:hover { color: var(--text-primary); }
.tool-sub-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.manage-tab-badge {
    display: inline-block;
    background: #EF4444;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 1rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

/* Tab content */
.manage-content {
    padding: 1.5rem 2rem 2rem;
    min-height: 300px;
    overflow-y: auto;
    flex: 1;
}

/* Tables */
.manage-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.manage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.manage-table th,
.manage-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.manage-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
    white-space: nowrap;
}
.manage-table td {
    color: var(--text-primary);
}
.manage-table tbody tr:hover {
    background: rgba(45, 125, 125, 0.04);
}

/* Action buttons inside manage panel */
.manage-btn {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.manage-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.manage-btn-danger {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #EF4444;
    background: transparent;
    color: #EF4444;
}
.manage-btn-danger:hover {
    background: #FEE2E2;
}
.manage-btn-primary {
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: var(--primary-color);
    color: white;
}
.manage-btn-primary:hover {
    background: var(--primary-color-dark);
}

/* Pagination */
.manage-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.manage-pagination button {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
}
.manage-pagination button:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.manage-pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Empty state */
.manage-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}
.manage-empty p {
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* Collections split layout */
.manage-data-layout {
    display: flex;
    gap: 1.5rem;
    min-height: 300px;
}
.collection-list {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.collection-card {
    padding: 0.875rem 1rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.collection-card:hover {
    border-color: var(--primary-color);
}
.collection-card.active {
    border-color: var(--primary-color);
    background: rgba(45, 125, 125, 0.06);
    border-left: 3px solid var(--primary-color);
}
.collection-card-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}
.collection-card-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.collection-card-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
}
/* Site-wide sensitive data toggle */
.sensitive-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}
.sensitive-label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
}
.sensitive-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.sensitive-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}
.sensitive-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.sensitive-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    border-radius: 22px;
    transition: background 0.2s;
}
.sensitive-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.sensitive-switch input:checked + .sensitive-slider {
    background: var(--primary-color);
}
.sensitive-switch input:checked + .sensitive-slider::before {
    transform: translateX(18px);
}
.collection-items-area {
    flex: 1;
    min-width: 0;
}
.collection-items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.collection-items-header h4 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0;
}

/* Form status badges */
.form-status-unread {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #3B82F6;
    margin-right: 0.4rem;
    vertical-align: middle;
}
.form-status-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
}
.form-status-badge.spam {
    background: #FEE2E2;
    color: #DC2626;
}
.form-status-badge.read {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Form submission detail row */
.form-detail-row td {
    padding: 1rem 1.5rem !important;
    background: var(--bg-tertiary);
}
.form-detail-content {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1.5rem;
    font-size: 0.875rem;
}
.form-detail-key {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: capitalize;
}
.form-detail-value {
    color: var(--text-primary);
    word-break: break-word;
}

/* Form filter buttons */
.manage-filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.manage-filter-btn {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 2rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.manage-filter-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.manage-filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Clickable form row cursor */
.form-row-clickable {
    cursor: pointer;
}
.form-row-clickable:hover {
    background: rgba(45, 125, 125, 0.04);
}


/* Confirm dialog overlay */
.manage-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.manage-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}
.manage-confirm-box {
    position: relative;
    background: var(--bg-primary);
    border-radius: 0.75rem;
    padding: 2rem;
    max-width: 450px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.manage-confirm-box p {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}
.manage-confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

/* Loading spinner for manage panel */
.manage-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}
.manage-loading .loading-spinner {
    width: 36px;
    height: 36px;
    margin-bottom: 0.75rem;
}

/* ─── Mobile Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .manage-panel {
        padding: 0;
    }
    .manage-panel-content {
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        max-height: 100dvh;
        height: 100dvh;
    }
    .manage-panel-header {
        padding: 1rem 1.25rem;
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        z-index: 10;
    }
    .manage-panel-header h3 {
        font-size: 1.25rem;
    }
    .manage-panel-close {
        width: 44px;
        height: 44px;
    }
    .manage-tabs {
        padding: 0 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: sticky;
        top: 60px;
        background: white;
        z-index: 9;
    }
    .manage-tab {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
    }
    .manage-content {
        padding: 1rem;
        min-width: 0;
        overflow-x: hidden;
    }
    /* Allow explainer tables/wide content to scroll horizontally */
    #toolSubContent > div {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Data tab: collection list becomes horizontal scroll */
    .manage-data-layout {
        flex-direction: column;
        gap: 1rem;
    }
    .collection-list {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }
    .collection-card {
        min-width: 140px;
        flex-shrink: 0;
        padding: 0.75rem;
    }

    /* Tables: convert to card layout on mobile */
    .manage-table-wrap {
        margin: 0;
        padding: 0;
        overflow-x: visible;
    }
    .manage-table {
        display: block;
    }
    .manage-table thead {
        display: none;
    }
    .manage-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    .manage-table tbody tr {
        display: flex;
        flex-direction: column;
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 0.75rem;
        padding: 1rem;
        gap: 0.5rem;
    }
    .manage-table tbody tr:hover {
        background: white;
    }
    .manage-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0;
        border-bottom: none;
        font-size: 0.875rem;
    }
    .manage-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.8rem;
        flex-shrink: 0;
        margin-right: 1rem;
    }
    .manage-table td:last-child {
        padding-top: 0.75rem;
        margin-top: 0.25rem;
        border-top: 1px solid var(--border-color);
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .manage-table td[style*="white-space"] {
        white-space: normal !important;
    }

    /* Buttons: touch-friendly sizing */
    .manage-btn,
    .manage-btn-danger {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        touch-action: manipulation;
    }
    .manage-btn-primary {
        min-height: 44px;
        touch-action: manipulation;
    }
    .manage-filter-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Pagination touch targets */
    .manage-pagination button {
        min-height: 44px;
        padding: 0.5rem 1.25rem;
        font-size: 0.85rem;
        touch-action: manipulation;
    }

    /* Form detail grid: single column on mobile */
    .form-detail-content {
        grid-template-columns: 1fr;
        gap: 0.25rem 0;
    }
    .form-detail-row td {
        padding: 0.75rem 1rem !important;
    }

    /* Collection items header stacks on mobile */
    .collection-items-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .collection-items-header .manage-btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* Confirm dialog mobile sizing */
    .manage-confirm-box {
        padding: 1.5rem;
        width: 95%;
    }
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
