/**
 * Database Cleaner Admin Styles
 * Uses Switchboard CSS variables and design patterns
 */

/* Page Layout - uses sb-module-wrap from switchboard-admin.css */
.switchboard-database-cleaner {
    max-width: 1200px;
}

/* Tabs */
.dbcleaner-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
}

.dbcleaner-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s ease;
}

.dbcleaner-tab:hover {
    background: white;
    color: var(--primary-600);
}

.dbcleaner-tab.active {
    background: white;
    color: var(--primary-600);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dbcleaner-tab .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

/* Tab Content */
.dbcleaner-tab-content {
    display: none;
}

.dbcleaner-tab-content.active {
    display: block;
}

/* Category Cards */
.dbcleaner-category-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
}

.dbcleaner-category-card.collapsed .category-content {
    display: none;
}

.dbcleaner-category-card.collapsed .category-toggle {
    transform: rotate(-90deg);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.category-header:hover {
    background: var(--gray-50);
}

.category-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.category-icon {
    font-size: 20px;
}

.category-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-900);
}

.category-count {
    font-size: 13px;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 4px 10px;
    border-radius: 20px;
}

.category-toggle {
    color: var(--gray-400);
    transition: transform 0.2s ease;
}

.category-content {
    border-top: 1px solid var(--gray-100);
}

/* Cleanup Items */
.cleanup-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.2s ease;
}

.cleanup-item:last-child {
    border-bottom: none;
}

.cleanup-item:hover {
    background: var(--gray-50);
}

.item-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.item-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-300);
    border-radius: 4px;
    cursor: pointer;
    accent-color: var(--primary-500);
}

.item-info {
    flex: 1;
}

.item-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.item-description {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 2px;
}

.item-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 100px;
}

.item-count {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-700);
}

.item-size {
    font-size: 12px;
    color: var(--gray-500);
}

.item-clean-btn {
    min-width: 70px;
}

/* Risk Badges */
.risk-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.risk-badge.caution {
    background: #fef3c7;
    color: #b45309;
}

.risk-badge.risky {
    background: #fee2e2;
    color: #dc2626;
}

/* Bulk Actions */
.dbcleaner-bulk-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 0;
}

.dbcleaner-bulk-actions .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.dbcleaner-bulk-actions .button .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    line-height: 1;
}

/* Action buttons with icons */
.dbcleaner-action-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.dbcleaner-action-btn .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    line-height: 1;
}

/* Section Header */
.dbcleaner-section-header {
    margin-bottom: 20px;
}

.dbcleaner-section-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary-900);
    margin: 0 0 8px 0;
}

.dbcleaner-section-header .description {
    color: var(--gray-500);
    margin: 0;
}

/* Filters */
.dbcleaner-filters {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    margin-bottom: 0;
    align-items: center;
    border-bottom: 1px solid var(--primary-50);
}

.dbcleaner-filters input[type="text"] {
    flex: 1;
}

.dbcleaner-filters input[type="text"],
.dbcleaner-filters select,
.dbcleaner-filters .button {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}

.dbcleaner-filters select {
    min-width: 180px;
    padding-right: 28px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-color: white;
}

.dbcleaner-filters .button {
    background: white;
    color: var(--primary-600);
    border-color: var(--primary-500);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.dbcleaner-filters .button:hover {
    background: var(--primary-50);
    border-color: var(--primary-600);
}

.dbcleaner-filters input[type="text"]:focus,
.dbcleaner-filters select:focus {
    border-color: var(--primary-500);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-500-rgb), 0.1);
}

/* Loading state for tables */
.loading-cell {
    text-align: center;
    padding: 40px !important;
    color: var(--gray-500);
}

.loading-cell .spinner {
    float: none;
    margin-right: 8px;
}

/* Percent Bar */
.percent-bar {
    position: relative;
    height: 20px;
    background: var(--gray-100);
    border-radius: 4px;
    overflow: hidden;
}

.percent-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-400), var(--primary-500));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.percent-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-700);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge-yes {
    background: #dcfce7;
    color: #166534;
}

.badge-no {
    background: var(--gray-100);
    color: var(--gray-600);
}

/* Pagination */
.dbcleaner-pagination {
    margin-top: 16px;
    display: flex;
    justify-content: center;
}

.pagination-links {
    display: flex;
    gap: 4px;
}

.pagination-btn {
    min-width: 36px;
    text-align: center;
}

.pagination-btn.active {
    background: var(--primary-500);
    color: white;
    border-color: var(--primary-500);
}

/* Logs */
.dbcleaner-logs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.dbcleaner-log-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 20px;
}

.dbcleaner-log-card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-900);
    margin: 0 0 16px 0;
}

.log-list {
    max-height: 400px;
    overflow-y: auto;
}

.log-entries {
    list-style: none;
    margin: 0;
    padding: 0;
}

.log-entry {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: var(--gray-500);
}

.log-action {
    color: var(--gray-700);
}

.log-action strong {
    color: var(--primary-600);
}

.no-logs, .no-data {
    color: var(--gray-500);
    text-align: center;
    padding: 40px 0;
}

/* Size Chart */
.size-chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 200px;
    padding: 0 10px;
}

.chart-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.chart-bar {
    width: 100%;
    background: linear-gradient(180deg, var(--primary-400), var(--primary-600));
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.3s ease;
}

.chart-label {
    font-size: 10px;
    color: var(--gray-500);
    margin-top: 8px;
    white-space: nowrap;
    transform: rotate(-45deg);
    transform-origin: top left;
}

/* Spin animation for loading icons */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.dashicons.spin {
    animation: spin 1s linear infinite;
}

/* Settings Tab - 2 Column Row */
.dbcleaner-settings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Schedule Radio Buttons */
.dbcleaner-schedule-radios {
    display: flex;
    gap: 8px;
}

.dbcleaner-radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dbcleaner-radio-label:hover {
    background: var(--primary-50);
    border-color: var(--primary-200);
}

.dbcleaner-radio-label:has(input:checked) {
    background: var(--primary-50);
    border-color: var(--primary-500);
}

.dbcleaner-radio-label span {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.dbcleaner-radio-label:has(input:checked) span {
    color: var(--primary-700);
}

/* Settings Tab - Schedule Options (3 columns) */
.dbcleaner-schedule-options {
    grid-template-columns: repeat(3, 1fr) !important;
}

/* Settings Tab - Items Grid (4 columns) */
.dbcleaner-items-grid {
    grid-template-columns: repeat(4, 1fr) !important;
}

/* Performance Settings - Batch Size Row */
.dbcleaner-batch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.dbcleaner-batch-label {
    flex: 1;
}

.dbcleaner-batch-label .sb-module-form-label {
    margin-bottom: 4px;
}

.dbcleaner-batch-label .sb-module-form-help {
    margin: 0;
}

/* Info text below controls */
.dbcleaner-info-text {
    margin: 16px 0 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
    font-size: 12px;
    color: var(--gray-500);
    line-height: 1.5;
}

/* Size History Chart - ensure minimum bar width */
.size-chart-bars {
    min-height: 180px;
}

.chart-bar-wrapper {
    min-width: 30px;
    max-width: 60px;
}

/* Toast */
.dbcleaner-toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 100000;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.dbcleaner-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.dbcleaner-toast .toast-icon {
    font-size: 18px;
    font-weight: 600;
}

.dbcleaner-toast .toast-message {
    font-size: 14px;
    color: var(--gray-800);
}

.dbcleaner-toast.success {
    border-left: 4px solid #22c55e;
}

.dbcleaner-toast.success .toast-icon {
    color: #22c55e;
}

.dbcleaner-toast.error {
    border-left: 4px solid #dc2626;
}

.dbcleaner-toast.error .toast-icon {
    color: #dc2626;
}

.dbcleaner-toast.warning {
    border-left: 4px solid #f59e0b;
}

.dbcleaner-toast.warning .toast-icon {
    color: #f59e0b;
}

.dbcleaner-toast.info {
    border-left: 4px solid var(--primary-500);
}

.dbcleaner-toast.info .toast-icon {
    color: var(--primary-500);
}

/* Responsive */
@media (max-width: 1024px) {
    .dbcleaner-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dbcleaner-logs-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .switchboard-database-cleaner .switchboard-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .dbcleaner-stats-grid {
        grid-template-columns: 1fr;
    }

    .dbcleaner-tabs {
        flex-wrap: wrap;
    }

    .cleanup-item {
        flex-wrap: wrap;
    }

    .item-stats {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        margin-top: 8px;
    }

    .item-clean-btn {
        width: 100%;
        margin-top: 8px;
    }

    .dbcleaner-filters {
        flex-wrap: wrap;
    }

    .dbcleaner-filters input[type="text"] {
        width: 100%;
    }
}
