:root {
  --primary-color: #0071e3;
  --bg-color: #f5f5f7;
  --card-bg: rgba(255, 255, 255, 0.8);
  --text-main: #1d1d1f;
  --text-secondary: #86868b;
  --sidebar-w: 320px;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* Sidebar Styling */
aside {
  width: var(--sidebar-w);
  height: 100%;
  min-height: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-right: 1px solid var(--glass-border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
  z-index: 10;
}

.title-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.title-header img {
  border-radius: 8px;
}

.title-header h1 {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-main);
}

.section-label {
  font-size: 0.8em;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin: 16px 0 8px 0;
  letter-spacing: 0.5px;
}

/* Form Elements */
.control-group {
  margin-bottom: 20px;
}

.source-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.selected-files-panel {
  margin-top: 8px;
  height: 120px;
  overflow-y: auto;
  border: 1px solid #d2d2d7;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.selected-files-panel.empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.selected-files-placeholder {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.selected-files-list {
  list-style: none;
  font-size: 12px;
}

.selected-files-list li {
  padding: 4px 0;
  border-bottom: 1px solid #f0f0f2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-files-list li:last-child {
  border-bottom: none;
}

button {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.2);
}

.btn-primary:hover {
  background-color: #0077ed;
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  color: var(--text-main);
  border: 1px solid #d2d2d7;
}

.btn-secondary:hover:not(:disabled) {
  background: #fbfbfd;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="number"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #d2d2d7;
  outline: none;
  margin-top: 4px;
}

.radio-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #d2d2d7;
  font-size: 13px;
  cursor: pointer;
}

/* Main Content area */
main {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Progress Section */
#progress_section {
  background: white;
  padding: 20px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: none;
  /* Shown when processing */
}

#progress_section.active {
  display: block;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9em;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e5e5e7;
  border-radius: 4px;
  overflow: hidden;
}

#progress_bar_fill {
  height: 100%;
  background: var(--primary-color);
  width: 0%;
  transition: width 0.3s ease;
}

/* Gallery / Large Previews */
/* Results Gallery - Tight Row Style */
#gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

.result-card {
  width: 200px;
  margin-bottom: 10px;
}

.result-card img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid #ddd;
  cursor: pointer;
  display: block;
}

.result-card h3 {
  font-size: 11px;
  margin-top: 5px;
  color: #666;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-actions {
  margin-top: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.result-actions button {
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid #d2d2d7;
  background: #fff;
  color: #1d1d1f;
  box-shadow: none;
}

.result-actions button:hover {
  background: #f8f8fa;
  transform: none;
}

.cookie-banner {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: 20px;
  z-index: 20000;
  background: #1d1d1f;
  color: #fff;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.cookie-banner.hidden {
  display: none;
}

.cookie-banner p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  flex: 1;
}

.cookie-banner button {
  width: auto;
  padding: 8px 14px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .cookie-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  .cookie-banner button {
    width: 100%;
  }
}

.empty-state {
  flex: 1;
  width: 100%;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-align: center;
  padding: 40px;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 20px;
  user-select: none;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 360px;
  margin: 0 auto;
}

#status_box {
  margin-top: auto;
  font-size: 13px;
}

.progress-bg {
  width: 100%;
  height: 10px;
  background: #eee;
  border-radius: 5px;
  margin-top: 10px;
}

#progress_fill {
  width: 0%;
  height: 100%;
  background: #007bff;
  border-radius: 5px;
  transition: width 0.2s;
}

/* Main Content */
.main-content {
  flex-grow: 1;
  padding: 40px;
  overflow-y: auto;
  background: #fff;
}

/* Image Preview Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  display: none; /* Hidden by default */
  justify-content: center;
  align-items: center;
  z-index: 9999;
  cursor: zoom-out;
}

.modal-overlay.active {
  display: flex !important;
}

.modal-content {
  position: relative;
  max-width: 95%;
  max-height: 95%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.modal-toolbar {
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: 160px 1fr 160px;
  gap: 8px;
  align-items: center;
}

.modal-filename {
  color: #fff;
  text-align: center;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-nav-btn {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12px;
}

.modal-nav-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

.modal-nav-btn:disabled {
  opacity: 0.45;
}

.modal-content img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 4px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  cursor: default;
}

.modal-close {
  position: fixed;
  top: 20px;
  right: 30px;
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10000;
}

@media (max-width: 760px) {
  .modal-toolbar {
    grid-template-columns: 1fr;
  }

  .modal-filename {
    order: -1;
  }
}