/* ============================================================
   StatusWala Poster Admin — dark theme, purple accent
   ============================================================ */

:root {
  --bg:          #0e0e14;
  --surface:     #16161f;
  --surface-2:   #1d1d29;
  --surface-3:   #24243200;
  --border:      #2a2a38;
  --border-soft: #23232f;
  --text:        #e9e9f2;
  --muted:       #9a9ab2;
  --muted-soft:  #6c6c84;

  --accent:        #7c5cfc;
  --accent-hover:  #6b4ce8;
  --accent-soft:   rgba(124, 92, 252, 0.14);

  --green:      #2ecc71;
  --green-soft: rgba(46, 204, 113, 0.16);
  --amber:      #f5a623;
  --amber-soft: rgba(245, 166, 35, 0.16);
  --danger:     #f0556a;
  --danger-soft:rgba(240, 85, 106, 0.14);

  --radius:    14px;
  --radius-sm: 10px;
  --shadow:    0 8px 30px rgba(0, 0, 0, 0.35);
  --ring:      0 0 0 3px rgba(124, 92, 252, 0.45);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Focus / accessibility ---------- */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: 8px;
}

/* ============================ Buttons ============================ */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:hover { background: #262635; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.08); }

.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ============================ Fields ============================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }

.field input,
.select {
  appearance: none;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input::placeholder { color: var(--muted-soft); }
.field input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239a9ab2' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
  cursor: pointer;
}

/* ============================ Login ============================ */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(124, 92, 252, 0.12), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand { display: flex; align-items: center; gap: 14px; }
.login-title { font-size: 19px; margin: 0; font-weight: 700; }
.login-subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.login-error {
  margin: 0;
  background: var(--danger-soft);
  border: 1px solid rgba(240, 85, 106, 0.4);
  color: #ffb3bd;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.login-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted-soft);
  line-height: 1.5;
}

/* ============================ Logo ============================ */
.logo {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #a17bff);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  flex: none;
}

/* ============================ Top bar ============================ */
.app-view { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(14, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-titles { display: flex; flex-direction: column; min-width: 0; }
.topbar-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.env-label {
  font-size: 12px;
  color: var(--muted);
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================ Layout ============================ */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 65px;
  align-self: start;
  padding: 20px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: calc(100dvh - 65px);
}

.category-nav { display: flex; flex-direction: column; gap: 6px; }

.cat-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.cat-btn:hover { background: var(--surface-2); color: var(--text); }
.cat-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: rgba(124, 92, 252, 0.45);
}
.cat-emoji { font-size: 17px; flex: none; }
.cat-name { flex: 1; }

.count-badge {
  min-width: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.cat-btn.active .count-badge { background: var(--accent); color: #fff; }
.count-badge-lg { font-size: 13px; min-width: 30px; padding: 3px 10px; }

.sidebar-total {
  margin-top: auto;
  padding: 14px 13px 4px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

/* ============================ Main ============================ */
.main {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* ---------- Stats ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-scope { color: var(--muted-soft); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 800; line-height: 1; }
.stat-free { color: var(--green); }
.stat-paid { color: var(--amber); }
.stat-updated { font-size: 14px; font-weight: 700; }

/* ============================ Panels ============================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-title { font-size: 15px; font-weight: 700; margin: 0; }

/* ---------- Upload ---------- */
.upload-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.field-inline { flex: 1; min-width: 140px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.dropzone:hover,
.dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.dropzone-icon { width: 34px; height: 34px; color: var(--accent); }
.dropzone-text { margin: 4px 0 0; color: var(--text); }
.dropzone-sub { margin: 0; font-size: 12px; color: var(--muted-soft); }

/* ---------- Queue ---------- */
.queue {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.queue-item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.queue-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex: none;
}
.queue-info { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.queue-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.queue-id { color: var(--muted-soft); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; }

.progress {
  height: 5px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.queue-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.queue-status {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.status-ready    { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.status-uploading{ background: var(--accent-soft); color: #b9a6ff; }
.status-done     { background: var(--green-soft); color: var(--green); }
.status-error    { background: var(--danger-soft); color: #ffb3bd; }

.queue-remove {
  background: transparent;
  border: none;
  color: var(--muted-soft);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}
.queue-remove:hover { color: var(--danger); background: var(--danger-soft); }

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

/* ---------- Poster grid ---------- */
.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.poster-card {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.poster-thumb-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #1a1a26, #14141d);
  overflow: hidden;
}
.poster-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.poster-thumb.img-failed { display: none; }
.poster-thumb-wrap.failed::after {
  content: "🖼️ image unavailable";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-soft);
  font-size: 12px;
  text-align: center;
  padding: 10px;
}

.tier-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}
.tier-free { background: var(--green-soft); color: #6dffa8; border: 1px solid rgba(46, 204, 113, 0.5); }
.tier-paid { background: var(--amber-soft); color: #ffce7a; border: 1px solid rgba(245, 166, 35, 0.5); }

.poster-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(10, 10, 16, 0.7);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s ease;
}
.poster-delete:hover { background: var(--danger); }
.poster-delete svg { width: 15px; height: 15px; }

.poster-meta {
  padding: 9px 11px;
  display: flex;
  align-items: center;
  min-width: 0;
}
.poster-id {
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
.empty-emoji { font-size: 38px; display: block; margin-bottom: 10px; }
.empty-title { font-weight: 700; margin: 0 0 4px; color: var(--text); }
.empty-sub { margin: 0; font-size: 13px; color: var(--muted-soft); }

/* ============================ Toasts ============================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: toast-in 0.2s ease;
  font-size: 13.5px;
}
.toast.leaving { animation: toast-out 0.2s ease forwards; }
.toast-success { border-left-color: var(--green); }
.toast-error   { border-left-color: var(--danger); }
.toast-info    { border-left-color: var(--accent); }
.toast-icon { font-size: 15px; line-height: 1.3; }
.toast-msg { flex: 1; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ============================ Spinner overlay ============================ */
.spinner-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  gap: 14px;
  grid-auto-flow: row;
  background: rgba(8, 8, 12, 0.6);
  backdrop-filter: blur(2px);
}
.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(124, 92, 252, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner-text { color: var(--text); font-size: 13px; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Modal ============================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 8, 12, 0.7);
  backdrop-filter: blur(3px);
  animation: toast-in 0.15s ease;
}
.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-title { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.modal-body { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.modal-body code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ============================ Responsive ============================ */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 12px 16px;
  }
  .category-nav { flex-direction: row; gap: 8px; }
  .cat-btn { width: auto; }
  .sidebar-total {
    margin: 0 0 0 auto;
    padding: 0 0 0 8px;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-left: 12px;
    white-space: nowrap;
  }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  body { font-size: 14px; }
  .main { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .env-label { display: none; }
  .stat-value { font-size: 20px; }
  .upload-controls { flex-direction: column; }
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .toast-container { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
