/* --- CONTAINER --- */
.sd-container {
    max-width: 800px;
    margin: 20px auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    font-family: 'Be Vietnam Pro', sans-serif;
    border: 1px solid #e0e0e0;
    overflow: hidden;
    position: relative;
}

/* --- HEADER --- */
.sd-header {
    background: #fff;
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sd-title { font-size: 18px; font-weight: 700; color: #333; display: flex; align-items: center; }
.sd-credits { font-size: 14px; color: #666; font-weight: 500; }
.highlight { color: #e91e63; font-weight: 700; font-size: 16px; }

/* --- TABS --- */
.sd-tabs { display: flex; background: #f9f9f9; padding: 0 20px; border-bottom: 1px solid #e0e0e0; gap: 20px; }
.sd-tab {
    background: none; border: none;
    padding: 15px 10px;
    font-size: 14px; font-weight: 600; color: #777;
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: 0.3s;
}
.sd-tab:hover { color: #333; }
.sd-tab.active { color: #0073aa; border-bottom-color: #0073aa; background: #fff; }

.sd-tab-content { display: none; padding: 25px; }
.sd-tab-content.active { display: block; animation: sdFadeIn 0.4s; }

/* --- FORM ELEMENTS --- */
.sd-form-group { margin-bottom: 20px; }
.sd-form-group label { display: block; font-weight: 600; margin-bottom: 8px; color: #444; font-size: 14px; }
.sd-form-group textarea, .sd-form-group input[type="text"], .sd-form-group input[type="number"] {
    width: 100%; padding: 12px;
    border: 1px solid #ddd; border-radius: 8px;
    font-family: inherit; font-size: 14px;
    box-sizing: border-box; transition: 0.3s;
}
.sd-form-group textarea:focus, .sd-form-group input:focus { border-color: #0073aa; outline: none; }

/* Upload Area */
.sd-upload-area {
    border: 2px dashed #ccc; border-radius: 8px;
    padding: 20px; text-align: center;
    cursor: pointer; transition: 0.3s;
    background: #fafafa; position: relative;
    min-height: 120px; display: flex; align-items: center; justify-content: center;
}
.sd-upload-area:hover { border-color: #0073aa; background: #fff; }
.sd-upload-content p { margin: 10px 0 0; color: #888; font-size: 13px; }
.sd-upload-content strong { color: #333; }
#preview-container { margin-top: 10px; }
#preview-container img { max-height: 150px; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

/* Grid */
.sd-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.sd-form-group select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; height: 45px; }

/* Magic Button */
.sd-prompt-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sd-magic-btn {
    background: linear-gradient(45deg, #8e2de2, #4a00e0);
    color: white; border: none; border-radius: 20px;
    padding: 5px 15px; font-size: 12px; font-weight: bold;
    cursor: pointer; transition: 0.3s; display: flex; align-items: center; gap: 5px;
}
.sd-magic-btn:hover { transform: scale(1.05); box-shadow: 0 4px 15px rgba(74, 0, 224, 0.3); }

/* Footer */
.sd-footer-action {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 20px; padding-top: 20px; border-top: 1px solid #eee;
}
.sd-cost-box { font-size: 14px; color: #555; }
.sd-cost-box strong { color: #d63638; font-size: 16px; }
.sd-btn-primary {
    background: #0073aa; color: #fff;
    border: none; padding: 12px 30px;
    border-radius: 6px; font-weight: 700; font-size: 15px;
    cursor: pointer; transition: 0.3s;
}
.sd-btn-primary:hover { background: #005177; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0, 115, 170, 0.3); }
.sd-btn-primary:disabled { background: #ccc; cursor: not-allowed; transform: none; box-shadow: none; }

/* Checkbox Label */
.sd-checkbox-label {
    display: flex; align-items: center; cursor: pointer;
    font-weight: normal !important;
}
.sd-checkbox-label input { margin-right: 10px; width: 18px; height: 18px; }

/* Loading */
.sd-loader {
    border: 4px solid #f3f3f3; border-top: 4px solid #0073aa;
    border-radius: 50%; width: 30px; height: 30px;
    animation: sdSpin 1s linear infinite;
}

/* History Grid */
.sd-video-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}
.sd-card {
    border: 1px solid #eee; border-radius: 8px; overflow: hidden;
    background: #fff; transition: 0.3s;
}
.sd-card:hover { transform: translateY(-5px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.sd-card-video video { width: 100%; aspect-ratio: 16/9; background: #000; display: block; }
.sd-card-body { padding: 15px; }
.sd-meta-tags { margin-bottom: 10px; }
.sd-tag {
    display: inline-block; padding: 2px 6px; border-radius: 4px;
    font-size: 10px; font-weight: bold; color: #fff; margin-right: 5px;
}
.sd-tag.img { background: #0073aa; }
.sd-tag.txt { background: #e91e63; }
.sd-tag.res { background: #4caf50; }
.sd-meta-info {
    display: flex; justify-content: space-between; font-size: 11px; color: #888;
    margin-bottom: 10px; border-bottom: 1px solid #f0f0f0; padding-bottom: 5px;
}
.sd-cost-val { color: #d63638; font-weight: bold; }
.sd-card-prompt {
    font-size: 13px; color: #555; margin: 0 0 15px; line-height: 1.4;
    height: 36px; overflow: hidden;
}
.sd-card-actions { display: flex; gap: 5px; }
.sd-action-btn {
    flex: 1; padding: 6px; border-radius: 4px;
    border: 1px solid #ddd; background: #f9f9f9; color: #555;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; text-decoration: none; transition: 0.2s;
}
.sd-action-btn:hover { background: #fff; border-color: #0073aa; color: #0073aa; }

/* === NEW MODAL STYLES (V17.4) === */
.sd-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99999;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(5px);
    animation: sdFadeIn 0.3s ease;
}

.sd-modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 16px;
    width: 90%; max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    position: relative;
    animation: sdSlideUp 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.sd-modal-icon {
    font-size: 40px; color: #ff9800; /* Màu cam cảnh báo */
    margin-bottom: 15px;
}
.sd-modal-icon .dashicons {
    width: 50px; height: 50px; font-size: 50px;
}

.sd-modal-content h3 {
    margin: 0 0 10px; font-size: 20px; color: #333;
}

.sd-modal-content p {
    font-size: 15px; color: #666; line-height: 1.5; margin-bottom: 25px;
}

.sd-modal-btn {
    background: #0073aa; color: #fff;
    border: none; padding: 10px 30px;
    border-radius: 50px; font-weight: 700; font-size: 14px;
    cursor: pointer; transition: 0.2s;
    box-shadow: 0 5px 15px rgba(0, 115, 170, 0.3);
}
.sd-modal-btn:hover {
    background: #005177; transform: translateY(-2px);
}

@keyframes sdFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sdSlideUp { from { opacity: 0; transform: translateY(30px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes sdSpin { to { transform: rotate(360deg); } }

/* Mobile */
@media (max-width: 600px) {
    /* Header */
    .sd-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px;
        padding-bottom: 10px !important;
    }
    .sd-header > div {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .sd-title { font-size: 16px !important; }
    .sd-credits { font-size: 13px !important; }
    
    /* Nút Hướng dẫn */
    .sd-title a {
        font-size: 11px !important;
        padding: 2px 8px !important;
    }

    /* Tabs */
    .sd-tabs { gap: 5px !important; }
    .sd-tab { padding: 8px 10px !important; font-size: 13px !important; flex: 1; text-align: center; }

    /* Grid */
    .sd-grid-2 { grid-template-columns: 1fr !important; gap: 15px !important; }
/* --- FIX BUTTON TEXT WRAPPING (V17.5) --- */
.sd-footer-action {
    display: flex !important;
    flex-direction: row !important; /* Luôn nằm ngang */
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
}

.sd-btn-primary {
    white-space: nowrap !important; /* Bắt buộc không xuống dòng */
    width: auto !important; /* Tự động co giãn theo chữ */
    min-width: 120px !important; /* Đảm bảo độ rộng tối thiểu */
    padding: 10px 20px !important;
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    height: 45px !important; /* Cố định chiều cao cho đẹp */
    margin: 0 !important;
}

/* Mobile nhỏ thì giảm chữ chút xíu */
@media (max-width: 400px) {
    .sd-btn-primary {
        font-size: 13px !important;
        padding: 0 15px !important;
    }
}
/* --- FIX SEEDANCE MOBILE UI (V17.6) --- */

/* 1. Nút Tối ưu mô tả: Luôn thẳng hàng, không bị bóp méo */
.sd-prompt-label-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: nowrap !important; /* Không cho rớt dòng */
}

.sd-magic-btn {
    white-space: nowrap !important; /* Chữ luôn 1 dòng */
    flex-shrink: 0 !important; /* Không bị co lại */
    width: auto !important;
    min-width: fit-content !important;
}

/* 2. Dòng Chi phí: Ép thẳng hàng, không rớt chữ "Credit" */
.sd-cost-box {
    white-space: nowrap !important; /* Bắt buộc 1 dòng */
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex-shrink: 0 !important; /* Không bị nút Tạo Video chèn ép */
    font-size: 13px !important;
}

/* 3. Tinh chỉnh lại footer trên mobile để vừa vặn */
@media (max-width: 400px) {
    .sd-footer-action {
        gap: 10px !important;
    }
    
    /* Nút Tạo Video tự co giãn cho vừa chỗ còn lại */
    .sd-btn-primary {
        flex-grow: 1 !important;
        min-width: unset !important; /* Bỏ giới hạn chiều rộng để không đẩy dòng chi phí */
        padding: 0 10px !important;
        font-size: 13px !important;
    }
}
/* --- FIX UPLOAD CLICK (V17.8 - SUPER FORCE) --- */
.sd-upload-area {
    position: relative !important;
    overflow: hidden !important; /* Đảm bảo input không tràn ra ngoài */
    z-index: 1; /* Tạo stacking context */
}

/* Ép buộc input đè lên tất cả */
#input_image, 
.sd-upload-area input[type="file"] {
    display: block !important;
    visibility: visible !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    opacity: 0 !important;
    z-index: 999 !important; /* Cao nhất */
    cursor: pointer !important;
    pointer-events: auto !important; /* Đảm bảo nhận click */
}

/* Đảm bảo nội dung preview nằm dưới input */
.sd-upload-content, 
#preview-container {
    position: relative;
    z-index: 2; /* Thấp hơn 999 */
    pointer-events: none; /* Để click xuyên qua nội dung xuống input */
}
/* --- FIX UPLOAD FINAL (V17.9) --- */
/* Ẩn hoàn toàn input gốc */
#input_image {
    display: none !important;
}

/* Đảm bảo khung có con trỏ chuột */
.sd-upload-area {
    cursor: pointer !important;
    position: relative;
    z-index: 1;
}

/* Style cho ảnh preview */
#preview-container img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    margin-top: 10px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}