:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --green: #3fb950;
  --green-dim: #238636;
  --cyan: #58d9f9;
  --yellow: #e3b341;
  --red: #f85149;
  --purple: #bc8cff;
  --white: #e6edf3;
  --gray: #8b949e;
  --orange: #ffa657;
  --blue: #1f6feb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  font-size: 14px;
}

/* ═══ HEADER ═══════════════════════════════════════════════ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.header-btn {
  background: none;
  border: none;
  color: var(--gray);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}
.header-btn:hover { color: var(--white); background: var(--surface2); }

.header-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.3px;
}

.avatar-wrap {
  position: relative;
  cursor: pointer;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green-dim);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid var(--border);
  transition: border-color 0.15s;
}
.avatar:hover { border-color: var(--green); }

.avatar-dropdown {
  position: absolute;
  top: 40px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
  padding: 6px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: none;
  z-index: 200;
}
.avatar-dropdown.show { display: block; }

.dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  color: var(--white);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.1s;
}
.dd-item:hover { background: var(--surface2); }
.dd-item svg { color: var(--gray); flex-shrink: 0; }
.dd-logout { color: var(--red); }
.dd-logout svg { color: var(--red); }
.dd-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ═══ SIDEBAR ══════════════════════════════════════════════ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 149;
  display: none;
}
.sidebar-overlay.show { display: block; }

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 150;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.app-sidebar.open { transform: translateX(0); }

.sidebar-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--green);
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--gray);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.sidebar-close:hover { color: var(--white); background: var(--surface2); }

.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--gray);
  text-decoration: none;
  font-size: 14px;
  border-radius: 8px;
  transition: all 0.15s;
}
.nav-item:hover { color: var(--white); background: var(--surface2); }
.nav-item.active { color: var(--white); background: rgba(56,189,248,0.1); }
.nav-item.active svg { color: var(--cyan); }

/* ═══ MAIN CONTENT ═════════════════════════════════════════ */
.app-content {
  margin-top: 56px;
  min-height: calc(100vh - 56px);
  padding: 16px;
}

/* Page fragments that need full-width max-width container */
.app-content > .page-wrap,
.app-content > .pg-wrap {
  max-width: 720px;
  margin: 0 auto;
}

.page-error {
  text-align: center;
  color: var(--gray);
  padding: 60px 20px;
  font-size: 16px;
}

/* ═══ LOGIN PAGE ═══════════════════════════════════════════ */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  text-align: center;
  font-size: 22px;
  color: var(--green);
  margin-bottom: 4px;
}

.login-logo {
  text-align: center;
  margin-bottom: 16px;
}
.login-logo-img {
  height: 48px;
  width: auto;
  filter: drop-shadow(0 0 12px rgba(63, 185, 80, 0.3));
  transition: transform 0.3s ease, filter 0.3s ease;
}
.login-logo-img:hover {
  transform: scale(1.08);
  filter: drop-shadow(0 0 20px rgba(63, 185, 80, 0.5));
}

.powered-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.powered-by span {
  color: var(--gray);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.powered-logo {
  height: 24px;
  width: auto;
  opacity: 0.7;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.powered-logo:hover {
  opacity: 1;
  transform: scale(1.05);
}

.login-card .login-sub {
  text-align: center;
  color: var(--gray);
  font-size: 13px;
  margin-bottom: 24px;
}

.login-card .field {
  margin-bottom: 16px;
}

.login-card label {
  display: block;
  color: var(--gray);
  font-size: 12px;
  margin-bottom: 6px;
}

.login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.login-card input:focus { border-color: var(--cyan); }

.login-card .btn-login {
  width: 100%;
  background: var(--green-dim);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.login-card .btn-login:hover { background: #2ea043; }
.login-card .btn-login:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin-bottom: 12px;
  display: none;
}

/* ═══ SHARED COMPONENTS ════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--white);
}

.form-field {
  margin-bottom: 14px;
}

.form-field label {
  display: block;
  color: var(--gray);
  font-size: 12px;
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--cyan); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-input::placeholder, .form-textarea::placeholder { color: #484f58; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--green-dim); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2ea043; }

.btn-secondary { background: var(--surface2); color: var(--white); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--gray); }

.btn-danger { background: #2a0a0a; color: var(--red); border: 1px solid #5c2020; }
.btn-danger:hover:not(:disabled) { background: #3d0a0a; border-color: var(--red); }

.btn-full { width: 100%; justify-content: center; }

.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-success { background: rgba(35,134,54,0.15); color: var(--green); border: 1px solid rgba(35,134,54,0.3); }
.alert-error { background: rgba(248,81,73,0.1); color: var(--red); border: 1px solid rgba(248,81,73,0.2); }

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ═══ PROMPT GENERATOR ═════════════════════════════════════ */
.prompt-result-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.prompt-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--gray);
  cursor: pointer;
  transition: all 0.15s;
}
.prompt-tab.active { background: var(--surface2); color: var(--cyan); border-color: var(--cyan); }
.prompt-tab:hover:not(.active) { border-color: var(--gray); color: var(--white); }

.prompt-panel { display: none; }
.prompt-panel.active { display: block; }

.prompt-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}

.prompt-block-label {
  font-size: 10px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.prompt-text {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--white);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.prompt-text::-webkit-scrollbar { width: 4px; }
.prompt-text::-webkit-scrollbar-track { background: transparent; }
.prompt-text::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.copy-btn {
  margin-top: 8px;
  padding: 6px 14px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.copy-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ═══ LIBRARY ══════════════════════════════════════════════ */
.library-group {
  margin-bottom: 20px;
}

.library-group-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.video-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.video-card video {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  display: block;
}

.video-card .vc-info {
  padding: 8px 10px;
}

.video-card .vc-name {
  font-size: 12px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-card .vc-date {
  font-size: 11px;
  color: var(--gray);
  margin-top: 2px;
}

.video-card .vc-actions {
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

/* ═══ AI VIDEOS IFRAME ═════════════════════════════════════ */
.ai-videos-frame {
  width: 100%;
  height: calc(100vh - 88px);
  border: none;
  border-radius: 8px;
}

/* ═══ DROPZONE (shared) ════════════════════════════════════ */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--cyan);
  background: #0f1f2e;
}
.dropzone .dz-text { color: var(--gray); font-size: 13px; }
.dropzone .dz-text span { color: var(--cyan); }
.dropzone .dz-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}
.dropzone .dz-preview img {
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
}
.dropzone .dz-preview .fname { color: var(--green); font-size: 12px; }
.dropzone .dz-preview .fsize { color: var(--gray); font-size: 11px; }

/* ═══ RESPONSIVE ═══════════════════════════════════════════ */
@media (max-width: 480px) {
  .app-content { padding: 12px 8px; }
  .card { padding: 12px; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
