/* =====================================================================
   TEMA - semua warna lewat variabel, mode gelap tinggal override
   ===================================================================== */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --surface-3: #ececee;
  --border: #e5e5ea;
  --text: #1a1a1a;
  --text-muted: #8a8a92;
  --placeholder: #b7b7bd;
  --accent: #2f6fed;
  --accent-bg: #eaf1ff;
  --shadow: 0 8px 30px rgba(0,0,0,0.06);
  --radius: 20px;
  --send-off: #d8d8dd;
  --model-bg: #1a1a1a;
  --model-fg: #ffffff;
  --model-bg-hover: #333333;
  --ok-bg: #e6f6ea;  --ok-fg: #1a7d38;
  --err-bg: #fde8e8; --err-fg: #b42318;
  --warn-bg: #fff3d6; --warn-fg: #92600a;
  --backdrop: rgba(0,0,0,0.25);
  --toast-bg: #1a1a1a; --toast-fg: #ffffff;
}
[data-theme="dark"] {
  --bg: #0f0f12;
  --surface: #17171b;
  --surface-2: #24242a;
  --surface-3: #2e2e35;
  --border: #2c2c34;
  --text: #ececf1;
  --text-muted: #9a9aa6;
  --placeholder: #6b6b76;
  --accent: #5b8cff;
  --accent-bg: #1d2a48;
  --shadow: 0 8px 30px rgba(0,0,0,0.5);
  --send-off: #3a3a44;
  --model-bg: #ececf1;
  --model-fg: #111114;
  --model-bg-hover: #ffffff;
  --ok-bg: #143d22;  --ok-fg: #6fdc8c;
  --err-bg: #4a1c1c; --err-fg: #ff8a80;
  --warn-bg: #4a3a12; --warn-fg: #ffd166;
  --backdrop: rgba(0,0,0,0.6);
  --toast-bg: #ececf1; --toast-fg: #111114;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

.page { max-width: 1200px; margin: 0 auto; padding: 48px 24px 80px; }

.hero-title { text-align: center; font-size: 34px; font-weight: 500; margin-bottom: 28px; }
.hero-title .brand { font-family: Georgia, "Times New Roman", serif; font-style: italic; }

/* ---------- Tabs ---------- */
.tabs { display: flex; justify-content: center; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  border: none; background: transparent; color: var(--text-muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }

/* ---------- Kotak input utama ---------- */
.box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  transition: border-color .15s;
}
.box.dragover { border-color: var(--accent); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attachment-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 10px;
  padding: 4px 8px 4px 4px; font-size: 12px; max-width: 260px;
}
.attachment-chip .thumb {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
  background: var(--surface-3); flex-shrink: 0;
}
.attachment-chip .thumb-icon {
  width: 40px; height: 40px; border-radius: 8px; background: var(--surface-3);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.attachment-chip .chip-text { display: flex; flex-direction: column; min-width: 0; }
.attachment-chip .chip-text .label { font-weight: 600; }
.attachment-chip .chip-text .sub {
  font-size: 10px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px;
}
.attachment-chip .remove { cursor: pointer; color: var(--text-muted); font-weight: bold; }
.attachment-chip.uploading { opacity: .55; }
.attachment-chip.error { background: var(--err-bg); color: var(--err-fg); }

.top-features { display: flex; gap: 8px; margin-bottom: 10px; }
.feature-btn {
  display: flex; align-items: center; gap: 6px;
  border: none; background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 8px 12px; font-size: 13px; cursor: pointer;
}
.feature-btn:hover { background: var(--surface-3); }
.feature-btn .icon { font-size: 14px; }

textarea#promptInput {
  width: 100%; border: none; outline: none; resize: none;
  font-size: 16px; padding: 6px 4px 14px; font-family: inherit;
  min-height: 26px; max-height: 200px;
  background: transparent; color: var(--text);
}
textarea#promptInput::placeholder { color: var(--placeholder); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }

.chip {
  border: none; background: transparent; color: var(--text-muted);
  font-size: 13px; display: flex; align-items: center; gap: 4px;
  cursor: pointer; padding: 4px 8px; border-radius: 10px;
}
.chip:hover { background: var(--surface-2); }
.chip.toggle[data-on="true"] { background: var(--accent-bg); color: var(--accent); }
.chip-divider { width: 1px; height: 16px; background: var(--border); }

.model-chip { background: var(--model-bg); color: var(--model-fg); padding: 5px 10px; }
.model-chip:hover { background: var(--model-bg-hover); }

.cost-hint { font-size: 12px; color: var(--text-muted); }

.send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--send-off); color: #fff; font-size: 16px; cursor: pointer;
}
.send-btn:enabled { background: var(--accent); }
.send-btn:disabled { cursor: not-allowed; }

.drop-overlay {
  position: absolute; inset: 0;
  background: var(--accent-bg); opacity: .85;
  border: 2px dashed var(--accent); border-radius: var(--radius);
  display: none; align-items: center; justify-content: center;
  font-size: 14px; color: var(--accent); pointer-events: none;
}
.box.dragover .drop-overlay { display: flex; }

.tab-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 10px; min-height: 16px; }

/* ---------- Tombol pojok kanan atas ---------- */
.settings-btn {
  position: fixed; top: 16px; right: 16px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 16px;
}
.theme-btn { right: 60px; }

/* ---------- Bagian & judul ---------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 40px; margin-bottom: 12px;
}
.section-title { font-size: 16px; margin: 0; color: var(--text-muted); font-weight: 600; }

/* ---------- Tombol umum ---------- */
.primary-btn, .secondary-btn, .link-btn {
  border: none; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.primary-btn { background: var(--accent); color: #fff; }
.secondary-btn { background: var(--surface-2); color: var(--text); }
.secondary-btn.small { padding: 5px 10px; font-size: 12px; }
.link-btn { background: transparent; color: var(--accent); text-decoration: underline; padding: 8px 4px; }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Grid hasil & riwayat ---------- */
.history-empty {
  border: 1px dashed var(--border); border-radius: 14px; padding: 28px;
  text-align: center; color: var(--text-muted); font-size: 13px;
}
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.history-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px; font-size: 12px;
}
.history-card .hstatus {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; margin-bottom: 6px;
}
.hstatus.SUCCEEDED { background: var(--ok-bg); color: var(--ok-fg); }
.hstatus.FAILED, .hstatus.ERROR, .hstatus.CANCELED, .hstatus.UNKNOWN, .hstatus.TIMEOUT { background: var(--err-bg); color: var(--err-fg); }
.hstatus.EXPIRED { background: var(--surface-3); color: var(--text-muted); }
.hstatus.PENDING, .hstatus.RUNNING { background: var(--warn-bg); color: var(--warn-fg); }
.history-card .htime { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.history-card .howner { margin-top: -2px; }
.history-card .hprompt {
  color: var(--text-muted); margin: 4px 0 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.history-card .hthumb {
  position: relative; border-radius: 10px; overflow: hidden; background: #000; cursor: pointer; margin-bottom: 8px;
}
.history-card .hthumb video, .history-card .hthumb .placeholder {
  width: 100%; max-height: 300px; object-fit: contain; background: #000; display: block;
}
.history-card .hthumb .placeholder {
  height: 200px; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; color: #ccc; font-size: 12px; cursor: default;
}
.history-card .hthumb .placeholder .spinner { border-color: #444; border-top-color: #fff; }
.history-card .hthumb .play-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 30px; background: rgba(0,0,0,0.15);
}
.history-card .hactions { display: flex; gap: 6px; flex-wrap: wrap; }
.history-card .hactions button, .history-card .hactions a {
  border: none; background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 5px 9px; font-size: 11px; cursor: pointer; text-decoration: none;
}
.history-card .hactions .danger { color: var(--err-fg); }

/* ---------- Popover ---------- */
.popover {
  position: absolute; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 50; min-width: 120px;
}
.popover-item { padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--text); }
.popover-item:hover { background: var(--surface-2); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--backdrop);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { background: var(--surface); color: var(--text); border-radius: 16px; padding: 22px; width: 380px; max-width: 90vw; }
.modal h3 { margin: 0 0 14px; }
.modal label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; margin-top: 10px; }
.modal input, .modal select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; background: var(--surface-2); color: var(--text);
}
.modal-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; }

.player-modal { width: 760px; max-width: 94vw; }
.player-modal video { width: 100%; border-radius: 12px; background: #000; max-height: 70vh; }
.player-prompt { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.player-modal .modal-actions a { text-decoration: none; display: inline-block; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-fg);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 200;
}

/* ---------- Quota badge ---------- */
.quota-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: help;
  white-space: nowrap;
}
.quota-badge.low { background: var(--warn-bg); color: var(--warn-fg); }
.quota-badge.empty { background: var(--err-bg); color: var(--err-fg); }
.howner { font-size: 10px; color: var(--text-muted); }

/* ---------- Quota badge ---------- */
.quota-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: help;
  white-space: nowrap;
}
.quota-badge.low { background: var(--warn-bg); color: var(--warn-fg); }
.quota-badge.empty { background: var(--err-bg); color: var(--err-fg); }
.howner { font-size: 10px; color: var(--text-muted); }

/* ---------- Baris generate: kotak prompt + kartu Settings sejajar ---------- */
.gen-row {
  display: flex;
  align-items: stretch;
  gap: 16px;
}
.gen-row .box {
  flex: 1;
  min-width: 0;
}
.settings-card {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.settings-card h3 { margin: 0 0 10px; font-size: 15px; }
.settings-card label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 3px; margin-top: 8px; }
.settings-card input {
  width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; background: var(--surface-2); color: var(--text);
  font-family: monospace;
}
.sidebar-hint { font-size: 10px; color: var(--text-muted); margin-top: 8px; }

/* Tab-hint hanya selebar kotak prompt (jangan melebar ke bawah kartu settings) */
.tab-hint { max-width: calc(100% - 296px); }

.theme-btn { position: fixed; top: 16px; right: 16px; }

@media (max-width: 900px) {
  .gen-row { flex-direction: column; }
  .settings-card { width: 100%; }
  .tab-hint { max-width: none; }
}

/* ---------- Baris tab profil (mini, seperti tab browser) ---------- */
.profile-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.profile-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.profile-tab {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  transition: all .12s;
}
.profile-tab:hover { border-color: var(--accent); }
.profile-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.profile-tab .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok-fg);
}
.profile-tab .dot.empty { background: var(--text-muted); }
.profile-tab .running {
  font-size: 10px;
  background: var(--warn-bg); color: var(--warn-fg);
  padding: 1px 6px; border-radius: 999px;
}
.profile-add {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px dashed var(--border);
  background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.profile-add:hover { border-color: var(--accent); color: var(--accent); }

.settings-head { display: flex; align-items: center; justify-content: space-between; }
.profile-del {
  border: none; background: transparent; cursor: pointer;
  font-size: 13px; opacity: .6;
}
.profile-del:hover { opacity: 1; }

/* ---------- "by Tyo" di judul ---------- */
.by-tyo {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

/* ---------- Halaman login/daftar ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 340px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.auth-title { text-align: center; font-size: 26px; margin: 0; }
.auth-title .brand { font-family: Georgia, serif; font-style: italic; }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 12px; margin: 4px 0 20px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; border: none; background: var(--surface-2); color: var(--text-muted);
  padding: 9px; border-radius: 10px; cursor: pointer; font-size: 13px;
}
.auth-tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.auth-card label { display: block; font-size: 11px; color: var(--text-muted); margin: 10px 0 3px; }
.auth-card input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 13px; background: var(--surface-2); color: var(--text);
}
.auth-err { color: var(--err-fg); font-size: 12px; margin-top: 10px; text-align: center; min-height: 16px; }

/* ---------- Header user (username + logout) ---------- */
.user-chip {
  position: fixed; top: 16px; left: 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 12px; z-index: 30;
}
.user-chip .uname { color: var(--text); font-weight: 600; }
.user-chip .logout-btn {
  border: none; background: var(--surface-2); color: var(--text-muted);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 11px;
}
.user-chip .logout-btn:hover { color: var(--err-fg); }

/* ---------- Badge saldo Rupiah di user-chip ---------- */
.balance-chip {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.balance-chip.low { background: var(--err-bg); color: var(--err-fg); }

/* ---------- Tombol topup Telegram ---------- */
.telegram-topup {
  background: #229ED9;
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.telegram-topup:hover { background: #1b87bd; }
