/* ==================== Config Page Styles ==================== */

.config-page {
    --settings-card-body-gap: 1.5rem;
    --settings-grid-gap: 0.75rem;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--settings-card-body-gap);
}

/* Import styles từ index.css cho file-config */
.file-config-wrapper {
    margin-top: 0;
    padding-top: 0;
    overflow: visible;
}

.file-config-content {
    overflow: visible;
}

.file-config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--settings-grid-gap);
    align-items: start;
}

.file-config-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
    overflow: visible;
    position: relative;
}

.file-config-group label {
    font-size: 0.9rem;
    color: #495057;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    flex-wrap: nowrap;
}

.file-config-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--control-border);
    border-radius: 6px;
    font-size: 0.95rem;
    line-height: 1.2;
    min-height: calc(0.5rem * 2 + 1.2em);
    width: 100%;
    background-color: var(--control-bg);
    color: var(--control-text);
    box-sizing: border-box;
}


.config-page select.file-config-input:not([multiple]):not(.settings-native-select-hidden) {
    opacity: 0;
    pointer-events: none;
}

.settings-native-select-hidden {
    display: none !important;
}

.settings-native-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.settings-native-select.open {
    z-index: 10002;
}

.settings-native-select-trigger {
    width: 100%;
    min-height: calc(0.5rem * 2 + 1.2em);
    height: calc(0.5rem * 2 + 1.2em);
    padding: 0 2rem 0 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    border: 1px solid var(--control-border);
    border-radius: 6px;
    background: var(--control-bg);
    color: var(--control-text);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
    box-sizing: border-box;
    position: relative;
}

.settings-native-select-trigger:hover {
    border-color: var(--control-hover-border);
    background: var(--dropdown-control-surface);
    box-shadow: none;
}

.settings-native-select.open .settings-native-select-trigger,
.settings-native-select-trigger:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: none;
    background: var(--dropdown-control-surface);
}

.settings-native-select-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-native-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.25rem 0;
    border: 1px solid var(--dropdown-border);
    border-radius: 6px;
    background: var(--dropdown-bg);
    box-shadow: var(--dropdown-shadow);
    box-sizing: border-box;
    z-index: 10003;
    scrollbar-width: thin;
    scrollbar-color: var(--dropdown-scrollbar-thumb) var(--dropdown-scrollbar-track);
}

.settings-native-select-menu::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.settings-native-select-menu::-webkit-scrollbar-track {
    background: var(--dropdown-scrollbar-track);
    border-radius: 999px;
}

.settings-native-select-menu::-webkit-scrollbar-thumb {
    background: var(--dropdown-scrollbar-thumb);
    border-radius: 999px;
}

.settings-native-select-menu::-webkit-scrollbar-thumb:hover {
    background: var(--dropdown-scrollbar-thumb-hover);
}

.settings-native-select-option {
    min-height: var(--dropdown-option-height);
    padding: 0 0.75rem;
    display: flex;
    align-items: center;
    color: var(--dropdown-option-text);
    font-size: 0.95rem;
    line-height: 1.25;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
}

.settings-native-select-option.disabled,
.settings-native-select.disabled .settings-native-select-trigger {
    opacity: 0.6;
    cursor: not-allowed;
}

.file-config-input:hover {
    border-color: var(--control-hover-border);
}

.file-config-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.config-page input[type="number"].file-config-input {
    appearance: textfield;
    -moz-appearance: textfield;
}

.config-page input[type="number"].file-config-input::-webkit-outer-spin-button,
.config-page input[type="number"].file-config-input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
}

/* Number Input Wrapper với Custom Spinner Buttons */
.number-input-wrapper {
    position: relative;
    display: inline-block;
    width: auto;
    min-width: 60px;
}

/* Riêng ô Port truy cập giữ width auto, không giới hạn max-width */
.number-input-wrapper:has(#configServerPort) {
    max-width: none;
    width: auto;
}

.number-input-wrapper .file-config-input {
    padding-right: 1.5rem;
    position: relative;
}

/* Custom spinner buttons - đặt bên trong input */
.custom-spinner-buttons {
    position: absolute;
    right: 4px;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1px;
    z-index: 10;
    pointer-events: none;
    height: 100%;
}

.custom-spinner-btn {
    width: 14px;
    height: 10px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 2px;
    pointer-events: auto;
}

.custom-spinner-btn:hover,
.custom-spinner-btn:active {
    background-color: var(--ui-interaction-hover-bg);
}

.custom-spinner-btn svg {
    width: 8px;
    height: 8px;
    stroke: rgba(var(--control-text-rgb), 0.62);
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.custom-spinner-btn:hover svg {
    stroke: var(--control-text);
}

/* Password Input Wrapper với Eye Toggle */
.password-input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.password-input-wrapper .file-config-input {
    padding-right: 2.5rem;
}

.password-toggle-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #495057;
    z-index: 1;
}

.password-toggle-btn:hover {
    color: #343a40;
}

.password-toggle-btn:focus {
    outline: none;
    color: #495057;
}

.password-toggle-btn:active {
    color: #495057;
}

.eye-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
}

/* Mặc định: ẩn cả 2 icon, sẽ được điều khiển bởi các rule cụ thể bên dưới */
.password-input-wrapper .eye-icon {
    display: none;
}

/* Khi nội dung đang ẩn, hiển thị mắt có gạch chéo. */
.password-input-wrapper .config-secret-input.is-masked ~ .password-toggle-btn .eye-icon.eye-closed {
    display: block !important;
}

.password-input-wrapper .config-secret-input.is-masked ~ .password-toggle-btn .eye-icon.eye-open {
    display: none !important;
}

/* Khi nội dung đang hiện, hiển thị mắt không có gạch chéo. */
.password-input-wrapper .config-secret-input:not(.is-masked) ~ .password-toggle-btn .eye-icon.eye-open {
    display: block !important;
}

.password-input-wrapper .config-secret-input:not(.is-masked) ~ .password-toggle-btn .eye-icon.eye-closed {
    display: none !important;
}

.password-input-wrapper .config-secret-input.is-masked {
    -webkit-text-security: disc;
}

/* Custom Select cho Server URL */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    border: 1px solid var(--control-border);
    border-radius: var(--form-control-radius);
    background-color: var(--control-bg);
    color: var(--control-text);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1.2;
    height: var(--dropdown-option-height);
    min-height: var(--dropdown-option-height);
    position: relative; /* Để đặt nút copy absolute */
    box-sizing: border-box;
}

.custom-select-trigger span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.custom-select-trigger svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.custom-select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background-color: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: var(--form-control-radius);
    box-shadow: var(--dropdown-shadow);
    z-index: 10003;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    margin-top: 0;
}

.custom-select-options.show {
    display: block;
}

.custom-select-list {
    padding: 0.25rem;
}

.server-url-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    cursor: pointer;
    border-radius: var(--dropdown-option-edge-radius);
    gap: 0.5rem;
    height: var(--dropdown-option-height);
    min-height: var(--dropdown-option-height);
    box-sizing: border-box;
}

.server-url-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    color: var(--dropdown-option-text);
}

.server-url-copy-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dropdown-option-text);
    flex-shrink: 0;
    border-radius: var(--form-control-radius);
    margin-left: auto; /* Căn lề bên phải */
    width: 20px;
    height: 20px;
}

.server-url-copy-btn:hover {
    background-color: transparent;
    color: var(--primary);
}

.server-url-copy-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
}

/* Control Card - giống index page */
.control-card {
    background: var(--surface-bg);
    border-radius: 12px;
    box-shadow: var(--surface-shadow-soft);
    overflow: visible;
    margin-bottom: 0;
}

.control-card .card-body {
    display: flex;
    flex-direction: column;
    gap: var(--settings-card-body-gap);
    overflow: visible;
    padding: var(--settings-card-body-gap);
    border-radius: 12px;
}

/* Responsive */
@media (max-width: 768px) {
    .config-page {
        max-width: 100%;
        --settings-card-body-gap: 1rem;
    }

    .file-config-grid {
        grid-template-columns: 1fr;
    }

}

/* Responsive cho màn hình nhỏ hơn */
@media (max-width: 480px) {
    .config-page {
        --settings-grid-gap: 0.5rem;
    }

    .file-config-group label {
        font-size: 0.8rem;
    }
    
    .file-config-input {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }
    
    .custom-select-trigger {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
        height: 32px;
        min-height: 32px;
    }
    
    .custom-select-option {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }
    
    .server-url-option {
        padding: 0 0.6rem;
    }
    
    .server-url-label {
        font-size: 0.85rem;
    }
}

/* Responsive cho màn hình trung bình */
@media (min-width: 481px) and (max-width: 1024px) {
    .config-page {
        --settings-card-body-gap: 1.25rem;
        --settings-grid-gap: 0.75rem;
    }

    .file-config-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    
    .file-config-group label {
        font-size: 0.875rem;
    }
    
    .file-config-input {
        font-size: 0.9rem;
    }
    
    .custom-select-trigger {
        font-size: 0.9rem;
    }
    
    .custom-select-option {
        font-size: 0.9rem;
    }
    
    .server-url-label {
        font-size: 0.9rem;
    }
}

/* ==================== Dark Mode ==================== */
body.dark-mode .control-card {
    background: var(--surface-bg);
    box-shadow: var(--surface-shadow);
}



body.dark-mode .file-config-input:-webkit-autofill,
body.dark-mode .file-config-input:-webkit-autofill:hover,
body.dark-mode .file-config-input:-webkit-autofill:focus,
body.dark-mode .file-config-input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--control-bg) inset !important;
    -webkit-text-fill-color: var(--control-text) !important;
    background-color: var(--control-bg) !important;
    color: var(--control-text) !important;
}

body.dark-mode .file-config-input::placeholder {
    color: #999 !important;
    opacity: 1;
}

body.dark-mode .file-config-input::-webkit-input-placeholder {
    color: #999 !important;
    opacity: 1;
}

body.dark-mode .file-config-input::-moz-placeholder {
    color: #999 !important;
    opacity: 1;
}

body.dark-mode .file-config-input:-ms-input-placeholder {
    color: #999 !important;
    opacity: 1;
}

body.dark-mode .file-config-input[type="number"]::-webkit-inner-spin-button,
body.dark-mode .file-config-input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    appearance: none !important;
    margin: 0 !important;
    opacity: 0 !important;
    display: none !important;
}

body.dark-mode .custom-select-options {
    background-color: var(--dropdown-bg) !important;
    border-color: var(--dropdown-border) !important;
}


body.dark-mode .settings-native-select-menu {
    background: var(--dropdown-bg);
    border-color: var(--dropdown-border);
    box-shadow: var(--dropdown-shadow);
}

body.dark-mode .settings-native-select-option {
    color: var(--dropdown-option-text);
}

body.dark-mode .server-url-label {
    color: var(--dropdown-option-text);
}

body.dark-mode .server-url-copy-btn {
    color: #b0b0b0;
}

body.dark-mode .server-url-copy-btn:hover {
    background-color: transparent;
    color: var(--primary);
}

/* Custom spinner interaction inherits the shared Light/Dark contract from style.css. */
/* Ẩn dropdown arrow luôn (kể cả có 2 IP) */
.custom-select-trigger > svg {
    display: none !important;
}

.custom-select.single-option .custom-select-trigger {
    cursor: default !important;
    padding-right: 2.5rem; /* Tạo không gian cho nút copy */
}

/* Khi có nhiều option, vẫn cần padding cho nút copy */
.custom-select-trigger {
    padding-right: 2.5rem !important;
}

/* Nút copy trong trigger */
.server-url-copy-btn-trigger {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #666;
    border-radius: 3px;
}

.server-url-copy-btn-trigger:hover {
    background-color: transparent;
    color: var(--primary);
}

.server-url-copy-btn-trigger:active {
    background-color: transparent;
}

.server-url-copy-btn-trigger svg {
    width: 14px;
    height: 14px;
}

/* Dark mode cho nút copy trong trigger */
body.dark-mode .server-url-copy-btn-trigger {
    color: #999;
}

body.dark-mode .server-url-copy-btn-trigger:hover {
    background-color: transparent;
    color: var(--primary);
}

body.dark-mode .server-url-copy-btn-trigger:active {
    background-color: transparent;
}

.file-config-input,
.custom-select-trigger,
.settings-native-select,
.settings-native-select-trigger {
    height: var(--form-control-height);
    min-height: var(--form-control-height);
    padding-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
}


/* Final lock: Settings page uses the same control surface as the home page. */
.config-page .control-card {
    background: var(--surface-bg) !important;
    color: var(--control-text) !important;
}

.config-page .file-config-group label {
    color: var(--control-text) !important;
}

.config-page :is(
    .file-config-input,
    .settings-native-select,
    .settings-native-select-trigger,
    .custom-select-trigger,
    .number-input-wrapper,
    .password-toggle-btn
) {
    height: var(--form-control-height) !important;
    min-height: var(--form-control-height) !important;
    border-radius: var(--form-control-radius) !important;
    box-sizing: border-box !important;
}

/* Final lock: config controls repaint theme colors instantly like the Link truy cập dropdown.
   Keep only border/focus animation so native inputs do not lag behind custom dropdowns. */
.config-page {
    color-scheme: light;
}

body.dark-mode .config-page {
    color-scheme: dark;
}

/* Interaction colors/states are owned by shared-control-state.css.
   This page stylesheet now keeps only Settings-specific geometry/layout. */

.config-page :is(
    .settings-native-select-option,
    .server-url-option,
    .custom-select-option
) {
    border-radius: var(--dropdown-option-edge-radius) !important;
}

.config-page :is(
    .file-config-input,
    .settings-native-select-trigger,
    .settings-native-select-option,
    .custom-select-trigger,
    .custom-select-option,
    .server-url-option
) {
    font-family: inherit !important;
    font-size: var(--form-control-font-size) !important;
    font-weight: var(--form-control-font-weight, 400) !important;
}

/* Settings dropdowns use the same visible overflow behavior as Register dropdowns.
   The embedded shell resizes the iframe while a dropdown is open, so menus must not be clipped by the card/grid. */
.config-page :is(
    .control-card,
    .card-body,
    .file-config-wrapper,
    .file-config-content,
    .file-config-grid,
    .file-config-group,
    .custom-select-wrapper,
    .custom-select,
    .settings-native-select
) {
    overflow: visible !important;
}

.config-page :is(.custom-select.active, .settings-native-select.open) {
    z-index: 12000 !important;
}

.config-page :is(.custom-select-options, .settings-native-select-menu) {
    z-index: 12010 !important;
    max-height: 320px;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}
