:root {
  --bg: #0b0f19;
  --surface: #131a2a;
  --surface-2: #1a2338;
  --border: #26324d;
  --text: #e5ecff;
  --muted: #93a3c7;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #0ea5e9;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a { color: #7dd3fc; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.hidden { display: none !important; }
.muted-text { color: var(--muted); font-size: 13px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: white;
}
.brand h1 { margin: 0; font-size: 17px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.topbar-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.mobile-nav-bar {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  gap: 8px;
}
.mobile-nav-btn {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.mobile-nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.mobile-only-btn { display: none; }

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 48px rgba(0,0,0,0.6);
}

.status-pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.status-pill.ok { border-color: rgba(16,185,129,0.5); color: #6ee7b7; background: rgba(16,185,129,0.12); }
.status-pill.warn { border-color: rgba(245,158,11,0.5); color: #fcd34d; background: rgba(245,158,11,0.12); }
.status-pill.err { border-color: rgba(239,68,68,0.5); color: #fca5a5; background: rgba(239,68,68,0.12); }

/* Layout */
.workspace {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  min-height: calc(100vh - 65px);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #0f1523;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 65px);
  position: sticky;
  top: 65px;
}

.sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-row { display: flex; gap: 6px; flex-wrap: wrap; }
.stat-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
}
.stat-chip strong { color: var(--text); }

.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.anime-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.anime-item {
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.anime-item:hover { border-color: #4f46e5; background: var(--surface-2); }
.anime-item.selected { border-color: var(--accent); background: #17243d; }

.anime-item-title { font-weight: 600; font-size: 13.5px; margin-bottom: 6px; word-break: break-word; }
.anime-item-badges { display: flex; flex-wrap: wrap; gap: 5px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-ok { background: rgba(16,185,129,0.14); color: #6ee7b7; border-color: rgba(16,185,129,0.4); }
.badge-warn { background: rgba(245,158,11,0.14); color: #fcd34d; border-color: rgba(245,158,11,0.4); }
.badge-info { background: rgba(14,165,233,0.14); color: #7dd3fc; border-color: rgba(14,165,233,0.4); }
.badge-muted { background: rgba(148,163,184,0.1); color: var(--muted); }

/* Right Panel */
.editor-panel { padding: 20px; overflow-y: auto; min-width: 0; }
.workspace-stack { display: flex; flex-direction: column; gap: 18px; max-width: 1180px; width: 100%; min-width: 0; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-width: 0;
  overflow: hidden;
}

.empty-editor { max-width: 680px; margin: 40px auto; text-align: center; padding: 36px; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 14px; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-header h2 { margin: 0; font-size: 17px; }
.card-desc { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.meta-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.dot { opacity: 0.4; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Inputs & Buttons */
.input {
  width: 100%;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1220;
  color: var(--text);
  font-size: 13.5px;
}
.input:focus { outline: none; border-color: var(--primary); }

.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { border-color: #4f46e5; }
.btn-accent { background: #0284c7; color: white; }
.btn-accent:hover:not(:disabled) { background: #0369a1; }
.btn-draft { background: #b45309; color: white; }
.btn-draft:hover:not(:disabled) { background: #92400e; }
.btn-publish { background: #059669; color: white; }
.btn-publish:hover:not(:disabled) { background: #047857; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }

.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.checkbox-label { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; color: var(--text); }
.checkbox-row { display: flex; gap: 18px; flex-wrap: wrap; }

/* ZIP files & buttons */
.zip-files-list { display: flex; flex-direction: column; gap: 6px; }
.zip-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.zip-file-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

.section-subheader { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-subheader h3 { margin: 0; font-size: 14px; }

.custom-buttons-box { margin-top: 14px; }
.custom-buttons-box > label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.custom-buttons-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.custom-btn-row {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  gap: 8px;
  align-items: center;
}
.inline-add-row { display: grid; grid-template-columns: 220px 1fr auto; gap: 8px; }

.preview-buttons-wrap { margin-top: 12px; padding: 10px; background: #0c1220; border-radius: 8px; border: 1px solid var(--border); }
.slug-preview { font-size: 12px; color: var(--muted); word-break: break-all; }
.slug-preview code { color: #7dd3fc; }
.mini-label { font-size: 11.5px; color: var(--muted); display: block; margin-bottom: 6px; }
.buttons-preview { display: flex; flex-wrap: wrap; gap: 8px; min-height: 28px; align-items: center; }
.wp-btn-mock {
  display: inline-block;
  background: #2563eb;
  color: white;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
}

/* Search dropdown */
.search-bar-row { display: flex; gap: 10px; align-items: flex-start; }
.search-input-wrap { position: relative; flex: 1; }
.live-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--primary);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 340px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}
.live-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.live-result-item:hover { background: #22304d; }
.live-result-item img { width: 40px; height: 56px; object-fit: cover; border-radius: 4px; }

/* Toggle chips */
.toggle-chip-group { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-toggle {
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0c1220;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.chip-toggle.active {
  background: rgba(99,102,241,0.22);
  border-color: var(--primary);
  color: #c7d2fe;
}

.meta-summary {
  margin-top: 14px;
  padding: 12px;
  background: #0c1220;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; font-size: 12.5px; }

/* Backdrop Finder (Horizontal 16:9) */
.poster-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.selected-poster-box { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.poster-finder-box { min-width: 0; max-width: 100%; overflow: hidden; }
.poster-tab-panel { min-width: 0; max-width: 100%; }
.poster-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0c1220;
  border: 2px dashed var(--border);
  border-radius: 10px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  color: var(--muted);
  overflow: hidden;
}
.poster-placeholder img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

.tabs-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
}
.tab-btn.active { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.inline-search-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; width: 100%; min-width: 0; align-items: center; }
.inline-search-row .input { flex: 1 1 200px; min-width: 0; width: auto; }

.tmdb-title-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  padding-bottom: 8px;
  margin-bottom: 8px;
  scrollbar-width: thin;
}
.tmdb-match-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  max-width: 240px;
  min-width: 0;
}
.tmdb-match-chip > div { min-width: 0; overflow: hidden; }
.tmdb-match-chip.active { border-color: var(--accent); background: #172844; }
.tmdb-match-chip img { width: 56px; height: 32px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.tmdb-match-chip span { display: block; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  max-height: 410px;
  overflow-y: auto;
  padding-right: 4px;
}

.poster-card {
  background: #0c1220;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
}
.poster-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.poster-card.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgba(16,185,129,0.3); }
.poster-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.poster-card-info { padding: 5px 7px; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; min-width: 0; }
.poster-card-info span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Publish Bar */
.wp-update-row { margin-bottom: 10px; padding: 9px 12px; background: rgba(14,165,233,0.1); border: 1px solid rgba(14,165,233,0.3); border-radius: 8px; }
.preview-details { margin: 10px 0 14px; }
.preview-details summary { cursor: pointer; color: #93c5fd; font-weight: 600; margin-bottom: 8px; }
.code-textarea {
  width: 100%;
  background: #090d16;
  color: #dbeafe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.publish-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.telegram-options { display: flex; flex-direction: column; gap: 4px; }
.publish-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.publish-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(16,185,129,0.12);
  border: 1px solid rgba(16,185,129,0.45);
}

.alert { padding: 11px 14px; border-radius: 8px; font-weight: 500; }
.alert.err { background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.45); color: #fecaca; }
.alert.ok { background: rgba(16,185,129,0.14); border: 1px solid rgba(16,185,129,0.45); color: #a7f3d0; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.68);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}
.modal-header, .modal-footer {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; gap: 10px; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.settings-section h3 { margin: 0 0 10px; font-size: 14.5px; color: #c7d2fe; }

@media (max-width: 1180px) {
  .poster-layout { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
    gap: 10px;
  }
  .topbar-status {
    justify-content: flex-start;
  }
  .topbar-actions {
    width: 100%;
  }
  .topbar-actions .btn {
    flex: 1 1 130px;
    justify-content: center;
  }
  .mobile-nav-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: sticky;
    top: 0;
    z-index: 45;
  }
  .mobile-only-btn {
    display: inline-flex;
    align-self: flex-start;
  }
  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .workspace[data-mobile-view="list"] .editor-panel {
    display: none;
  }
  .workspace[data-mobile-view="editor"] .sidebar {
    display: none;
  }
  .sidebar {
    height: auto;
    max-height: none;
    position: static;
    border-right: none;
  }
  .editor-panel {
    padding: 12px;
  }
  .grid-3, .grid-2, .meta-grid, .poster-layout, .custom-btn-row, .inline-add-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .brand h1 { font-size: 16px; }
  .subtitle { font-size: 11.5px; }
  .status-pill { font-size: 11px; padding: 4px 8px; }
  .card { padding: 14px; border-radius: 10px; }
  .card-header { gap: 10px; }
  .header-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .header-actions .btn { width: 100%; justify-content: center; }

  /* Prevent iOS Safari zoom on input focus and enlarge touch targets */
  .input, select.input, .code-textarea {
    font-size: 16px;
    min-height: 42px;
  }
  .btn {
    min-height: 40px;
    padding: 9px 12px;
  }
  .btn-sm { min-height: 36px; padding: 6px 10px; }
  .chip-toggle, .pill {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .search-bar-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-bar-row .btn {
    width: 100%;
    justify-content: center;
  }

  .zip-file-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .zip-file-row .btn {
    width: 100%;
    justify-content: center;
  }

  .poster-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    max-height: 360px;
  }

  .publish-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .publish-buttons {
    width: 100%;
  }
  .publish-buttons .btn {
    flex: 1 1 140px;
    justify-content: center;
  }

  .modal-backdrop { padding: 8px; }
  .modal { max-height: 94dvh; }
  .modal-footer .btn { flex: 1; justify-content: center; }
}
