/* ============================================================
 * DASHBOARD PAGE — Toggle, Settings, Donut, Plan Stats, R2 Slider
 * ============================================================ */

/* Công tắc bật/tắt */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border-primary, #ccc);
    border-radius: 20px;
    transition: background 0.25s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--color-success, #22c55e);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(16px);
}

/* Dòng cài đặt nội tuyến */
.setting-inline-row {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

.setting-inline-top {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.setting-inline-title {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}

.setting-inline-input {
    flex: 1;
    min-width: 0;
    padding: 0 10px !important;
    border: 1px solid var(--border-primary) !important;
    border-radius: var(--radius-md) !important;
    background: var(--bg-primary) !important;
    font-size: 14px;
    text-align: center;
    height: 34px !important;
    line-height: 34px !important;
    width: auto !important;
}

.setting-inline-top .btn {
    flex: 0 0 auto;
    width: auto !important;
    height: 34px !important;
    line-height: 34px !important;
    padding: 0 12px !important;
    margin-top: 0 !important;
    display: inline-flex;
    align-items: center;
}

.setting-inline-desc {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    line-height: 1.4;
}

/* Xem trước giá gói */
.plan-price-preview {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--color-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============================================================
 * DONUT CHART — Overview Tab
 * ============================================================ */
.donut-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.donut-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg, 12px);
    border: 1px solid var(--border-primary);
}

.donut-card h4 {
    margin: 0 0 14px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.donut-wrap {
    position: relative;
    width: 120px;
    height: 120px;
}

.donut-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--bg-tertiary);
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.donut-pct {
    font-size: 20px;
    font-weight: 800;
    line-height: 1;
    color: var(--text-primary);
}

.donut-sub {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.donut-legend {
    width: 100%;
    margin-top: 14px;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    padding: 3px 0;
    color: var(--text-secondary);
}

.donut-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.donut-legend-item span:last-child {
    margin-left: auto;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    max-width: 50%;
    text-align: right;
}

/* ============================================================
 * Current Plan Card
 * ============================================================ */
.current-plan-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--color-primary), #2563eb);
    color: #fff;
    margin-bottom: 20px;
}

.current-plan-header .plan-name-block {
    display: flex;
    align-items: center;
    gap: 10px;
}

.current-plan-header .plan-name-block h4 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
}

.current-plan-header .plan-name-block .plan-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.current-plan-header .plan-expiry {
    font-size: 0.8rem;
    opacity: 0.9;
    text-align: right;
    line-height: 1.5;
}

.current-plan-header .plan-expiry strong {
    color: #fff;
}

.plan-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.plan-stat-item {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: center;
    border: 1px solid var(--border-primary);
    transition: border-color var(--transition-base);
}

.plan-stat-item:hover { border-color: var(--color-primary); }

.plan-stat-item .stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.plan-stat-item .stat-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.plan-stat-item .stat-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.plan-stat-item .stat-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width var(--transition-slow);
}

.plan-actions-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--border-primary);
    flex-wrap: wrap;
}

.plan-actions-footer .renewal-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.plan-actions-footer .renewal-section .renewal-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.plan-actions-footer .renewal-section .renewal-status {
    font-size: 0.75rem;
    font-weight: 600;
}

/* ============================================================
 * R2 Refresh & Slider
 * ============================================================ */
.r2-refresh-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0;
    font-size: 10px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.2s, opacity 0.2s;
    opacity: 0.4;
}

.r2-refresh-btn:hover {
    color: var(--color-primary);
    opacity: 1;
}

@keyframes r2Spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.r2-spin {
    animation: r2Spin 0.8s linear infinite;
    pointer-events: none;
    opacity: 1 !important;
    color: var(--color-primary) !important;
}

.r2-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.r2-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    border: none !important;
    padding: 0 !important;
}

.r2-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.r2-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.r2-slider-val {
    width: 52px !important;
    min-width: 52px;
    padding: 4px 4px !important;
    border: 1px solid var(--border-primary) !important;
    border-radius: 4px !important;
    background: var(--bg-tertiary) !important;
    color: var(--text-primary);
    font-size: 12px !important;
    text-align: center;
}

.r2-slider-val::-webkit-inner-spin-button,
.r2-slider-val::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.r2-slider-unit {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    min-width: 18px;
}

/* ============================================================
 * RESPONSIVE — Dashboard Page
 * ============================================================ */
@media (max-width: 900px) {
    .donut-row {
        grid-template-columns: 1fr;
    }

    .donut-card {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        overflow: hidden;
    }

    .donut-card h4 {
        width: 100%;
        margin-bottom: 0;
    }

    .donut-wrap {
        width: 90px;
        height: 90px;
        flex-shrink: 0;
    }

    .donut-center {
        width: 56px;
        height: 56px;
    }

    .donut-pct {
        font-size: 16px;
    }

    .donut-legend {
        flex: 1;
        margin-top: 0;
        min-width: 0;
        overflow: hidden;
    }

    .donut-legend-item {
        min-width: 0;
    }

    .donut-legend-item span:nth-child(2) {
        flex-shrink: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .plan-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .current-plan-header {
        flex-direction: column;
        text-align: center;
    }

    .current-plan-header .plan-expiry {
        text-align: center;
    }

    .plan-actions-footer {
        flex-direction: column;
        align-items: stretch;
    }
}
