
@font-face {
    font-family: 'Google Sans';
    src: url('fonts/GoogleSans-Bold.woff2') format('woff2'),
         url('fonts/GoogleSans-Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Google Sans';
    src: url('fonts/GoogleSans-Medium.woff2') format('woff2'),
         url('fonts/GoogleSans-Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Google Sans';
    src: url('fonts/GoogleSans-Regular.woff2') format('woff2'),
         url('fonts/GoogleSans-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
/* Light Mode Variables (default) */
:root {
  --primary: #007aff;
  --bg: #f5f5f7;
  --text: #1c1c1e;
  --panel-bg: #fff; /* Background for sidebar and main */
  --border-color: #e0e0e0;
  --drop-area-bg: #f9f9f9;
  --drop-area-highlight: #e6f7ff;
  --group-bg: #fdfdfd;
  /* Removed --thumb-hover-transform as it causes scrollbar */
  --thumb-done-bg: var(--primary);
  --thumb-info-bg: rgba(0, 0, 0, 0.7); /* Background for hover info on cropped thumb */
  --drag-over-border: 2px solid var(--primary); /* New: Drag over border */
  --drag-source-opacity: 0.5; /* New: Opacity for dragged item */
}

/* Dark Mode Variables */
body.dark-mode {
  --primary: #8ab4f8; /* Lighter blue for dark mode */
  --bg: #1c1c1e;
  --text: #e8eaed;
  --panel-bg: #2d2d2d;
  --border-color: #444;
  --drop-area-bg: #3c3c3c;
  --drop-area-highlight: #4a4a4a;
  --group-bg: #3a3a3a;
  --thumb-done-bg: var(--primary); /* Use primary color for dark mode done indicator */
  --thumb-info-bg: rgba(255, 255, 255, 0.2); /* Background for hover info on cropped thumb in dark mode */
  --drag-over-border: 2px solid var(--primary); /* New: Drag over border for dark mode */
  --drag-source-opacity: 0.5; /* New: Opacity for dragged item */
}

* {
  box-sizing: border-box;
}
body {
  font-family: 'Google Sans', sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s; /* Smooth transition for dark mode */
}
h1 {
  font-size: 1.9rem;
  font-weight: 600;
  margin: 8px 0;
  text-align: center;
  font-family: "Saira", sans-serif;
}
h3 {
  font-family: "Saira", sans-serif;
  font-weight: 600;
  font-size: 19px;
  margin: 0.5rem 0rem 1rem;
  text-decoration: underline; /* Thêm gạch chân */
  text-underline-offset: 5px; /* Đặt khoảng cách gạch chân dưới 5px */
}
.wrapper {
  max-width: 1366px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  padding: 0 8px;
  overflow: hidden;
  transition: border-color 0.3s;
}
.container {
  flex: 1;
  display: flex;
  gap: 12px;
  overflow: hidden;
  height: 100%;
}
.sidebar, .main {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--panel-bg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: background-color 0.3s, border-color 0.3s;
}
.sidebar {
  width: 25%;
  min-width: 200px;
  overflow-y: auto;
}
/* Thêm lại sidebar-content để đẩy nút xuống cuối */
.sidebar-content {
  flex-grow: 1; /* Đẩy button xuống cuối */
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* Cho phép nội dung bên trong cuộn */
}
.main {
  flex: 1;
  overflow-y: auto;
}
/* Styles cho khu vực kéo thả */
.drop-area {
    border: 2px dashed var(--primary);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
    font-size: 1rem;
    cursor: pointer;
    background: var(--drop-area-bg);
    margin-bottom: 12px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 98px; /* Đảm bảo đủ không gian */
    transition: background-color 0.3s ease;
}
.drop-area.highlight {
    background-color: var(--drop-area-highlight);
}
.drop-area input[type="file"] {
    display: none; /* Ẩn input mặc định */
}
.drop-area p {
    margin: 2px 0;
    color: var(--text);
}
.drop-area button {
    padding: 8px 15px;
    font-size: 0.9rem;
    margin-top: 5px;
    margin-bottom: 4px;
    width: auto;
}

.thumb {
  width: 100%;
  margin-bottom: 8px;
  position: relative;
  cursor: grab; /* Change cursor for draggable items */
  border: 1px solid var(--border-color); /* Add border to thumb */
  border-radius: 6px; /* Apply to the whole thumb */
  overflow: hidden; /* Ensure content respects border-radius */
  transition: box-shadow 0.2s ease-in-out, border-color 0.2s ease-in-out; /* New transition */
}
.thumb:hover {
  /* New hover effect */
  box-shadow: 0 0 8px rgba(0, 122, 255, 0.3);
  border-color: var(--primary);
}
.thumb img {
  width: 100%;
  display: block; /* Ensure no extra space below image */
  border-radius: 6px 6px 0 0; /* Only top corners rounded for image */
  margin-bottom: 0; /* Remove default margin */
}
.thumb.done::after {
  content: "\2713";
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--thumb-done-bg);
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
/* Styling for original image info within the thumbnail */
.thumb .thumb-info-original {
    font-size: 0.7rem; /* Smaller font for original info */
    color: #666; /* Softer color */
    padding: 2px 5px;
    text-align: center; /* Changed to center */
    white-space: nowrap; /* Keep text on one line */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Add ellipsis for overflow */
    background-color: var(--panel-bg); /* Match panel background */
    border-top: 1px solid var(--border-color); /* Separator from image */
    line-height: 1.2;
    padding-top: 5px;
    padding-bottom: 5px;
    box-sizing: border-box; /* Include padding in element's total width and height */
    max-width: 100%; /* Ensure it doesn't overflow its parent */
    display: flex; /* Use flexbox to align filename and details */
    flex-direction: column; /* Stack filename, dimensions, size vertically */
    gap: 2px; /* Small gap between lines */
}
/* Style for cropped preview overlay */
.thumb .cropped-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none; /* Hidden by default, shown when cropped */
    object-fit: contain; /* Ensure image fits well */
    background-color: var(--panel-bg); /* Background for preview area */
    border-radius: 6px; /* Match thumb border radius */
}
.thumb.done .cropped-preview {
    display: block; /* Show preview when done */
}
.thumb .thumb-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--thumb-info-bg);
    color: white;
    font-size: 0.75rem;
    padding: 3px 5px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    pointer-events: none;
}
.thumb:hover .thumb-info {
    opacity: 1;
}

/* New: Styles for individual remove button on thumbnail */
.thumb .remove-thumb-btn {
    position: absolute;
    top: 0px; /* Adjust as needed for padding/margin */
    left: 0px; /* Adjust as needed for padding/margin */
    background: rgba(255, 0, 0, 0.7); /* Red background */
    color: white;
    border: none;
    border-radius: 5px 0 5px 0; /* Rounded top-right and bottom-left */
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    z-index: 10; /* Ensure it's on top */
    opacity: 0.8;
    transition: background-color 0.2s, opacity 0.2s;
    line-height: 1; /* Adjust line height for better centering of X */
    padding: 0;
}
.thumb .remove-thumb-btn:hover {
    background-color: rgba(255, 0, 0, 0.9);
    opacity: 1;
}

/* Drag and Drop Styling for Thumbs */
.thumbs-list {
    display: flex;
    flex-direction: column;
}
.thumb.dragging {
    opacity: var(--drag-source-opacity); /* Make dragged item semi-transparent */
}
.thumb.drag-over {
    border: var(--drag-over-border); /* Highlight border for drag-over effect */
}

footer p {
    font-size: 14px;
    line-height: 0.6;
}

footer p a {
 color: var(--primary); /* Sử dụng màu primary đã định nghĩa trong theme */
 text-decoration: none; /* Loại bỏ dấu gạch dưới */
 transition: color 0.3s ease; /* Thêm hiệu ứng chuyển màu khi hover (tùy chọn) */
}

footer p a:hover {
 color: darken(var(--primary), 10%); /* Màu đậm hơn khi hover (tùy chọn) */
}

label, input, button {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  font-family: 'Google Sans', sans-serif;
  font-weight: 400;
}
input[type="number"],
input[type="text"],
select {
  padding: 8px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
  transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  font-family: 'Google Sans', sans-serif;
}

input[type="color"] {
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-sizing: border-box;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border: none;
  border-radius: 10px;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 10px;
  padding: 0;
  margin: 0;
}

input[type="color"]::-moz-focus-inner {
  border: none;
}
button {
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  background-color: var(--primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.3s;
  display: flex; /* Dùng flexbox cho nội dung nút */
  align-items: center;
  justify-content: center;
  gap: 8px; /* Khoảng cách giữa text và icon */
}
button:hover {
  filter: brightness(1.1); /* Dùng filter để làm sáng hover */
}
button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

#aspectRatioLinkBtn {
    max-width: 50px;
    margin: auto;
    padding: 13px;
}

/* Styles cho nút "Xử lý lại tất cả ảnh" */
#processAll {
    background-color: #6c757d; /* Màu xám */
}
#processAll:hover:not(:disabled) {
    background-color: #5a6268;
}

/* Styles cho nút "Lưu Cài đặt" */
#manualSaveSettings {
    background-color: #28a745; /* Màu xanh lá cây */
}
#manualSaveSettings:hover {
    background-color: #218838;
}
/* Styles cho nút "Xóa tất cả ảnh đã tải" */
#clearAllImages {
  background-color: #dc3545; /* Màu đỏ */
  margin-bottom: 0;
}
#clearAllImages:hover:not(:disabled) {
  background-color: #c82333;
}
/* Styles for "Lưu ảnh này" button */
#saveCurrentOnly {
    background-color: #17a2b8; /* Info blue */
}
#saveCurrentOnly:hover {
    background-color: #138496;
}
/* Styles for "Clear Settings" button */
#clearSettings {
    background-color: #ffc107; /* Warning yellow */
    color: #343a40; /* Dark text for contrast */
}
#clearSettings:hover {
    background-color: #e0a800;
}

#image-container {
  width: 100%;
  position: relative;
  border-radius: 12px;
  background: var(--panel-bg);
  margin-bottom: 10px;
  overflow: visible;
  aspect-ratio: auto;
  min-height: 200px;
  flex-grow: 1; /* Cho phép image-container chiếm không gian còn lại */
  transition: background-color 0.3s;
}
#image-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-color: var(--preview-bg, #fff);
  z-index: 0;
}
#image {
  display: block;
  position: relative;
  z-index: 1;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}
.cropper-modal {
  background-color: transparent !important;
}
.cropper-crop-box {
  border: 1px solid rgba(0, 122, 255, 0.9) !important;
  box-shadow: 0 0 6px rgba(0, 122, 255, 0.5);
}
/* CSS cho đường căn giữa */
.guide-line {
  position: absolute;
  background-color: var(--primary); /* Màu của đường căn */
  z-index: 2; /* Đảm bảo nằm trên hình ảnh nhưng dưới khung cắt */
}
.guide-line.horizontal {
  width: 100%;
  height: 1px;
  left: 0;
}
.guide-line.vertical {
  height: 100%;
  width: 1px;
  top: 0;
}
/* CSS cho xem trước thumbnail đã crop (đã ẩn) */
.thumb-preview-container {
    display: none; /* Đã ẩn */
}
.options-group {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 5px;
    background: var(--group-bg);
    transition: background-color 0.3s, border-color 0.3s;
}
.options-group label {
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text);
}
.options-group input, .options-group select {
    margin-bottom: 8px;
}
.options-group input[type="color"] {
    height: 38px;
}
.flex-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}
.flex-row label {
    flex-shrink: 0;
    width: auto;
    margin-bottom: 0;
}
.flex-row input, .flex-row select {
    flex-grow: 1;
    margin-bottom: 0;
}
/* CSS cho bố cục 3 cột */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); /* 3 cột tự điều chỉnh */
    gap: 15px;
    margin-bottom: 5px;
}

/* CSS cho các nút hành động chính */
.main-action-buttons {
    display: flex;
    gap: 10px; /* Khoảng cách giữa các nút */
    margin-top: 6px; /* Khoảng cách với phần trên */
    flex-wrap: wrap; /* Cho phép các nút xuống dòng trên màn hình nhỏ hơn */
    justify-content: center; /* Căn giữa các nút theo chiều ngang */
}
.main-action-buttons button {
    flex: 1; /* Chia đều không gian cho các nút */
    min-width: 150px; /* Đảm bảo nút không quá nhỏ */
    margin-bottom: 0; /* Loại bỏ margin-bottom mặc định */
}

/* Spinner CSS */
.spinner {
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* CSS cho Progress Bar */
#progressBarContainer {
    width: 100%;
    background-color: var(--border-color);
    border-radius: 10px;
    height: 20px;
    margin-top: 10px;
    overflow: hidden;
    display: none; /* Mặc định ẩn */
    transition: background-color 0.3s;
}
#progressBar {
    height: 100%;
    width: 0%;
    background-color: var(--primary);
    border-radius: 10px;
    text-align: center;
    color: white;
    font-size: 0.8rem;
    line-height: 20px;
    transition: width 0.3s ease-in-out, background-color 0.3s;
}

/* Toast Notifications */
#toastContainer {
    position: fixed;
    top: 20px; /* Changed from bottom to top */
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end; /* Align toasts to the right */
}
.toast {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(-20px); /* Start above the screen */
    animation: slideInFadeOut 3s forwards; /* Use new animation */
    min-width: 250px;
    text-align: center;
}

/* New animation for toasts */
@keyframes slideInFadeOut {
    0% { opacity: 0; transform: translateY(-20px); } /* Start above, hidden */
    10% { opacity: 1; transform: translateY(0); }    /* Slide down, fully visible */
    90% { opacity: 1; transform: translateY(0); }    /* Stay visible */
    100% { opacity: 0; transform: translateY(-20px); } /* Slide up, hidden */
}

/* Dark Mode Toggle Switch */
.dark-mode-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
  -webkit-transform: translateX(16px);
  -ms-transform: translateX(16px);
  transform: translateX(16px);
}

/* Animation cho icon tải về */
@keyframes downloadFloating {
    0%, 100% { transform: translateY(0); } /* Bắt đầu và kết thúc ở vị trí ban đầu */
    50% { transform: translateY(-3px); }  /* Nhảy lên 3px ở giữa chu kỳ */
}

/* Áp dụng animation trực tiếp cho icon khi nút hiển thị */
#downloadAll .fas.fa-file-archive {
    animation: downloadFloating 1.5s ease-in-out infinite; /* Chạy animation liên tục */
    /* 1.5s: thời gian một chu kỳ animation */
    /* ease-in-out: kiểu tăng tốc mượt mà */
    /* infinite: lặp vô hạn */
}
/* Keyframes cho hiệu ứng chạy sáng */
@keyframes shine {
    to {
        background-position: 200% 0;
    }
}

/* Áp dụng hiệu ứng cho nút */
button#downloadAll {
    flex: 1;
    min-width: 150px;
    margin-bottom: 0;
    background-image: linear-gradient(90deg, transparent, #19cf43, transparent); /* Tạo lớp phủ gradient trắng nhạt */
    background-size: 200% auto; /* Đảm bảo gradient đủ rộng để chạy qua */
    background-position: 0 0; /* Bắt đầu từ bên trái */
    animation: shine 2s linear infinite; /* Chạy animation liên tục */
    /* Điều chỉnh 2s để thay đổi tốc độ chạy sáng */
}