/* =========================================
   THX_EC GENERAL SETTINGS PANEL
   ========================================= */

.thx-ec-general-settings-panel {
    position: fixed;

    /* [CẬP NHẬT] Căn giữa màn hình */
    top: 50%;
    left: 60px;
    /* Cách lề trái 60px để không đè lên nút bấm */
    right: auto;
    bottom: auto;
    margin-top: 0;

    width: 320px;
    max-width: calc(100vw - 80px);
    max-height: 420px;

    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    z-index: 9999;

    /* [Trạng thái ẨN] */
    opacity: 0;
    visibility: hidden;
    /* Dịch xuống một chút (-45%) và thu nhỏ để tạo hiệu ứng trồi lên */
    transform: translateY(-45%) scale(0.95);

    user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* [Trạng thái HIỆN] */
.thx-ec-general-settings-panel.is-open {
    opacity: 1;
    visibility: visible;
    /* Căn giữa hoàn hảo theo chiều dọc */
    transform: translateY(-50%) scale(1);
}

/* HEADER */
.thx-ec-gs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f6;
    background: #fff;
    border-radius: 12px 12px 0 0;
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

.thx-ec-general-settings-panel.is-saving .thx-ec-gs-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--tv-accent, #4A5D23) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: thxEcLoadingScan 1.5s infinite linear;
    z-index: 10;
    pointer-events: none;
}

.thx-ec-gs-header span {
    font-weight: 700;
    font-size: 14px;
    color: #111827;
}

.thx-ec-gs-close-btn {
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.2s;
    padding: 0;
}

.thx-ec-gs-close-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

.thx-ec-gs-close-btn:hover {
    background-color: var(--tv-accent, #4A5D23);
    color: #ffffff;
    transform: rotate(90deg);
}

/* TABS */
.thx-ec-gs-tabs {
    display: flex;
    background: #f9fafb;
    padding: 4px 4px 0;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.thx-ec-gs-tab-btn {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.thx-ec-gs-tab-btn:hover {
    color: var(--tv-accent, #4A5D23);
    background: rgba(0, 0, 0, 0.02);
}

.thx-ec-gs-tab-btn.active {
    color: var(--tv-accent, #4A5D23);
    border-bottom-color: var(--tv-accent, #4A5D23);
    background: #ffffff;
    border-radius: 6px 6px 0 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.02);
}

/* BODY & SCROLL */
.thx-ec-gs-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    background: #fff;
    border-radius: 0 0 12px 12px;
    min-height: 100px;
    position: relative;
    z-index: 10;
}

.thx-ec-gs-body::-webkit-scrollbar {
    width: 4px;
}

.thx-ec-gs-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

.thx-ec-gs-tab-pane {
    display: none;
    padding: 12px;
    animation: fadeInSmooth 0.3s ease-in-out;
}

.thx-ec-gs-tab-pane.active {
    display: block;
}

/* STANDARD ROW */
.thx-ec-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 8px;
    border-bottom: 1px dashed #f0f0f0;
    gap: 10px;
    cursor: pointer;
    transition: background-color 0.1s;
    border-radius: 6px;
    position: relative;
}

.thx-ec-toggle-row:hover {
    background-color: #f9fafb;
}

.thx-ec-toggle-row:last-child {
    border-bottom: none;
}

/* CHILD ROW */
.thx-ec-toggle-row.thx-ec-is-child {
    margin-left: 24px;
    padding-left: 8px;
    background-color: rgba(249, 250, 251, 0.5);
    position: relative;
    overflow: visible;
    border-left: 1px solid transparent;
    width: auto;
}

.thx-ec-toggle-row.thx-ec-is-child::before {
    content: "↳";
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 16px;
    font-weight: bold;
    pointer-events: none;
    line-height: 1;
}

.thx-ec-toggle-row.thx-ec-disabled {
    opacity: 0.6;
    pointer-events: none;
}

.thx-ec-toggle-row.thx-ec-is-overridden {
    opacity: 1;
    pointer-events: auto;
    cursor: not-allowed;
    background: #f9fafb;
}

.thx-ec-toggle-row.thx-ec-is-overridden .thx-ec-row-label {
    color: #9ca3af;
}

.thx-ec-toggle-row.thx-ec-is-overridden .thx-ec-control-wrapper {
    opacity: 0.5;
    pointer-events: none;
}

.thx-ec-toggle-row.thx-ec-is-overridden .thx-ec-info-icon {
    opacity: 1;
    pointer-events: auto;
    cursor: help;
}

/* LABELS & CONTROLS */
.thx-ec-row-label {
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    flex: 1;
    display: flex;
    align-items: center;
}

.thx-ec-control-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ICON INFO */
.thx-ec-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: #e5e7eb;
    color: #6b7280;
    border-radius: 50%;
    font-size: 9px;
    font-weight: 700;
    font-family: serif;
    margin-left: 5px;
    cursor: help;
    flex-shrink: 0;
    position: static;
}

.thx-ec-info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 280px;
    background: #1f2937;
    color: #fff;
    font-family: sans-serif;
    font-size: 11px;
    line-height: 1.4;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
    white-space: normal;
    text-align: center;
    margin-bottom: 8px;
}

.thx-ec-info-icon:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.thx-ec-info-icon::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    margin-bottom: 3px;
    border-width: 5px;
    border-style: solid;
    border-color: #1f2937 transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 100000;
}

.thx-ec-info-icon:hover::before {
    opacity: 1;
    visibility: visible;
}

/* COMPONENTS */
.thx-ec-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
    margin: 0;
}

.thx-ec-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.thx-ec-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e5e7eb;
    transition: .4s;
    border-radius: 20px;
}

.thx-ec-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

input:checked+.thx-ec-slider {
    background-color: var(--tv-accent, #4A5D23);
}

input:checked+.thx-ec-slider:before {
    transform: translateX(14px);
}

.thx-ec-gs-slider {
    width: 130px;
    height: 24px;
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
    touch-action: none;
    margin-right: 0;
}

.thx-ec-gs-slider.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.thx-ec-gs-slider-track {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    position: relative;
}

.thx-ec-gs-slider-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: #bef264;
    border-radius: 2px;
    pointer-events: none;
    z-index: 1;
}

.thx-ec-gs-slider-tick {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #9ca3af;
    border-radius: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 0;
    pointer-events: none;
}

.thx-ec-gs-slider-tick.is-active {
    background: #15803d;
    z-index: 2;
    transform: translate(-50%, -50%) scale(1.2);
}

.thx-ec-gs-slider-thumb {
    position: absolute;
    width: 16px;
    height: 16px;
    background: #ffffff;
    border: 2px solid #bef264;
    border-radius: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    z-index: 3;
    transition: left 0.1s, transform 0.1s;
}

.thx-ec-gs-slider:hover .thx-ec-gs-slider-thumb,
.thx-ec-gs-slider.is-dragging .thx-ec-gs-slider-thumb {
    transform: translate(-50%, -50%) scale(1.15);
}

.thx-ec-gs-slider.is-dragging .thx-ec-gs-slider-thumb {
    transition: none;
}

.thx-ec-gs-slider-tooltip {
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(var(--tooltip-shift, -50%)) translateY(5px);
    background-color: #1f2937;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s, transform 0.1s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    z-index: 10000;
}

.thx-ec-gs-slider-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: var(--arrow-pos, 50%);
    margin-left: -4px;
    border-width: 4px;
    border-style: solid;
    border-color: #1f2937 transparent transparent transparent;
    transition: left 0.1s;
}

.thx-ec-gs-slider:hover .thx-ec-gs-slider-tooltip,
.thx-ec-gs-slider.is-dragging .thx-ec-gs-slider-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(var(--tooltip-shift, -50%)) translateY(0);
}

.thx-ec-select {
    padding: 4px 24px 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    color: #374151;
    outline: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat right 4px center/16px;
    appearance: none;
}

.thx-ec-shortcuts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #e5e7eb;
}

.thx-ec-shortcuts-grid .thx-ec-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    border: 1px solid #f3f4f6;
    border-radius: 6px;
    background: #fff;
    padding: 6px 8px;
    gap: 8px;
    transition: border-color 0.2s;
}

.thx-ec-shortcuts-grid .thx-ec-toggle-row:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

.thx-ec-shortcuts-grid .thx-ec-toggle-row.thx-ec-is-child {
    border-left: 2px solid #e5e7eb;
}

.thx-ec-shortcuts-grid .thx-ec-row-label {
    flex: 1;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    font-size: 13px;
    line-height: 1.4;
    color: #374151;
}

.thx-ec-key-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 20px;
    padding: 0 4px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-bottom-width: 2px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    line-height: 1;
    white-space: nowrap;
}

.thx-ec-key-badge svg {
    width: 12px;
    height: 12px;
    display: block;
    stroke-width: 2.5;
}

.thx-ec-key-plus {
    margin: 0 1px;
    color: #94a3b8;
    font-size: 10px;
}

.thx-ec-key-divider {
    margin: 0 4px;
    color: #cbd5e1;
    font-weight: 300;
}

.thx-ec-shortcuts-grid .thx-ec-info-icon {
    margin-left: 6px;
    background: transparent;
    border: 1px solid #e2e8f0;
    color: #94a3b8;
}

/* FLOATING BUTTONS */
.thx-ec-floating-btn,
.thx-ec-sidebar-toggle-btn {
    position: fixed;
    left: 0;
    right: auto;
    top: 50% !important;
    bottom: auto !important;
    width: 42px;
    height: 42px;
    border-radius: 0 8px 8px 0;
    background: #fff;
    color: #555;
    border: 1px solid #e0e0e0;
    border-left: none;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    z-index: 190;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease, visibility 0.3s, width 0.2s ease, background 0.2s;
    padding: 0 !important;
    outline: none;
}

.thx-ec-floating-btn.is-visible,
.thx-ec-sidebar-toggle-btn.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.thx-ec-floating-btn:hover,
.thx-ec-sidebar-toggle-btn:hover {
    width: 52px;
    background: #f9f9f9;
    color: var(--tv-accent, #4A5D23);
    box-shadow: 4px 2px 12px rgba(0, 0, 0, 0.15);
}

.thx-ec-floating-btn svg,
.thx-ec-sidebar-toggle-btn svg {
    width: 22px;
    height: 22px;
    stroke-width: 2;
    transition: transform 0.4s ease;
}

.thx-ec-floating-btn:hover svg {
    transform: rotate(90deg);
}

/* XẾP CHỒNG (TOC trên, GSP dưới) */
.thx-ec-sidebar-toggle-btn {
    margin-top: -24px;
}

#thx-ec-general-settings-trigger.thx-ec-floating-btn {
    margin-top: 24px;
}

/* Mobile Hiding */
body.showing-popup-drawer-from-right .thx-ec-floating-btn,
body.showing-popup-drawer-from-left .thx-ec-floating-btn,
body.kadence-drawer-open .thx-ec-floating-btn,
body.showing-popup-drawer-from-right .thx-ec-sidebar-toggle-btn,
body.showing-popup-drawer-from-left .thx-ec-sidebar-toggle-btn,
body.kadence-drawer-open .thx-ec-sidebar-toggle-btn {
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateX(-100%) !important;
}

@keyframes thxEcLoadingScan {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@keyframes fadeInSmooth {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive for floating buttons on mobile */
@media (max-width: 768px) {

    .thx-ec-general-settings-panel {
        left: 42px !important;
        /* Đẩy panel sát lại nút mở (width 32px) */
    }

    .thx-ec-floating-btn,
    .thx-ec-sidebar-toggle-btn {
        width: 32px !important;
        height: 44px !important;
    }

    .thx-ec-floating-btn.is-visible,
    .thx-ec-sidebar-toggle-btn.is-visible {
        opacity: 0.5 !important;
    }

    .thx-ec-floating-btn:active,
    .thx-ec-sidebar-toggle-btn:active {
        opacity: 1 !important;
    }

    .thx-ec-floating-btn svg,
    .thx-ec-sidebar-toggle-btn svg {
        width: 18px !important;
        height: 18px !important;
    }

    .thx-ec-sidebar-toggle-btn {
        margin-top: -25px !important;
    }

    #thx-ec-general-settings-trigger.thx-ec-floating-btn {
        margin-top: 25px !important;
    }
}