:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --text2: #999;
  --accent: #c850c0;
  --accent2: #4158d0;
  --green: #34c759;
  --red: #ff453a;
  --yellow: #ffd60a;
  --blue: #6ea8fe;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Auth Screen ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  flex-direction: column;
  gap: 16px;
}

#auth-screen h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

#auth-screen input {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  width: 280px;
  outline: none;
}

#auth-screen button {
  padding: 12px 32px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

/* ── Layout ── */
#app {
  display: none;
}

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

header h1 {
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.api-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 36px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 10px;
  transition: all 0.3s ease;
}

.api-counter.safe {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.api-counter.warning {
  color: #fbbf24;
  border-color: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

.api-counter.danger {
  color: #ef4444;
  border-color: #dc2626;
  box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
}

/* ── Console Box ── */
.console-box {
  background: #111;
  color: #0f0;
  padding: 10px;
  margin: 15px 20px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.9em;
  box-shadow: inset 0 0 10px #000;
}

.console-header {
  color: #aaa;
  border-bottom: 1px solid #333;
  padding-bottom: 5px;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.console-actions {
  display: flex;
  gap: 6px;
}

.console-actions .btn {
  background: #333;
  color: #ddd;
  border-color: #444;
  padding: 2px 8px;
  font-size: 0.75rem;
}

.console-actions .btn:hover {
  background: #444;
}

#console-logs {
  max-height: 200px;
  overflow-y: auto;
}

/* ── Stats ── */
.stats-row {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  overflow-x: auto;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 130px;
  flex-shrink: 0;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text2);
  margin-top: 2px;
}

/* ── Filters ── */
.filters {
  padding: 8px 24px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border: none;
  color: white;
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-green {
  background: var(--green);
  border-color: var(--green);
  color: #000;
  font-weight: 600;
}

.btn-red {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 600;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.75rem;
}

/* ── Draft Cards ── */
.drafts-grid {
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.draft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s;
}

.draft-card:hover {
  transform: translateY(-2px);
}

.media-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/5;
  background: var(--surface2);
}

.draft-images {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  height: 100%;
  scrollbar-width: none;
  /* Hide scrollbar Firefox */
}

.draft-images::-webkit-scrollbar {
  display: none;
  /* Hide scrollbar Chrome/Safari */
}

.draft-images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  flex-shrink: 0;
  scroll-snap-align: start;
}

/* Slide wrapper — positions overlay button */
.slide-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  flex-shrink: 0;
  scroll-snap-align: start;
}

.slide-wrap img {
  flex-shrink: unset;
  scroll-snap-align: unset;
}

/* Slide action buttons container */
.slide-actions {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 15;
}

.slide-wrap:hover .slide-actions {
  opacity: 1;
}

/* Edit Text Overlay / Regenerate buttons */
.overlay-edit-btn {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

.overlay-edit-btn:hover {
  background: rgba(0, 0, 0, 0.9);
}

.draft-images .no-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 0.9rem;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  font-size: 1.5rem;
  line-height: 1;
  padding-bottom: 4px;
  /* Visual centering adjustment */
  transition: opacity 0.2s;
  opacity: 0;
  /* Hidden by default until hovered or JS enables */
  pointer-events: none;
}

.media-wrapper:hover .nav-btn {
  opacity: 1;
  pointer-events: auto;
}

.nav-btn.hidden {
  display: none;
}

.nav-btn.prev {
  left: 8px;
}

.nav-btn.next {
  right: 8px;
}

.slide-counter {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  z-index: 10;
}

.draft-body {
  padding: 14px;
}

.draft-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.draft-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-pending {
  background: var(--yellow);
  color: #000;
}

.badge-approved {
  background: var(--green);
  color: #000;
}

.badge-published {
  background: var(--accent);
  color: #fff;
}

.badge-rejected {
  background: var(--red);
  color: #fff;
}

.badge-scheduled {
  background: var(--blue);
  color: #000;
}

.schedule-badge {
  font-size: 0.8rem;
  color: var(--blue);
  padding: 4px 0;
}

.schedule-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 12px;
  color-scheme: dark;
}

.badge-single {
  background: var(--surface2);
  color: var(--text2);
}

.badge-carousel {
  background: var(--accent2);
  color: #fff;
}

.draft-caption {
  font-size: 0.8rem;
  color: var(--text2);
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
  margin-bottom: 10px;
  white-space: pre-line;
}

.draft-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

#confirm-modal {
  z-index: 1000;
}

#error-modal {
  z-index: 1001;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.modal input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.modal label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 4px;
  margin-top: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions-center {
  justify-content: center;
}

/* Modal variants */
.modal-sm {
  max-width: 400px;
  text-align: center;
}

.modal-sm h2.error-title {
  color: var(--red);
}

.modal-sm p {
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-sm .confirm-message {
  color: var(--text2);
}

/* Sidebar specific styles */
.sidebar-header {
  margin-bottom: 16px;
  font-size: 1.1rem;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-count {
  font-size: 0.8rem;
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text2);
}

.sidebar-fetch-btn {
  width: 100%;
  margin-bottom: 16px;
}

/* Filters override */
.filters {
  margin-bottom: 20px;
  padding: 0;
}

/* Drafts grid override */
.drafts-grid {
  padding: 0;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* Form select */
.modal select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

/* Regenerate btn in label */
.label-action-btn {
  float: right;
  margin-top: -5px;
}

/* Timestamp small */
.timestamp {
  font-size: 0.7rem;
  color: var(--text2);
}

.sidebar-item-date {
  font-size: 0.75rem;
  color: var(--text2);
  margin-bottom: 4px;
}

/* ── Edit Modal Image Viewer ── */
.edit-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 8px;
}

.edit-image-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  aspect-ratio: 4/5;
  background: var(--surface2);
}

.edit-image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.edit-image-item .slide-label {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 8px;
}

.edit-image-item .regen-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.edit-image-item:hover .regen-btn {
  opacity: 1;
}

/* Delete button in edit modal */
.edit-image-item .del-slide-btn {
  right: 36px;
}

/* Delete button tint in carousel overlay */
.overlay-del-btn {
  background: rgba(200, 50, 50, 0.7) !important;
}

.overlay-del-btn:hover {
  background: rgba(200, 50, 50, 0.9) !important;
}

.edit-image-item.regenerating {
  opacity: 0.5;
  pointer-events: none;
}

.edit-image-item.regenerating::after {
  content: "⏳";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text2);
}

.empty-state h2 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 8px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--green);
  color: #000;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  z-index: 200;
  animation: slideUp 0.3s ease;
}

.toast.error {
  background: var(--red);
  color: #fff;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 400px;
    overflow-y: auto;
  }
}

/* ── Layout Grid ── */
.main-container {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: calc(100vh - 70px);
  /* Subtract header height */
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 70px);
  position: sticky;
  top: 0;
}

.content-area {
  padding: 20px;
  overflow-y: auto;
}

/* ── Sidebar Items ── */
#unprocessed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.unprocessed-item {
  background: var(--surface2);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s;
}

.unprocessed-item:hover {
  border-color: var(--accent2);
}

.unprocessed-item.processing {
  border-color: var(--yellow);
  background: rgba(255, 214, 10, 0.05);
}

.unprocessed-item .sidebar-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.4;
}