:root {
  --bg: #0f1117;
  --card: #181b24;
  --card-2: #202431;
  --border: #2c3142;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #10b981;
  --warn-bg: #3b230a;
  --warn-border: #d97706;
  --warn-text: #fde68a;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
}
.brand-badge {
  display: inline-block;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  max-width: 100%;
}
.topbar-left, .topbar-actions, .topbar-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}
.logo { font-weight: 800; font-size: 1.08rem; white-space: nowrap; }
.pill {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.format-pill { color: #34d399; border-color: rgba(16,185,129,0.4); }
.stat-chip {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  display: inline-flex;
  gap: 5px;
  align-items: center;
  white-space: nowrap;
}
.badge {
  background: var(--primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.retention-banner {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text);
  text-align: center;
  padding: 8px 14px;
  font-size: 0.86rem;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  background: #141720;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 9px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab-btn.active {
  background: var(--card-2);
  color: var(--text);
  border-color: var(--border);
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px;
}
.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
h1, h2, h3 { margin: 0 0 8px 0; }
h2 { font-size: 1.08rem; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col-tight { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 900px) { .two-col, .two-col-tight { grid-template-columns: 1fr; } }

label, .lbl { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.btn {
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #052e16; }
.btn.danger { background: rgba(239,68,68,0.16); border-color: rgba(239,68,68,0.5); color: #fca5a5; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 0.82rem; }
.btn.big { padding: 13px 18px; font-size: 1rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 820px) { .mode-grid { grid-template-columns: 1fr; } }
.mode-card {
  text-align: left;
  background: var(--card-2);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.mode-card.active { border-color: var(--primary); background: rgba(99, 102, 241, 0.12); }
.mode-icon { font-size: 1.4rem; margin-bottom: 6px; }
.mode-title { font-weight: 700; margin-bottom: 4px; }
.mode-desc { font-size: 0.82rem; color: var(--muted); }

.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  background: rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-weight: 400;
}
.sr-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: rgba(99, 102, 241, 0.08); }
.preview-thumb { max-height: 180px; max-width: 100%; border-radius: 8px; object-fit: contain; }
.mini-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}
.preset-item {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg);
  text-align: center;
}
.preset-item.active { border-color: var(--primary); }
.preset-item img { width: 100%; height: 96px; object-fit: cover; display: block; }
.preset-item span { display: block; font-size: 0.7rem; padding: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset-item.random-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 118px;
  padding: 8px;
  gap: 6px;
}
.model-del-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(15, 17, 23, 0.85);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.5);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 2px 6px;
  cursor: pointer;
}
.model-strip-box {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.model-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px 3px 3px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.model-chip img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

.acct-models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
}
.acct-model-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.acct-model-card img {
  width: 100%;
  height: 135px;
  object-fit: cover;
  display: block;
}
.acct-model-edit {
  padding: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.acct-model-edit .model-rename-input {
  padding: 6px 8px;
  font-size: 0.82rem;
  min-width: 0;
  flex: 1;
}
.acct-model-edit .btn.small {
  padding: 6px 9px;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.qty-pills { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.qty-pill {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.qty-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.qty-custom { width: 92px; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.88rem; border: 1px solid transparent; }
.alert.info { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.35); color: #bfdbfe; }
.alert.success { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.4); color: #a7f3d0; }
.alert.error { background: rgba(239,68,68,0.14); border-color: rgba(239,68,68,0.4); color: #fecaca; }

.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions.end { justify-content: flex-end; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.global-batch-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  background: var(--card-2);
  padding: 12px;
  border-radius: 10px;
}
.global-batch-bar > label { flex: 1 1 190px; min-width: 0; }
@media (max-width: 900px) {
  .global-batch-bar > label, .global-batch-bar > button { flex: 1 1 100%; }
}

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th, .data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.video-card {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: #090b10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-frame video, .video-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-meta { padding: 12px; display: flex; flex-direction: column; gap: 7px; font-size: 0.84rem; }
.card-title { font-size: 0.96rem; line-height: 1.3; word-break: break-word; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.btn-dl-mp4 { flex: 1 1 auto; }
.vo-details {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
}
.vo-details summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.vo-details[open] summary { margin-bottom: 5px; color: var(--text); }
.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.st-completed { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.st-queued, .st-generating_image, .st-generating_video { background: rgba(99,102,241,0.25); color: #c7d2fe; }
.st-failed, .st-expired { background: rgba(239,68,68,0.2); color: #fca5a5; }
.countdown-tag { font-size: 0.75rem; color: var(--warn-text); }

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  margin-top: 2px;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #10b981);
  transition: width 0.4s ease;
}
.progress-fill.pulse {
  animation: pulseBar 1.6s ease-in-out infinite;
}
@keyframes pulseBar {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.86rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.45);
  color: var(--text);
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 380px;
}
.modal-card.modal-wide {
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
}

/* === MOBILE FIRST ERGONOMICS (<= 768px) === */
@media (max-width: 768px) {
  .topbar {
    padding: 10px 12px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  .topbar-left { order: 1; }
  .topbar-actions { order: 2; margin-left: auto; }
  .topbar-stats {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
    gap: 6px;
    justify-content: flex-start;
  }
  .topbar-stats .stat-chip {
    font-size: 0.76rem;
    padding: 4px 8px;
  }
  .retention-banner {
    font-size: 0.78rem;
    padding: 7px 10px;
    line-height: 1.35;
  }

  /* Bottom App Bar: seluruh menu terlihat tanpa terpotong ke samping */
  .nav-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 70;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 4px;
    background: rgba(20, 23, 32, 0.97);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: 0 -6px 20px rgba(0,0,0,0.45);
  }
  .tab-btn {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    font-size: 0.72rem;
    min-height: 50px;
    border-radius: 10px;
  }
  .tab-ic { font-size: 1.1rem; line-height: 1; }
  .tab-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tab-btn.active {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.55);
    color: #fff;
  }

  .container {
    padding: 12px 12px 92px 12px;
  }
  .card {
    padding: 14px;
  }
  input, select, textarea {
    font-size: 16px;
    padding: 11px 12px;
  }
  .btn { min-height: 42px; }
  .btn.small { min-height: 38px; padding: 7px 11px; }

  .mode-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
  }
  .mode-icon {
    font-size: 1.5rem;
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .qty-pills { display: grid; grid-template-columns: repeat(2, 1fr); }
  .qty-custom { width: 100%; }

  /* Tabel Batch & Admin otomatis menjadi kartu rapi di HP tanpa scroll samping */
  .table-wrap { overflow: visible; }
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody { display: block; width: 100%; }
  .responsive-table tr {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
  }
  .responsive-table td {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0;
    border-bottom: 0;
  }
  .responsive-table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  .responsive-table td .b-row-qty { width: 100% !important; }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: 78px;
    max-width: none;
  }
}

@media (max-width: 600px) {
  .video-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .video-card {
    border-radius: 14px;
  }
  .video-frame {
    width: min(100%, 260px);
    margin: 12px auto 0;
    border-radius: 10px;
    overflow: hidden;
  }
}
