/* ════════════════════════════════════════
   grok i2v – flatter, functional styles
   ════════════════════════════════════════ */

:root {
  --bg: #09090e;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: #222233;
  --text: #ececf2;
  --dim: #72728a;
  --accent: #6366f1;
  --green: #22c997;
  --red: #ef5f5f;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: 32px;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Header ─────────────────────────── */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}
.bar-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.3px; }
.logo .dim { color: var(--dim); font-weight: 400; }
.nav { display: flex; gap: 2px; }
.tab-btn {
  background: none;
  border: none;
  color: var(--dim);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: background .12s, color .12s;
}
.tab-btn:hover { color: var(--text); background: var(--surface); }
.tab-btn:active { background: var(--surface2); }
.tab-btn.active { color: var(--text); background: var(--surface2); font-weight: 600; }

/* ─── Credits ────────────────────────── */
.credits-wrap {
  margin: 6px 12px;
}
.credits {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}
.credits-buy {
  display: block;
  text-align: center;
  padding: 5px 8px;
  font-size: .68rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
}
.credits-buy:hover { background: var(--surface2); }
.cr { flex: 1; text-align: center; padding: 6px 4px; border-right: 1px solid var(--border); }
.cr:last-child { border-right: none; }
.cr-l { display: block; font-size: .6rem; text-transform: uppercase; color: var(--dim); letter-spacing: .4px; }
.cr-v { display: block; font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }
.cr-sub { display: block; font-size: .58rem; color: var(--dim); margin-top: 2px; line-height: 1.2; }
.cr-v.acc { color: var(--accent); }
.cr-v.grn { color: var(--green); }

/* ─── Tab containers ─────────────────── */
.tab { padding: 0 0 20px; }

/* ─── Card ───────────────────────────── */
.card {
  margin: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.card-label { font-size: .78rem; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: .3px; }
.pill {
  background: var(--surface2);
  padding: 1px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
}

/* ─── Dropzone ───────────────────────── */
.dropzone {
  position: relative;
  min-height: 90px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 6px;
  transition: border-color .15s;
}
.dropzone.dragover, .dropzone:active { border-color: var(--accent); }
.dz-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 16px;
  color: var(--dim);
}
.dz-icon { font-size: 1.6rem; line-height: 1; font-weight: 300; }
.dz-text { font-size: .85rem; }
.dz-sub { font-size: .68rem; opacity: .6; }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 5px;
}
.preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface2);
}
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-remove {
  position: absolute;
  top: 2px; right: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: .6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.url-details { margin-top: 6px; font-size: .78rem; }
.url-details summary { cursor: pointer; color: var(--dim); padding: 2px 0; }
.url-details textarea {
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px;
  font-size: .78rem;
  resize: vertical;
  font-family: inherit;
  outline: none;
}
.url-details textarea:focus { border-color: var(--accent); }

/* ─── Form elements ──────────────────── */
textarea, input, select { font-family: inherit; font-size: .88rem; outline: none; }

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px;
  resize: vertical;
  transition: border-color .12s;
}
textarea:focus { border-color: var(--accent); }
.char-count { font-size: .68rem; color: var(--dim); }

.set-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.preset-row { margin-bottom: 10px; }
.preset-btns { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.preset-btn {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: .72rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: border-color .12s, background .12s;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn.active { border-color: var(--accent); background: var(--surface2); }
.set-l {
  display: block;
  font-size: .7rem;
  color: var(--dim);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.set-grid select,
.batch-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 8px;
  appearance: auto;
}
.set-grid select:focus { border-color: var(--accent); }

.dur-row { display: flex; align-items: center; gap: 6px; }
.dur-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}
.stepper-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}
.stepper-btn:active { background: var(--border); }
.stepper-btn:disabled { opacity: .35; cursor: not-allowed; }
#durationDisplay { flex: 1; text-align: center; font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.dur-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 4px; }
.dur-row span { min-width: 30px; text-align: center; font-weight: 600; font-size: .85rem; }

.set-span { grid-column: 1 / -1; }
.set-span label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--dim);
  cursor: pointer;
}
.set-span input { accent-color: var(--accent); width: 15px; height: 15px; }

.batch-input { width: 70px; text-align: center; }

/* ─── Panel (storage/history tabs) ───── */
.panel {
  margin: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.panel-head { margin-bottom: 8px; }
.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.toolbar-filters { flex: 1; min-width: 0; }
.sort-row { margin-top: 4px; }
.toolbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg);
  color: var(--dim);
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { color: var(--text); border-color: var(--accent); background: var(--surface2); }
.chip.preset-num { min-width: 32px; text-align: center; padding: 5px 8px; }

.prompt-tools { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.prompt-presets-wrap .chip-row { margin-top: 4px; }
.prompt-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.prompt-history-details { font-size: .75rem; }
.prompt-history-details summary { cursor: pointer; color: var(--dim); padding: 2px 0; }
.prompt-history-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 140px; overflow-y: auto; }
.prompt-history-item {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-size: .72rem;
  color: var(--text);
  cursor: pointer;
  line-height: 1.35;
  text-align: left;
}
.prompt-history-item:hover { border-color: var(--accent); }
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  cursor: pointer;
}
.toggle-label input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ─── Buttons ────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 6px 12px;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .12s;
}
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .3; pointer-events: none; }
.cost-badge { font-size: .7rem; font-weight: 400; opacity: .75; }

.btn-sm {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: .78rem;
  cursor: pointer;
  transition: background .12s;
}
.btn-sm:active { background: var(--surface2); }
.btn-sm.danger { border-color: var(--red); color: var(--red); }

.btn-close {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

/* ─── Queue / strips ─────────────────── */
.queue-wrap {
  margin: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.queue-wrap .card-row { margin-bottom: 6px; }
.strip-list { display: flex; flex-direction: column; gap: 4px; }

.queue-strip, .history-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  font-size: .72rem;
}
.queue-strip:hover, .history-strip:hover { border-color: var(--accent); background: var(--surface2); }
.queue-strip.fail, .history-strip.fail { border-color: rgba(239,95,95,.3); }
.history-strip.active-job { border-color: rgba(99,102,241,.35); }
.queue-strip .qi-progress { margin: 3px 0 1px; }
.queue-strip .qi-progress-bar { height: 3px; }

.queue-item { display: none; }
.qi-status {
  font-size: .65rem; font-weight: 600;
  padding: 1px 8px; border-radius: 99px;
}
.qi-s-waiting { background: #1e1e3a; color: #8a8aff; }
.qi-s-queuing { background: #1a2e1a; color: #6fcf6f; }
.qi-s-generating { background: #2e1a1a; color: #f0ad4e; }
.qi-s-success { background: #0f2a1a; color: var(--green); }
.qi-s-fail { background: #2a0f0f; color: var(--red); }
.qi-meta { color: var(--dim); font-size: .7rem; }
.qi-result.fail-tag { color: var(--red); font-size: .72rem; margin-top: 4px; line-height: 1.35; }
.qi-credits { color: var(--accent); font-size: .7rem; margin-top: 2px; }
.qi-progress { margin-top: 6px; }
.qi-progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.qi-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s;
}
.qi-progress-label { font-size: .64rem; color: var(--dim); margin-top: 2px; }

.qi-result { margin-top: 6px; }
.qi-result video, .qi-result img { width: 100%; max-height: 170px; border-radius: 6px; object-fit: cover; }
.qi-actions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.qi-actions a, .qi-actions button {
  padding: 4px 10px;
  border-radius: 5px;
  background: var(--surface2);
  color: var(--text);
  font-size: .7rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background .1s;
}
.qi-actions a:active, .qi-actions button:active { background: var(--border); }
.qi-actions .accent-btn { background: var(--accent); color: #fff; }

/* ─── Storage grid ────────────────────── */
.storage-quota {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.quota-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.quota-bar {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width .3s;
}
.quota-bar.warn { background: #f0ad4e; }
.quota-bar.danger { background: var(--red); }
.quota-text { font-size: .7rem; color: var(--dim); white-space: nowrap; }
.storage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.storage-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  position: relative;
  transition: border-color .12s;
}
.storage-item.highlight { border-color: var(--accent); }
.storage-item.liked { border-color: rgba(239,95,108,.45); }
.si-fav {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .65rem;
  cursor: pointer;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.si-fav.active { background: rgba(239,95,108,.9); }
.si-thumb-mini {
  width: 100%;
  height: 72px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  background: var(--surface2);
}
.si-thumb-mini.video {
  display: flex;
  align-items: center;
  justify-content: center;
}
.si-play-sm {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: .65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 2px;
}
.storage-item .si-info {
  padding: 4px 5px;
  font-size: .56rem;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.storage-item .si-select {
  position: absolute;
  top: 4px; left: 4px;
  width: 14px; height: 14px;
  accent-color: var(--accent);
  z-index: 3;
}
.storage-bar { display: none; }

/* ─── History ────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 3px; }
.hs-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.hs-dot.success { background: var(--green); }
.hs-dot.fail { background: var(--red); }
.hs-dot.waiting, .hs-dot.generating, .hs-dot.queuing { background: var(--accent); }
.hs-body { flex: 1; min-width: 0; }
.hs-prompt {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.hs-meta { color: var(--dim); font-size: .64rem; line-height: 1.3; }
.hs-meta .fail-tag { color: var(--red); }
.hs-chevron { color: var(--dim); font-size: .9rem; flex-shrink: 0; }
.hi-status.waiting, .hi-status.generating, .hi-status.queuing { color: var(--accent); }

/* ─── Overlay ────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  animation: .15s fadeIn;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-panel {
  width: 100%;
  max-height: 90dvh;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: .2s up;
}
@keyframes up { from { transform: translateY(30px); } to { transform: translateY(0); } }
.overlay-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.overlay-h h2 { font-size: .95rem; font-weight: 600; }
.overlay-b { flex: 1; overflow-y: auto; padding: 14px 18px; }
.overlay-f { padding: 10px 18px 16px; border-top: 1px solid var(--border); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .78rem; font-weight: 600; margin-bottom: 4px; }
.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px;
  outline: none;
  font-size: .85rem;
}
.field input:focus { border-color: var(--accent); }
.f-hint { font-size: .68rem; color: var(--dim); margin-top: 3px; }
.f-hint a { color: var(--accent); }

.alert-box {
  background: #1e1e2a;
  border: 1px solid #f0ad4e;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: .75rem;
  color: #f0ad4e;
  margin-bottom: 12px;
}

/* ─── Toast ──────────────────────────── */
.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: .82rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  animation: ti .2s ease-out;
  white-space: nowrap;
  pointer-events: auto;
}
.toast.err { border-color: var(--red); }
.toast.ok { border-color: var(--green); }
@keyframes ti { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Empty state ────────────────────── */
.empty-state {
  text-align: center;
  color: var(--dim);
  font-size: .82rem;
  padding: 20px 16px;
}

/* ─── Modal for video preview ────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0,0,0,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: .12s fadeIn;
}
.modal-content {
  max-width: 100%;
  max-height: 90dvh;
  border-radius: 8px;
  overflow: hidden;
}
.modal-content video { width: 100%; max-height: 82dvh; display: block; background: #000; }
.modal-content img { max-width: 100%; max-height: 82dvh; border-radius: 8px; display: block; }
.modal-actions {
  position: absolute;
  top: 12px; left: 12px;
  z-index: 2;
}
.modal-dl {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .75rem;
  cursor: pointer;
}
.modal-dl:disabled { opacity: .5; cursor: wait; }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(0,0,0,.6);
  border: none;
  color: #fff;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ─── Login panel ────────────────────── */
.login-panel { max-width: 360px; margin: 0 auto; border-radius: 14px !important; }
.login-panel .btn-primary { margin: 0; width: 100%; }