:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-glow: rgba(37, 99, 235, 0.18);
    --success: #10b981;
    --success-hover: #059669;
    --success-glow: rgba(16, 185, 129, 0.18);
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --bg-light: #f8fafc;
    --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Khung tổng thể */
.tao-wrapper {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    box-sizing: border-box;
}

.page-header { text-align: center; margin-bottom: 14px; }
.page-header h2 { font-size: 19px; font-weight: 800; color: var(--text-dark); margin: 0 0 2px 0; }
.page-header .dev { font-size: 12px; color: var(--text-muted); margin: 0; }

/* Form Controls (2 Cột) */
.tao-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 12px;
}

.tao-controls hr {
    grid-column: 1 / -1;
    border: 0;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

/* Upload Card (Tràn rộng 2 cột) */
.upload-wrapper { grid-column: 1 / -1 !important; width: 100% !important; }
.upload-card {
    width: 100% !important;
    box-sizing: border-box;
    padding: 18px 12px;
    background: var(--bg-light);
    border: 1.5px dashed #cbd5e1;
    border-radius: 12px;
    text-align: center;
    transition: var(--transition);
}
.upload-card:hover { border-color: var(--primary); background: #eff6ff; }
.upload-icon { font-size: 30px; color: var(--primary); margin-bottom: 4px; }
.upload-card h3 { font-size: 13.5px; font-weight: 600; color: var(--text-dark); margin: 0 0 10px 0; }

.btn-select {
    display: inline-block;
    padding: 8px 20px;
    background: var(--primary);
    color: #ffffff !important;
    font-weight: 600;
    font-size: 12.5px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-select::before { display: none !important; }
.btn-select:hover { background: var(--primary-hover); }

/* Labels & Input */
label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dark);
    gap: 4px;
}

input[type="text"], select {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--text-dark);
    background: #ffffff;
    outline: none;
    transition: var(--transition);
}
input[type="text"]:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2.5px var(--primary-glow);
}

/* Toggle Switch */
.switch-line {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 2px 0;
}
.switch-line span { font-size: 12.5px; font-weight: 600; color: var(--text-dark); }
.switch { position: relative; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0;
    background-color: #cbd5e1;
    transition: var(--transition);
    border-radius: 20px;
    cursor: pointer;
}
.slider:before {
    position: absolute; content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: var(--transition);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }

/* Nút bấm Tạo ảnh (Trái) & Lưu ảnh (Phải) */
#createBtn, #saveBtn {
    grid-column: span 1 !important;
    width: 100%;
    padding: 10px;
    font-size: 13px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
}
#createBtn { grid-column: 1 / 2 !important; background: var(--primary); color: #ffffff; box-shadow: 0 3px 10px var(--primary-glow); }
#createBtn:hover { background: var(--primary-hover); }
#saveBtn { grid-column: 2 / 3 !important; background: var(--success); color: #ffffff; box-shadow: 0 3px 10px var(--success-glow); }
#saveBtn:hover { background: var(--success-hover); }

/* FIX MODAL CROPPING LUÔN HIỆN NÚT */
.crop-modal {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    padding: 16px;
    box-sizing: border-box;
}

.crop-modal .modal-content {
    background: #ffffff;
    width: 100%; max-width: 400px;
    max-height: 85vh; /* Giới hạn chiều cao */
    border-radius: 16px;
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.crop-modal .modal-header {
    padding: 12px 16px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.crop-modal .modal-header h4 { margin: 0; font-size: 14px; font-weight: 700; color: var(--text-dark); }
.close-modal { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }

.crop-modal .modal-body {
    flex: 1;
    min-height: 200px;
    max-height: 55vh;
    background: #0f172a;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.crop-modal #imageToCrop { max-width: 100% !important; max-height: 100% !important; display: block; }

.crop-modal .modal-footer {
    padding: 12px 16px;
    display: flex; justify-content: flex-end; gap: 8px;
    border-top: 1px solid var(--border);
    background: #ffffff;
    flex-shrink: 0; /* Giữ nút luôn cố định ở đáy */
}

#btnCancel { padding: 8px 16px; background: #f1f5f9; color: #475569; border: none; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
#cropBtn { padding: 8px 20px; background: var(--primary); color: #ffffff; border: none; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }

/* Toast Notification */
.ck-toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    background: #ffffff; color: var(--text-dark);
    padding: 8px 20px; border-radius: 50px;
    font-size: 12px; font-weight: 600;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; transition: var(--transition);
}
.ck-toast.show { opacity: 1; top: 24px; }