/* Reset & base styles */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

input, select, textarea, button {
  font-family: inherit;
}


/* top-area: 3 cột ngang (console, info, select+run) */
.top-area {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 5px;
}
.top-col {
  background: #1c1c1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 10px;
  padding-bottom: 5px; /* ❌ bỏ padding-bottom để không tốn chỗ */
  min-height: 120px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative; /* ✨ thêm dòng này để positioning thanh tiến trình */
}



/* console-log (chiều cao ~100px, chữ nhỏ) */
.console-log {
  position: relative;
  background: transparent; /* bỏ nền đen */
  border: none;             /* bỏ viền */
  padding: 6px;
  padding-bottom: 10px;  /* ✨ chừa sẵn 30px phía dưới cho progress bar */
  height: 100px;
  overflow-y: auto;
  font-family: Menlo, monospace;
  font-size: 0.8em;
  line-height: 1.2em;
}

/* === ADDED: Progress Bar Styles === */
.progress-bars-wrapper {
  /* MODIFIED: Use absolute positioning */
  position: absolute;
  bottom: 5px; /* Position inside parent's bottom padding */
  left: 5px;   /* Position inside parent's left padding */
  right: 5px;  /* Position inside parent's right padding */
  /* margin-top: auto; /* Removed */
  /* width: 100%; /* Removed, width is now auto based on left/right */
  /* padding: 0 5px 5px 5px; /* Removed, padding handled by parent/positioning */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1px; /* Keep the 1px gap */
}

.progress-bar-container {
  width: 100%;
  height: 1px; /* Very thin bar */
  background-color: #444; /* Dark grey background/track */
  border-radius: 1px; /* Optional: slightly rounded ends */
  overflow: hidden; /* Important: hide excess fill */
}

.progress-bar-fill {
  height: 100%;
  width: 0%; /* Start at 0% */
  border-radius: 1px; /* Match container */
  transition: width 0.3s ease-out; /* Smooth transition */
}

/* Specific colors */
.progress-bar-fill.overall { /* Top bar */
  background-color: #ffc107; /* Yellow */
}

.progress-bar-fill.ksampler { /* Bottom bar */
  background-color: #28a745; /* Green */
}
/* === END ADDED: Progress Bar Styles === */




/* info-bar */
.info-bar {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85em;
  max-height: 100px; /* Chiều cao tối đa cố định */
  overflow-y: auto;  /* Hiển thị thanh cuộn nếu nội dung vượt quá */
}
.info-bar code {
  background: #2c2c2e;
  padding: 2px 4px;
  border-radius: 4px;
  color: #e0e0e0;
}

/* input-group (chọn workflow) */
.input-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.input-group label {
  font-size: 0.9em;
}
input, select, textarea {
  background: #2c2c2e;
  color: #e0e0e0;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 6px;
  font-size: 0.9em;
}





/* Loading overlay & progress bar */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.loading-text {
  font-size: 1.1em;
  margin-bottom: 10px;
}
.progress-bar {
  width: 80%;
  height: 8px;
  background: #444;
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #007aff;
  width: 0%;
  transition: width 0.5s ease;
}



.workflow-dropdown {
  padding: 5px 10px; /* Điều chỉnh padding để khớp với nút */
  font-size: 14px;
  border-radius: 15px;
  border: 1px solid #666;
  background: #222;
  color: white;
  min-width: 150px;
  width: 100%;
  box-sizing: border-box;
}


/* === KHÔI PHỤC CSS CHO LỊCH SỬ === */
#history-section {
  display: flex; 
  flex-direction: column; 
  /* Removed margin-top: auto; */
  flex: 1; /* Add this to make it grow */
  min-height: 0;
  overflow: hidden;
  margin-bottom: 20px;
  /* Existing styles below */
  background-color: #2d2d2d; 
  border: 1px solid #444; 
  border-radius: 8px; 
  padding: 15px; 
  box-sizing: border-box;
  width: 100%;
}



/* Modal phóng to ảnh */
.modal {
  display: none;
  position: fixed;
  z-index: 1500; /* Ở giữa - cao hơn avatar nhưng thấp hơn dropdown menu */
  padding-top: 60px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0,0,0,0.9);
  user-select: none;
}

/* Khi modal hiển thị, không cho body scroll */
body.modal-open {
  overflow: hidden;
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  max-height: 90%;
  transition: transform 0.2s ease;
  user-select: none; /* Không cho phép bôi đen */
  -webkit-user-drag: none; /* Không cho phép kéo ảnh */
}
.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background-color: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  color: #ffffff;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  z-index: 150; /* Đảm bảo hiện ở trên cùng */
  transition: all 0.2s ease;
}

.modal-close:hover,
.modal-close:focus {
  background-color: rgba(255, 0, 0, 0.7);
  color: #ffffff;
  border-color: #ffffff;
  transform: scale(1.1);
  text-decoration: none;
}

/* Thêm CSS cho điều khiển zoom */
.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  background: rgba(0,0,0,0.6);
  padding: 5px 10px;
  border-radius: 20px;
  z-index: 110;
}

.zoom-controls button {
  background: #333;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
}

.zoom-controls button:hover {
  background: #444;
}

/* Node grid & box */
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}
.node-box {
  border: 1px solid #444;
  border-radius: 8px;
  background: #1c1c1e;
  padding: 10px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
}
.node-title {
  font-weight: bold;
  font-size: 1em;
  background: rgba(255,255,255,0.05);
  padding: 6px;
  margin-bottom: 8px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-grow: 1;
  min-height: 0;
  padding: 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Dòng bình thường */
.node-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Dòng chứa checkbox */
.node-row.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 5px;
}







.node-row label {
  font-size: 0.85em;
  margin-right: 5px;
}
.node-row input,
.node-row select,
.node-row textarea {
  width: 100%;
  font-size: 0.9em;
  padding: 6px;
}
.node-row textarea {
  resize: vertical;
  max-width: 100%;
  overflow-x: auto;
}

/* =========================================================
   RESPONSIVE SCALE ĐỂ 4 NODE 1 HÀNG KHÔNG BỊ CHE KHUẤT
   => Kết hợp scale + bù width/height + overflow: visible
========================================================= */



.node-box {
  min-width: 0; /* cho phép co giãn theo container */
}












/* Mỗi ô lịch sử: ép buộc giữ tỷ lệ vuông theo kỹ thuật padding */



#mask-preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Đảm bảo hình ảnh lấp đầy khung chứa và giữ nguyên tỷ lệ */
  background-color: #222;
  /* border: 1px dashed #777; */ /* Loại bỏ viền ngoài */
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1px; /* Đảm bảo khoảng cách nhỏ giữa ảnh và viền */
}


.icon-btn.comfy-running svg {
  stroke: #4cd964 !important; /* Màu xanh lá cho viền icon */
  /* Có thể thêm hiệu ứng nhẹ nhàng khác nếu muốn */
   filter: drop-shadow(0 0 1px rgba(76, 217, 100, 0.8));
}

/* Đảm bảo màu viền SVG mặc định và khi disabled */
.icon-btn:disabled svg {
    stroke: #666 !important; /* Màu xám đậm khi disable */
}

.icon-btn:not(.comfy-running):not(:disabled) svg {
     stroke: #aaa !important; /* Màu xám nhạt mặc định khi không chạy và không disable */
     fill: none !important; /* Luôn đảm bảo không có fill màu */
     stroke-width: 0.5 !important; /* Đặt độ dày viền mong muốn */
 }


/* --- Home Page Content --- */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* Căn giữa theo chiều ngang */
  justify-content: center; /* Căn giữa theo chiều dọc */
  height: 100%; /* Chiếm toàn bộ chiều cao của*/
  padding: 15px 25px; /* Giảm padding thêm */
  box-sizing: border-box;
  text-align: center;
  overflow-y: auto; /* Cho phép cuộn nếu nội dung quá dài */
  color: #ccc; /* Màu text mặc định */
}

.home-title {
  font-size: 1.7em; /* Giảm nhẹ font size */
  font-weight: 300; /* Font mỏng, hiện đại */
  color: #e0e0e0; /* Màu sáng hơn cho tiêu đề */
  margin-bottom: 5px; /* Giảm mạnh margin dưới */
}

.home-divider,
.home-divider-short {
  border: none; /* Bỏ border mặc định của hr */
  height: 1px; /* Độ dày đường kẻ */
  background-color: #383838; /* Làm màu đường kẻ nhạt hơn chút */
  margin: 10px 0; /* Giảm mạnh margin trên dưới */
}

/* Điều chỉnh riêng cho divider đầu tiên */
.home-container > .home-divider:first-of-type {
    margin-top: 8px; /* Giảm margin trên của divider đầu */
    margin-bottom: 12px; /* Giảm margin dưới của divider đầu */
}

.home-divider {
  width: 50%; /* Giảm chiều rộng thêm */
}

.home-divider-short {
  width: 25%; /* Giảm chiều rộng thêm */
  margin: 8px 0; /* Giảm margin thêm */
}

.home-intro {
  font-size: 1.0em; /* Giảm nhẹ font size */
  line-height: 1.6;
  max-width: 750px; /* Giới hạn chiều rộng */
  margin-bottom: 15px; /* Giảm margin dưới */
  color: #aaa; /* Màu text tối hơn một chút */
}

.home-features {
  display: flex;
  flex-direction: column; /* Các feature xếp dọc */
  align-items: center; /* Căn giữa các feature */
  gap: 0; /* Không cần gap vì dùng hr */
  width: 100%;
  max-width: 650px; /* Giới hạn chiều rộng khu vực features */
  margin-bottom: 15px; /* Giảm margin dưới */
}

.home-feature-item {
  margin: 8px 0; /* Giảm margin trên dưới */
}

.home-feature-title {
  font-size: 1.2em; /* Giảm nhẹ font size */
  font-weight: 500; /* Đậm hơn một chút */
  color: #ddd;
  margin-bottom: 3px; /* Giảm mạnh margin dưới */
}

.home-feature-item p {
  font-size: 0.9em; /* Giảm font size */
  color: #aaa;
  line-height: 1.4; /* Giảm line-height */
}

.home-cta {
  font-size: 1.0em; /* Giảm nhẹ font size */
  font-weight: 500;
  color: #e0e0e0;
  margin-top: 10px; /* Giảm margin trên */
}

/* Đảm bảo nội dung không tràn nếu khung quá hẹp */
.home-container > * {
    max-width: 100%;
}
/* --- End Home Page Content --- */


/* === Kết thúc Layout cho Workflow UI Grid === */

/* === Static Page Styles (Terms, Privacy, Refund, Pricing) === */
.static-page-container {
    padding: 40px 20px; /* Padding tổng thể */
}

.static-page-content {
    max-width: 800px; /* Giới hạn chiều rộng nội dung */
    margin: 0 auto; /* Căn giữa nội dung */
    background-color: #1c1c1e; /* Nền tối nhẹ */
    padding: 30px 40px; /* Padding bên trong box */
    border-radius: 8px; /* Bo góc */
    border: 1px solid #333;
    color: #ccc; /* Màu chữ mặc định */
    line-height: 1.7; /* Giãn dòng dễ đọc */
}

.static-page-content h1 {
    font-size: 2.2em;
    font-weight: 600; /* Đậm hơn title chính */
    color: #e0e0e0;
    margin-bottom: 10px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}

.static-page-content h2 {
    font-size: 1.6em;
    font-weight: 500;
    color: #ddd;
    margin-top: 35px; /* Khoảng cách giữa các mục */
    margin-bottom: 15px;
}

.static-page-content h3 {
    font-size: 1.3em;
    font-weight: 500;
    color: #ccc;
    margin-top: 25px;
    margin-bottom: 10px;
}

.static-page-content p {
    margin-bottom: 15px;
}

.static-page-content ul,
.static-page-content ol {
    margin-left: 25px;
    margin-bottom: 15px;
}

.static-page-content li {
    margin-bottom: 8px;
}

.static-page-content a {
    color: #58a6ff; /* Màu link xanh dương nhạt */
    text-decoration: none;
}

.static-page-content a:hover {
    text-decoration: underline;
}

.static-page-content .last-updated {
    font-size: 0.9em;
    color: #888;
    margin-bottom: 25px;
    font-style: italic;
}
/* === End Static Page Styles === */

/* === Pricing Page Specific Styles === */
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); /* Cột tự động điều chỉnh */
    gap: 30px; /* Khoảng cách giữa các gói */
    margin-top: 40px; /* Khoảng cách với tiêu đề */
    margin-bottom: 40px;
}

.pricing-tier {
    background-color: #2a2a2e; /* Nền hơi khác biệt */
    border: 1px solid #444; /* Viền rõ hơn chút */
    border-radius: 8px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    text-align: left; /* Căn trái nội dung trong gói */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative; /* Cho recommended badge */
    overflow: hidden; /* Cho recommended badge */
}

.pricing-tier:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.pricing-tier.recommended {
    border-color: #58a6ff; /* Viền màu xanh cho gói nổi bật */
    box-shadow: 0 0 15px rgba(88, 166, 255, 0.2);
}

.recommended-badge {
    position: absolute;
    top: -1px; /* Điều chỉnh vị trí */
    right: -1px;
    background-color: #58a6ff;
    color: #fff;
    padding: 4px 12px;
    font-size: 0.8em;
    font-weight: 600;
    border-bottom-left-radius: 8px; /* Bo góc chéo */
    border-top-right-radius: 8px; /* Bo góc trên phải của badge*/
}

.tier-title {
    font-size: 1.4em;
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 8px;
}

.tier-price {
    font-size: 1.8em;
    font-weight: 300; /* Font mỏng cho giá */
    color: #e0e0e0;
    margin-bottom: 8px;
}

.tier-price span {
    font-size: 0.7em; /* Chữ /month nhỏ hơn */
    color: #aaa;
}

.tier-description {
    font-size: 0.95em;
    color: #aaa;
    margin-bottom: 20px;
    min-height: 3em; /* Giữ chiều cao ổn định */
}

.tier-features {
    list-style: none;
    padding: 0;
    margin-bottom: 25px;
    flex-grow: 1; /* Đẩy nút xuống dưới */
}

.tier-features li {
    margin-bottom: 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.95em;
    color: #ccc;
}

.tier-features .check-mark,
.tier-features .cross-mark {
    font-size: 1.1em;
    line-height: 1.3;
}

.tier-features .check-mark {
    color: #4CAF50; /* Màu xanh lá */
}
.tier-features .check-mark.faded {
    color: #8a8a8a; /* Màu xám cho tính năng giới hạn */
}

.tier-features .cross-mark {
    color: #8a8a8a; /* Màu xám cho tính năng không có */
}

.tier-button {
    display: block; /* Nút chiếm toàn bộ chiều rộng */
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-radius: 6px;
    background-color: #58a6ff; /* Màu nền nút */
    color: #fff; /* Màu chữ nút */
    font-size: 1em;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-top: auto; /* Đẩy nút xuống cuối flex container */
}

.tier-button:hover {
    background-color: #4090e0; /* Màu hover tối hơn */
}

.pricing-tier.recommended .tier-button {
    background-color: #4CAF50; /* Màu nút khác cho gói recommended */
}

.pricing-tier.recommended .tier-button:hover {
    background-color: #45a049;
}

.pricing-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #333;
    color: #aaa;
    font-size: 0.95em;
}

.pricing-footer a {
     color: #58a6ff;
     text-decoration: none;
}
.pricing-footer a:hover {
     text-decoration: underline;
}
/* === End Pricing Page Specific Styles === */

/* Styling for the user email/username display button */
#auth-button.user-display {
  max-width: 200px; 
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex; 
  align-items: center;   
  justify-content: center; 
  vertical-align: middle; 
  padding-left: 15px; 
  padding-right: 15px;
  /* Removed margin-left: auto; Alignment handled by wrapper div in HTML */
  /* margin-right: 0; Removed */
}

/* Ensure logout button aligns well */
#logout-button {
  vertical-align: middle;
  /* Removed margin-left: 8px; Spacing is now handled by the parent div's gap property */
}

/* === CSS MOVED FROM index.html <style> block === */

/* Thêm CSS cho vùng chứa node grid */
/* === Sửa chuẩn chỉnh, chuyên nghiệp cho #workflowUI và node === */

#workflowUI {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 4 cột bằng nhau */
  grid-template-rows: 120px 1fr; /* ADD THIS BACK: Row 1 fixed, Row 2 flexible */
  gap: 5px;
  padding: 5px;
  border: none;
  border-radius: 8px;
  background-color: #2d2d2d;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* Style chung cho node */
.node {
  display: flex;
  flex-direction: column;
  justify-content: flex-start; 
  align-items: stretch;       
  background: #1e1e1e;
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  min-height: 0;
  /* ADDED: Prevent node from expanding horizontally due to content */
  overflow: hidden; 
}

/* Các node ở hàng đầu (4 node đầu tiên) */
#workflowUI > .node:nth-child(-n+4) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 5px 10px;
  height: 120px;
  overflow: hidden;
  min-height: 0;
}

/* Title của 4 node đầu */
#workflowUI > .node:nth-child(-n+4) .node-title {
  margin-bottom: 4px;
  width: 100%;
}

/* Input text/number/select trong 4 node đầu (không ảnh hưởng checkbox) */
#workflowUI > .node:nth-child(-n+4) input[type="text"],
#workflowUI > .node:nth-child(-n+4) input[type="number"],
#workflowUI > .node:nth-child(-n+4) select {
  height: 28px;
  padding: 5px 10px;
  margin-bottom: 4px;
  width: 100%;
  box-sizing: border-box;
}

/* Style cho label trong 4 node đầu */
#workflowUI > .node:nth-child(-n+4) label {
  margin-bottom: 2px;
}

/* node-body và node-row trong 4 node đầu */
#workflowUI > .node:nth-child(-n+4) .node-body {
  margin-top: 0;
  width: 100%;
}

#workflowUI > .node:nth-child(-n+4) .node-row {
  margin-bottom: 4px;
}

#workflowUI > .node:nth-child(-n+4) p {
  margin: 0;
  line-height: 1.4;
}

/* Các node hàng 2 trở đi (n+5) */
#workflowUI > .node:nth-child(n+5) {
  padding: 5px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
}


#workflowUI > .node:nth-child(n+5) .node-body {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow: hidden;
  min-height: 0;
}


/* Checkbox trong node (tiny-checkbox chuẩn) */
.node input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  max-width: 16px;
  max-height: 16px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
}




/* Flex row chứa checkbox và label */
.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.checkbox-row label {
  flex: 1;
  font-size: 0.9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Kết thúc phần chỉnh sửa chuyên nghiệp === */

/* Style cho container chứa ảnh preview trong node 201/202 */
.node-image-preview-container {
    flex-grow: 1; /* ADDED BACK: Allow preview container to fill space */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevent image overflow */
    min-height: 0; /* CHANGED: Allow shrinking completely if needed */
    border: 1px dashed #555; /* UNCOMMENTED: Show the dashed border */
}

/* Style cho chính thẻ ảnh preview */
#node201Preview,
#node202Preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Xóa các CSS trùng lặp và không cần thiết */
.node img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* CSS cho hộp chứa log */
#console-log {
    /* Thêm overflow: hidden để ngăn nội dung con đẩy hộp ra */
    overflow: hidden;
    /* Có thể thêm các style khác cho chính hộp console nếu cần */
    /* ví dụ: height, background-color, border, padding đã có thể được định nghĩa ở class .console-log */
}

/* CSS cho các dòng log bên trong console-log */
#console-log > div {
    white-space: normal; /* Cho phép xuống dòng bình thường */
    overflow: visible;   /* Hiển thị đầy đủ */
    text-overflow: clip; /* Không hiển thị ... */
}

/* CSS cho nút Run Workflow khi bị vô hiệu hóa */
#btnRunWorkflow:disabled {
    opacity: 0.6; /* Giữ lại hiệu ứng mờ đi (tùy chọn) */
    cursor: default; /* Đặt lại con trỏ chuột thành mặc định */
}

/* CSS cho các nút xác thực chung */
.auth-btn {
  width: 180px; 
  height: 30px; 
  text-align: center; 
  padding: 5px 10px; 
  box-sizing: border-box; 
  white-space: nowrap;  
  overflow: hidden;     
  text-overflow: ellipsis; 
  vertical-align: middle; 
  border-radius: 15px;
  border: 1px solid #555; 
  background-color: #222; 
  color: #e0e0e0; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
}

.auth-btn.google {
  background: white;
  color: black;
}

.auth-btn:hover {
  opacity: 0.85;
}



/* CSS cho layout 2 cột của mainContainer */
#mainContainer {
display: grid; 
grid-template-columns: 3fr 1fr; 
gap: 5px; 
flex: 1 1 auto;
min-height: 0;
height: auto;   
max-height: 100%; 
}


#mainContainer > div:first-child {
min-width: 0;
display: flex;
flex-direction: column;
flex: 1 1 auto; /* ✨ thêm dòng này */
min-height: 0; /* ✨ thêm dòng này */
height: auto; /* ✨ đổi từ 100% thành auto */
}


#mainContainer > div:last-child { /* Cột phải */
display: flex;
flex-direction: column;
flex: 1 1 auto; /* ✨ thêm dòng này */
gap: 5px;
overflow: hidden;
min-height: 0;
height: auto;  /* ✨ đổi từ 100% thành auto */
max-height: 100%; /* ✨ thêm để giới hạn */
}


/* Style chung cho các box ở cột phải */
#current-image-section, 
#history-section {
    background-color: #2d2d2d; 
    border: 1px solid #444; 
    border-radius: 8px; 
    padding: 5px; 
    box-sizing: border-box;
    width: 100%;
}

/* Style riêng cho container ảnh kết quả */
.result-image-container {
    margin-top: 10px; 
    min-height: 250px; 
    width: 100%; 
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #282828; 
    border: 1px dashed #555; 
    border-radius: 4px; 
    overflow: hidden; 
}

/* Style cho ảnh #ketquanode */
#current-image-section .result-image-container img#ketquanode {
    display: block; 
    max-width: 100%; 
    max-height: 100%; 
    height: auto; 
    object-fit: contain; 
    border: none !important;
    draggable: true; /* Cho phép kéo ảnh */
}

/* === KHÔI PHỤC CSS CHO LỊCH SỬ === */
#history-section {
display: flex;
flex-direction: column;
flex: 1 1 auto; /* ✨ thêm dòng này */
min-height: 0;
overflow: hidden;
margin-bottom: 5px;/* hoặc 5px, tuỳ bạn */
}


#history-section h3 {
    margin-bottom: 10px; 
    flex-shrink: 0; 
}



.history-item img {
    width: 100%;
    aspect-ratio: 1 / 1; 
    object-fit: cover; 
    border-radius: 4px; 
    draggable: true; /* Cho phép kéo ảnh */
}
/* === KẾT THÚC KHÔI PHỤC CSS LỊCH SỬ === */

/* === THÊM CSS CHO FOOTER === */
#footerContainer {
    display: flex;
    justify-content: space-between;
    gap: 5px;
    padding: 5px; 
    background-color: #333;
    border-radius: 8px; 
    color: #333;
    flex-shrink: 0; 
}

.footer-box {
    flex: 1;
    background: #333; 
    padding: 5px; 
    border-radius: 4px; 
    /* MODIFIED: Use flexbox for vertical and horizontal centering */
    display: flex; 
    align-items: center; /* Vertical centering */
    justify-content: center; /* Horizontal centering */
    /* text-align: center; /* Replaced by justify-content */
}
/* === KẾT THÚC CSS FOOTER === */

html, body {
  margin: 0;
  padding: 0;
  /* overflow: hidden; /* MOVED to body.app-layout */
  /* height: 100vh; /* MOVED to body.app-layout */
  box-sizing: border-box; /* Keep this for all pages */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #121212;
  color: #e0e0e0;
  /* padding: 5px; /* MOVED to body.app-layout */
  font-size: 14px;
  line-height: 1.4;
  /* display: flex; /* MOVED to body.app-layout */
  /* flex-direction: column; /* MOVED to body.app-layout */
}

/* Styles specific to the main application layout */
body.app-layout {
  overflow: hidden; /* Prevent scrolling */
  height: 100vh; /* Full viewport height */
  display: flex; /* Enable flexbox layout */
  flex-direction: column; /* Stack elements vertically */
  padding: 5px; /* Overall padding for the app */
}


/* === THÊM CSS CHO WRAPPER CHÍNH === */
#mainWrapper {
display: flex;
flex-direction: column;
flex: 1 1 auto;
min-height: 0;
}






/* Thêm CSS cho nội dung text trong node */
.node-content {
    flex: 0 0 auto;
    min-height: 0;
    overflow: hidden;
}

/* Đảm bảo tất cả các input và select trong node có chiều cao phù hợp */
.node input,
.node select {
    height: 32px; /* Chiều cao cố định cho input/select */
    box-sizing: border-box;
}

/* Đảm bảo label không chiếm quá nhiều không gian */
.node label {
  margin-bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px; /* khoảng cách nhỏ giữa checkbox và chữ */
}

/* Style cho node-body trong các node hàng 2 */
#workflowUI > .node:nth-child(n+5) .node-body {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow: hidden; /* ✨ Bỏ auto, đổi hidden */
  min-height: 0;     /* ✨ Thêm min-height: 0 bắt buộc */
}


/* Style cho node-row trong các node hàng 2 */



/* FIX: Cho node hàng 1 (192, 212, 213, 113) full chiều rộng bên trong */
#workflowUI > .node:nth-child(-n+4) .node-title,
#workflowUI > .node:nth-child(-n+4) .node-body {
width: 100%;              /* ✅ kéo dài ngang node */
}

#workflowUI > .node:nth-child(-n+4) input,
#workflowUI > .node:nth-child(-n+4) select {
width: 100%;              /* ✅ input/select cũng full chiều ngang */
box-sizing: border-box;   /* ✅ để padding không phá layout */
}

/* === REMOVE DUPLICATE/CONFLICTING #workflowUI RULE === */
/* 
#workflowUI { ... }
*/
/* === END REMOVAL === */

/* === UPDATED: Workflow UI Wrapper as Flex Column === */
#workflowUIWrapper {
  flex: 1 1 auto; /* Allow shrinking/growing */
  display: flex;
  flex-direction: column; /* Stack rows vertically */
  min-height: 0;
  overflow: hidden;
  padding: 5px;
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 8px;
  margin-bottom: 5px;
  gap: 5px; /* Gap between Row 1 and Row 2 */
}
/* === END UPDATED === */

/* === NEW: Styles for Workflow Row 1 === */


/* === UPDATED/NEW: General Node Styles (Apply to nodes in both rows) === */
/* REMOVE THE ENTIRE .node RULE BLOCK BELOW */
/*
.node {
  display: flex;
  flex-direction: column;
  overflow: hidden; 
  background: #1e1e1e;
  border-radius: 8px;
  padding: 5px; 
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  min-height: 0; 
}
*/
/* === END UPDATED === */

/* === NEW: Specific styles for nodes INSIDE Row 1 === */



/* === END NEW Row 1 Node Styles === */


/* === NEW: Specific styles for nodes INSIDE Row 2 === */

/* === END NEW Row 2 Node Styles === */


/* --- Ensure other general node styles are still correct --- */
.node-title {
  font-weight: bold;
  font-size: 1em;
  background: rgba(255,255,255,0.05);
  padding: 5px 8px; /* Consistent padding */
  border-radius: 4px;
}

.node-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-grow: 1;
  min-height: 0;
}



/* ... (Keep other relevant general .node-row styles if any) ... */


/* === REMOVE any remaining rules starting with #workflowUI > ... === */
/* Example: Comment out the duplicate #workflowUI rule if still present */
/*
#workflowUI { ... }
*/
/* === END REMOVAL === */

/* === CSS CHO NÚT TRẠNG THÁI AGENT === */
.agent-status.visible {
  opacity: 1;
}
/* === Copying Colors for Agent Statuses from Backup index.html <style> === */
.agent-status.connecting,
.agent-status.retrying { /* Gom connecting và retrying */
  background-color: #4a4a4a; /* Grey */
  color: #ccc;
  border-color: #4a4a4a;
}
.agent-status.connected {
  background-color: #28a745; /* Green */
  color: white;
  border-color: #28a745;
}
.agent-status.disconnected {
  background-color: #dc3545; /* Red */
  color: white;
  border-color: #dc3545;
}
.agent-status.error {
  background-color: #ffc107; /* Yellow */
  color: #333;
  border-color: #ffc107;
}
.agent-status.idle {
  /* Keep default look or slightly different */
  background-color: #333;
  color: #aaa;
  border-color: #555;
}
/* === END Copied Colors === */
/* === KẾT THÚC CSS CHỈ BÁO === */

/* === REPLACED: Base Styles for Icon Buttons (Using Backup Version) === */
 /* <<< ADDED CSS FOR ICON BUTTONS >>> */
 .icon-btn {
  display: inline-flex; /* Use flex to center content */
  align-items: center;
  justify-content: center;
  width: 24px; /* Fixed small width */
  height: 24px; /* Fixed small height */
  padding: 0; /* Remove padding */
  font-size: 16px; /* Adjust icon size */
  line-height: 1; /* Ensure vertical centering */
  border-radius: 4px; /* Slightly rounded corners */
  border: 1px solid #555;
  background-color: #444; /* Slightly darker background */
  color: #e0e0e0;
  cursor: pointer;
  vertical-align: middle; /* Align with other buttons */
}
.icon-btn:hover {
  background-color: #555;
}
.icon-btn.danger-btn {
  background-color: #dc3545;
  border-color: #dc3545;
  color: white;
}
 .icon-btn.danger-btn:hover {
  background-color: #c82333; /* Darker red on hover */
  border-color: #bd2130;
}
/* <<< ADDED Style for active queue >>> */
#btnIconClear.queue-active {
    border-color: red;
    color: white; /* Ensure number is visible */
}
/* <<< UPDATED Style for active cancel >>> */
#btnIconCancel.cancel-active {
    /* color: red; */ /* REMOVED */
    border-color: yellow;
}

/* <<< ADDED CSS FOR ICON BUTTONS >>> */
.icon-btn {
  display: inline-flex; /* Use flex to center content */
  align-items: center;
  justify-content: center;
  width: 24px; /* Fixed small width */
  height: 24px; /* Fixed small height */
  padding: 0; /* Remove padding */
  font-size: 16px; /* Adjust icon size */
  line-height: 1; /* Ensure vertical centering */
  border-radius: 4px; /* Slightly rounded corners */
  border: 1px solid #555;
  background-color: #444; /* Slightly darker background */
  color: #e0e0e0;
  cursor: pointer;
  vertical-align: middle; /* Align with other buttons */
}
.icon-btn:hover {
  background-color: #555;
}
.icon-btn.danger-btn {
  background-color: #dc3545;
  border-color: #dc3545;
  color: white;
}
 .icon-btn.danger-btn:hover {
  background-color: #c82333; /* Darker red on hover */
  border-color: #bd2130;
}
/* <<< ADDED Style for active queue >>> */
#btnIconClear.queue-active {
    border-color: red;
    color: white; /* Ensure number is visible */
}
/* <<< UPDATED Style for active cancel >>> */
#btnIconCancel.cancel-active {
    /* color: red; */ /* REMOVED */
    border-color: yellow;
}

/* === END REPLACED === */


/* Checkbox nhỏ gọn */
.tiny-checkbox {
  width: 16px;
  height: 16px;
  flex-shrink: 0; /* Không bị co kéo */
  margin: 0;
  padding: 0;
}

/* Row chứa checkbox + label */
.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%; /* ✅ để label chiếm phần còn lại */
}

/* Input checkbox trong dòng checkbox */
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Label cạnh checkbox */
.checkbox-row label {
  flex: 1; /* ✅ label chiếm hết phần còn lại */
  font-size: 0.9em;
  line-height: 1.2; /* Optional: cho cân đối chiều cao */
  white-space: nowrap; /* Không xuống dòng */
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ADDED: Specific styles for image preview container */
.node-image-preview-container {
  flex-grow: 1; /* ADDED BACK: Allow preview container to fill space */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* Prevent image overflow */
  min-height: 0; /* CHANGED: Allow shrinking completely if needed */
  border: 1px dashed #555; /* UNCOMMENTED: Show the dashed border */
}

/* ADDED/MODIFIED: Ensure image scales correctly */
.node-image-preview-container img {
  display: block; /* Needed for max-width/height to work correctly */
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* Maintain aspect ratio */
}

/* ADDED: Specific styles for dropdown row within node-body */
.node-body > .node-row:has(select) { /* Target rows in node-body that contain a select */
  flex-direction: row; /* Override the default column direction */
  align-items: center; /* Align label and select vertically */
  flex-shrink: 0; /* Prevent this row from shrinking */
  gap: 5px; /* Space between label and select */
}

.node-body > .node-row:has(select) label {
  flex-shrink: 0; /* Prevent label from shrinking */
  margin-right: 0; /* Remove default margin */
}

.node-body > .node-row:has(select) select {
  flex-grow: 1; /* Allow select to take remaining horizontal space */
  width: auto; /* Override default 100% width */
}

/* === ADDED: Style for LoRA name label within the list === */
#lora-list-container .lora-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* Allow shrinking in flex layout */
}

/* === ADDED: Prevent LoRA list container from expanding horizontally === */
#lora-list-container {
    overflow-x: hidden; /* Hide horizontal overflow */
}

/* === ADDED/UPDATED: Styles for LoRA Rows and Name Label === */
/* Style for each row */
#lora-list-container .lora-row {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
    padding: 3px 5px;
    background-color: rgba(255, 255, 255, 0.03);
    border-radius: 3px;
    overflow: hidden; /* Crucial for containing children */
    min-width: 0; /* Crucial for allowing row itself to shrink */
}

/* Style for the LoRA name label within the row */
#lora-list-container .lora-name {
    flex-grow: 1; /* Allow it to take up space */
    flex-shrink: 1; /* Allow it to shrink */
    overflow: hidden; /* Hide overflowing text */
    white-space: nowrap; /* Prevent text wrapping */
    text-overflow: ellipsis; /* Show ... for overflow */
    min-width: 0; /* Essential for shrinking in flexbox */
}

/* ADDED: Allow slider and value to shrink/flex */
#lora-list-container .lora-strength-slider {
    flex-basis: 60px; /* Suggest initial width */
    flex-grow: 0; /* Don't grow */
    flex-shrink: 1; /* ALLOW shrinking */
    min-width: 40px; /* Prevent shrinking too much */
    height: 10px; /* Keep original height */
    margin: 0 3px; 
    padding: 0;
    cursor: pointer;
}

#lora-list-container .lora-strength-value {
    flex-shrink: 1; /* ALLOW shrinking */
    min-width: 25px; /* Keep original min-width */
    text-align: right; /* Keep alignment */
    font-size: 11px;
}

/* Prevent LoRA list container from expanding horizontally */
#lora-list-container {
    overflow-x: hidden; /* Hide horizontal overflow */
}

/* === BEGIN STATS & AGENT STATUS REFACTOR === */

/* Row container (adjust gap/padding if needed in index.html inline style or here) */
.status-indicator-row {
  /* Styles already inline, but can be moved here */
  /* display: flex; */
  /* justify-content: flex-end; */
  /* align-items: center; */
  /* gap: 10px; */
  /* height: 30px; */
  /* padding-right: 5px; */
  color: #a0a0a0; /* Default light grey text for the row */
  font-size: 12px;
}

/* Remove old system-stats-bar background */
#system-stats-bar {
  /* display: none; */ /* Or simply remove rules if element is gone */
   background-color: transparent !important;
   padding: 0 !important;
   border: none !important;
   height: auto !important;
}

/* Style individual stat items */
.stat-item {
  padding: 0 5px;
  border-left: 1px solid #555; /* Keep separator */
  line-height: 1; /* Align text better */
}
.stat-item:first-child {
  border-left: none; /* Remove border for the first item */
}

/* Container for the agent status (replaces the old button style) */
.agent-status-display {
  display: inline-flex; /* Use inline-flex */
  align-items: center;
  gap: 5px; /* Gap between dot and text */
  padding: 4px 8px; /* Add some padding */
  border-radius: 6px; /* Optional: Slight rounding */
  /* Remove button-like appearance */
  background-color: transparent;
  border: none;
  cursor: default; /* Not clickable */
  margin-left: 5px; /* Add some space from stats */
}

/* The indicator dot */
.agent-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #666; /* Default grey (idle) */
  transition: background-color 0.3s ease;
}

/* Text next to the dot */
.agent-status-display .status-text {
  font-size: 12px;
  line-height: 1;
  color: inherit; /* Inherit color from parent row */
}

/* --- Color states for the dot based on parent class --- */
/* Existing JS adds classes to the #local-agent-status-indicator (now .agent-status-display) */

.agent-status-display.connecting .agent-dot,
.agent-status-display.retrying .agent-dot {
  background-color: #ffcc00; /* Yellow */
}
.agent-status-display.connecting .status-text,
.agent-status-display.retrying .status-text {
    color: #ffcc00; /* Match text color */
}


.agent-status-display.connected .agent-dot {
  background-color: #34c759; /* Green */
}
.agent-status-display.connected .status-text {
    color: #34c759; /* Match text color */
}

.agent-status-display.disconnected .agent-dot {
  background-color: #ff3b30; /* Red */
}
.agent-status-display.disconnected .status-text {
    color: #ff3b30; /* Match text color */
}


.agent-status-display.error .agent-dot {
  background-color: #ff3b30; /* Red */
}
.agent-status-display.error .status-text {
    color: #ff3b30; /* Match text color */
}

.agent-status-display.idle .agent-dot {
  background-color: #8e8e93; /* Grey */
}
.agent-status-display.idle .status-text {
    color: #8e8e93; /* Match text color */
}

/* Remove old agent-status button styles if they conflict */
.auth-btn.agent-status {
   /* Override or remove conflicting styles */
   background-color: transparent !important;
   border: none !important;
   padding: 0 !important;
   color: inherit !important;
   height: auto !important;
}
.auth-btn.agent-status:disabled {
    opacity: 1 !important; /* Ensure it's not faded when idle */
}


/* === END STATS & AGENT STATUS REFACTOR === */

.user-avatar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #555;
  background-color: #333;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  vertical-align: middle;
  transition: border-color 0.2s ease;
  z-index: 500; /* Thấp nhất - nằm dưới modal */
  position: relative;
}
.user-avatar-btn:hover {
  border-color: #888;
}
#user-avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#user-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  background-color: #555;
  color: #fff;
}
#user-dropdown-menu {
  position: fixed;
  min-width: 120px;
  background-color: #2d2d2d;
  border: 1px solid #444;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  padding: 5px 0;
  z-index: 2000; /* Cao nhất - luôn hiển thị trên tất cả */
  display: none;
}
.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 15px;
  border: none;
  background: none;
  color: #ccc;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  z-index: 1000; /* Giảm xuống, vẫn cao nhưng thấp hơn dropdown menu */
}
.dropdown-item:hover {
  background-color: #3a3a3a;
  color: #fff;
}


.agent-status-display {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.agent-status-display .status-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  right: 120%;   /* Đẩy box sang bên trái chấm */
  top: 50%;
  transform: translateY(-50%);
  background: #222;
  color: #fff;
  padding: 7px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  white-space: nowrap;
  font-size: 14px;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
}

.agent-status-display:hover .status-text {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}



/* Xếp các ảnh lịch sử thành một grid, tự chia đều không gian */
#history-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  margin-bottom: 5px;/* hoặc 5px, tuỳ bạn */
}

#history-list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  flex: 1 1 auto;      /* QUAN TRỌNG: Cho phép lấp đầy chiều cao còn lại */
  min-height: 0;       /* Để grid không bị co lại */
  max-height: unset;   /* Đảm bảo không bị giới hạn bởi max-height */
  overflow-y: auto;
}

.history-item {
  position: relative;
  width: 100%;
  padding-top: 100%;  /* Padding-top 100% giúp chiều cao bằng chiều rộng */
  overflow: hidden;
}

/* Ảnh trong mỗi ô: căng đều ô và giữ tỷ lệ */
.history-item img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}



/* ======== Style Gallery Styles (Chuẩn hóa) ======== */

/* --- Node UI Elements --- */
.style-teacache-node .node-row {
  width: 100%; /* Đảm bảo các hàng chiếm đủ chiều rộng */
}

/* --- Style Gallery Button --- */
.style-gallery-button {
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  background-color: #4a4a4a;
  color: #e0e0e0;
  border: 1px solid #666;
  border-radius: 5px;
  transition: background-color 0.2s ease;
  white-space: nowrap;
}
.style-gallery-button:hover {
  background-color: #5e5e5e;
}
.style-gallery-button:disabled {
  background-color: #3a3a3a;
  color: #888;
  cursor: not-allowed;
  border-color: #555;
}

/* --- Selected Style Name --- */
.selected-style-name {
  font-size: 12px;
  color: #aaa;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-grow: 1;
}
.selected-style-name.has-selection {
  color: #e0e0e0;
  font-style: normal;
}

/* --- Modal Overlay --- */
.style-gallery-modal {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  z-index: 1050;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.75);
  animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Modal Content Box --- */
.style-gallery-content {
  background-color: #2f2f2f;
  border: 1px solid #555;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  width: 90%;
  max-width: 900px;
  height: 85vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* --- Modal Header --- */
.style-gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #4a4a4a;
  flex-shrink: 0;
}
.style-gallery-header span {
  font-size: 1.3em;
  font-weight: 600;
  color: #e0e0e0;
}
.style-gallery-close-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  padding: 0 5px;
  transition: color 0.2s ease;
}
.style-gallery-close-btn:hover,
.style-gallery-close-btn:focus {
  color: #fff;
}

/* --- Search Input --- */
.style-gallery-search {
  width: auto;
  margin: 15px 20px;
  padding: 10px 12px;
  border: 1px solid #555;
  background-color: #3a3a3a;
  color: #e0e0e0;
  border-radius: 5px;
  box-sizing: border-box;
  font-size: 14px;
  flex-shrink: 0;
}
.style-gallery-search:focus {
  outline: none;
  border-color: #00aaff;
  box-shadow: 0 0 5px rgba(0, 170, 255, 0.5);
}

/* --- Gallery Container (Grid) --- */
.style-gallery-container {
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); /* Responsive grid (User value) */
  grid-auto-rows: max-content; /* <<< Thử để hàng tự động điều chỉnh chiều cao */
  gap: 8px;
  padding: 10px; /* <<< Đã sửa padding để đều 4 cạnh */
  width: 100%;
  margin: 0 auto;
  scrollbar-width: thin;
  scrollbar-color: #666 #333;
}
/* Scrollbar for Webkit */
.style-gallery-container::-webkit-scrollbar {
  width: 8px;
}
.style-gallery-container::-webkit-scrollbar-track {
  background: #333;
  border-radius: 4px;
}
.style-gallery-container::-webkit-scrollbar-thumb {
  background-color: #666;
  border-radius: 4px;
  border: 2px solid #333;
}
.style-gallery-container::-webkit-scrollbar-thumb:hover {
  background-color: #888;
}

/* --- Thumbnail Container --- */
.style-thumbnail-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1; /* Sử dụng aspect-ratio thay vì padding hack */
  background-color: #404040;
  border-radius: 6px;
  overflow: hidden;
  border: 3px solid transparent;
  transition: border-color 0.2s ease;
}
/* --- Thumbnail Images --- */
.style-thumbnail {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  object-fit: cover;
  cursor: pointer;
  /* border: 3px solid transparent; <<< Xóa border ở đây */
  border-radius: 6px; /* Giữ bo góc cho ảnh */
  transition: transform 0.2s ease; /* Chỉ transition transform */
  background-color: #404040;
}

/* --- Hover và Selected States --- */
.style-thumbnail-container:hover {
  border-color: #00aaff; /* <<< Đổi border container khi hover */
}

.style-thumbnail:hover {
  /* border-color: #00aaff; <<< Xóa */
  transform: scale(1.03);
  z-index: 10;
}

.style-thumbnail-container.selected { /* <<< Selector mới cho container selected */
  border-color: #00ff88;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.7);
}

.style-thumbnail.selected {
  /* border-color: #00ff88; <<< Xóa */
  /* box-shadow: 0 0 10px rgba(0, 255, 136, 0.7); <<< Xóa */
  transform: scale(1.03);
}

/* --- Thumbnail Error Styles --- */
.style-thumbnail.image-error {
  object-fit: contain;
  padding: 15%;
  background-color: #4a4a4a;
  opacity: 0.7;
}
/* Remove the empty ruleset below */
/*
.style-thumbnail.image-error:hover,
.style-thumbnail.image-error.selected {
  /* border-color: #ff4d4d; */ /* Có thể cần áp dụng cho container nếu muốn viền lỗi */
  /* box-shadow: 0 0 8px rgba(255, 77, 77, 0.6); */
/* }
*/

/* --- Gallery Messages --- */
.style-gallery-message,
.style-gallery-error {
  grid-column: 1 / -1;
  text-align: center;
  color: #aaa;
  padding: 20px;
  font-style: italic;
}
.style-gallery-error {
  color: #ff8a8a;
  font-weight: bold;
}



/* ======== Kết thúc Style Gallery Styles ======== */
/* Style for disabled UI elements */
.disabled-ui {
  opacity: 0.4; /* Make it partially transparent */
  pointer-events: none; /* Disable all mouse interactions */
  user-select: none; /* Prevent text selection */
  /* Optional: Add a grayscale filter */
  /* filter: grayscale(80%); */ 
}

/* Ensure the disabled effect applies correctly to child inputs/selects if needed */
.disabled-ui input,
.disabled-ui select,
.disabled-ui button {
    /* Styles here might be needed if pointer-events: none on parent isn't enough */
    /* e.g., background-color: #444 !important; */
}

/* Voice Create Gradient */
.voice-create-gradient {
  width: 100%;
  height: 200px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.voice-create-gradient::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg,
    rgba(102, 126, 234, 0.9) 0%,
    rgba(118, 75, 162, 0.9) 50%,
    rgba(255, 94, 77, 0.8) 100%);
  animation: gradientShift 3s ease-in-out infinite alternate;
}

.voice-text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.1em;
  position: relative;
  z-index: 2;
  text-transform: uppercase;
}

@keyframes gradientShift {
  0% {
    background: linear-gradient(135deg,
      rgba(102, 126, 234, 0.9) 0%,
      rgba(118, 75, 162, 0.9) 50%,
      rgba(255, 94, 77, 0.8) 100%);
  }
  100% {
    background: linear-gradient(135deg,
      rgba(255, 94, 77, 0.9) 0%,
      rgba(118, 75, 162, 0.9) 50%,
      rgba(102, 126, 234, 0.8) 100%);
  }
}

/* Responsive for Voice Create */
@media (max-width: 768px) {
  .voice-text {
    font-size: 2rem;
  }
}