/* Core Design System Variables */
:root {
  /* Default Light Theme variables */
  --bg-app: #f4f6f9;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-secondary: #0ea5e9;
  --accent-success: #16a34a;
  --accent-success-bg: #dcfce7;
  --accent-error: #dc2626;
  --accent-error-bg: #fee2e2;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font-family: 'Plus+Jakarta+Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark Theme Variables overriding default */
html.theme-dark {
  --bg-app: #0b0f19;
  --bg-card: #151d30;
  --border: #232d45;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-secondary: #38bdf8;
  --accent-success: #22c55e;
  --accent-success-bg: rgba(34, 197, 94, 0.15);
  --accent-error: #ef4444;
  --accent-error-bg: rgba(239, 68, 68, 0.15);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.3), 0 2px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

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

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.95rem;
  line-height: 1.6;
  padding-bottom: 3rem;
  transition: var(--transition);
}

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Header styling */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.logo-section h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo-section h1 span {
  color: var(--accent);
}

.logo-section p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Theme Toggle Slider */
.theme-toggle {
  position: relative;
  display: inline-block;
  width: 170px;
  height: 42px;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  transition: var(--transition);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border: 1px solid rgba(0,0,0,0.05);
}

.theme-toggle .slider .icon {
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 2;
  transition: var(--transition);
}

.theme-toggle .slider .sun {
  color: var(--text-main);
}

.theme-toggle .slider .moon {
  color: var(--text-muted);
}

.theme-toggle .slider::before {
  position: absolute;
  content: "";
  height: 34px;
  width: 80px;
  left: 4px;
  bottom: 3px;
  background-color: var(--bg-card);
  transition: var(--transition);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  z-index: 1;
}

.theme-toggle input:checked + .slider::before {
  transform: translateX(80px);
}

.theme-toggle input:checked + .slider .sun {
  color: var(--text-muted);
}

.theme-toggle input:checked + .slider .moon {
  color: var(--text-main);
}

/* Card layout */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

/* Collapsible Manual Guide */
.manual-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.manual-header h3 {
  margin: 0;
}

.toggle-icon {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: var(--transition);
}

.manual-header.active .toggle-icon {
  transform: rotate(180deg);
}

.manual-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out;
}

.manual-content.show {
  max-height: 600px;
  margin-top: 1.5rem;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.step-card {
  background: var(--bg-app);
  padding: 1.25rem;
  border-radius: var(--radius-sm);
  position: relative;
  border: 1px solid var(--border);
}

.step-num {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-muted);
  opacity: 0.15;
}

.step-card h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.step-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.step-card code {
  background: var(--bg-card);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

/* Workspace layout columns */
.workspace-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 992px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

/* Form Styling */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: var(--bg-app);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
  resize: vertical;
}

/* Helper Tooltip Icon */
.help-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 16px;
  height: 16px;
  font-size: 0.7rem;
  background: var(--border);
  border-radius: 50%;
  cursor: help;
  color: var(--text-muted);
}

/* Button Styling */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.8rem 1.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  gap: 0.5rem;
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
}

.btn-primary:not(:disabled):hover {
  background-color: var(--accent-secondary);
}

.btn-secondary {
  background-color: var(--border);
  color: var(--text-main);
  border: 1px solid rgba(0,0,0,0.05);
}

.btn-secondary:not(:disabled):hover {
  background-color: var(--bg-app);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 4px;
}

.badge-info {
  background-color: var(--border);
  color: var(--text-muted);
}

.badge-active {
  background-color: var(--accent-success-bg);
  color: var(--accent-success);
}

/* 15 API Key slots styling */
.api-slots-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 5px;
}

.api-slots-container::-webkit-scrollbar {
  width: 6px;
}

.api-slots-container::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 3px;
}

.api-slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-app);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.api-slot .label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 50px;
}

.api-slot input {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}

.api-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--border);
  flex-shrink: 0;
  transition: var(--transition);
}

.api-indicator.valid {
  background-color: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
}

.api-indicator.invalid {
  background-color: var(--accent-error);
}

.api-indicator.checking {
  border: 2px solid var(--accent);
  border-top-color: transparent;
  background-color: transparent;
  animation: spin 1s linear infinite;
  border-radius: 50%;
}

/* Products Table */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.product-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.product-table th,
.product-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.product-table th {
  background: var(--bg-app);
  font-weight: 700;
}

.product-table tr:last-child td {
  border-bottom: none;
}

.table-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--accent-error);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  border-radius: 4px;
}

.delete-btn:hover {
  background: var(--accent-error-bg);
}

/* Microstock-style Progress Dashboard */
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.active-api-indicator {
  background-color: var(--accent);
  color: #ffffff;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
}

.progress-timer-container {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background-color: var(--bg-app);
  padding: 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.timer-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background-color: var(--bg-card);
  border-radius: 50%;
  border: 4px solid var(--accent);
  flex-shrink: 0;
}

.timer-number {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.timer-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.progress-text-info h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.progress-text-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.progress-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.progress-bar-container {
  height: 12px;
  background-color: var(--border);
  border-radius: 6px;
  flex-grow: 1;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background-color: var(--accent-success);
  border-radius: 6px;
  transition: width 0.4s ease;
}

.progress-percentage {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 35px;
}

.error-log-box {
  margin-top: 1.25rem;
  background: var(--accent-error-bg);
  border: 1px solid var(--accent-error);
  padding: 1rem;
  border-radius: var(--radius-sm);
  color: var(--accent-error);
}

.error-log-box h5 {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.error-log-box ul {
  font-size: 0.8rem;
  padding-left: 1.25rem;
}

/* Success Download Banner */
.success-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  background-color: var(--accent-success-bg);
  border: 1px solid var(--accent-success);
  padding: 1.25rem;
  border-radius: var(--radius-sm);
  color: var(--accent-success);
  margin-bottom: 1.25rem;
}

.success-banner svg {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.success-banner h3 {
  font-size: 1.1rem;
  margin-bottom: 0.2rem;
}

.success-banner p {
  font-size: 0.85rem;
  opacity: 0.9;
}

.download-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.download-card .btn {
  text-decoration: none;
}

/* Preview results and Tabs */
.preview-tabs {
  display: flex;
  gap: 0.5rem;
}

.tab-btn {
  padding: 0.4rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  transition: var(--transition);
}

.tab-btn.active {
  background-color: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.tab-content {
  display: none;
  margin-top: 1.5rem;
}

.tab-content.active {
  display: block;
}

/* Pins Grid Preview */
.pins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
}

.pin-preview-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-app);
}

.pin-preview-item img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}

.pin-info-overlay {
  padding: 0.5rem;
  font-size: 0.75rem;
}

.pin-info-overlay .title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}

.pin-info-overlay .meta {
  color: var(--text-muted);
}

/* Threads Storytelling list */
.threads-list {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.thread-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-app);
  padding: 1.25rem;
}

.thread-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.thread-title {
  font-weight: 700;
  font-size: 0.9rem;
}

.thread-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.thread-body-scroll {
  background-color: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 1rem;
  max-height: 250px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.copy-thread-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  background-color: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  transition: var(--transition);
}

.copy-thread-btn:hover {
  background-color: var(--accent-secondary);
}

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

/* Mobile Responsive Breakpoints */
@media (max-width: 768px) {
  .container {
    padding: 0.75rem;
  }
  
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .theme-toggle {
    align-self: flex-end;
  }
  
  .form-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .download-buttons {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .pins-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
  }
  
  .product-table th:nth-child(3),
  .product-table td:nth-child(3) {
    display: none; /* Hide price column on small mobile screens to fit inputs */
  }

  .thread-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  
  .thread-meta {
    font-size: 0.7rem;
  }
}

/* Modal overlay styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 580px;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  animation: modalScale 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.close-modal {
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.close-modal:hover {
  color: var(--text-main);
}

@keyframes modalScale {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
