:root {
  --bg: #f7f5f2;
  --card: #ffffff;
  --text: #2a2622;
  --muted: #8a8378;
  --accent: #c9722c;
  --accent-dark: #a85a1e;
  --border: #e6e1d8;
  --success: #4a7c59;
  --error: #b5453a;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
}

nav.tabs a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 20px;
  font-size: 14px;
  font-weight: 500;
  padding-bottom: 4px;
}

nav.tabs a.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
  font-size: 16px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 14px;
  background: #fff;
  color: var(--text);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.secondary:hover {
  background: #fbeee1;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.hidden {
  display: none !important;
}

.pill {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f0ece3;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pill.status-completed { background: #e5f0e7; color: var(--success); }
.pill.status-processing { background: #fdf1e2; color: var(--accent-dark); }
.pill.status-failed { background: #fbe9e7; color: var(--error); }
.pill.status-pending { background: #eee; color: var(--muted); }

.preview-img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 10px;
}

.caption-box {
  background: #fbf9f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.caption-box .label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.msg {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
}

.msg.error { background: #fbe9e7; color: var(--error); }
.msg.success { background: #e5f0e7; color: var(--success); }
.msg.info { background: #eef2f6; color: #3c5a75; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.history-card {
  position: relative;
}

.history-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #eee;
  cursor: pointer;
  transition: opacity 0.15s;
}

.history-card img:hover {
  opacity: 0.85;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.lightbox-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
  z-index: 1;
}

.delete-btn:hover {
  opacity: 1;
  background: var(--error);
}

.photo-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.photo-picker-item {
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: #fff;
}

.photo-picker-item img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}

.photo-picker-item .name {
  font-size: 10px;
  padding: 4px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-picker-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.actions-slot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.history-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.history-card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.filters {
  margin-bottom: 20px;
}

.filters select {
  max-width: 240px;
  margin-bottom: 0;
}
