/* Director Studio v2 — Multi-tenant */

:root {
  --bg: #0c0a14;
  --bg-2: #1a1626;
  --bg-3: #2a2438;
  --fg: #f0e8f5;
  --fg-muted: #998fa6;
  --accent: #d4af37;
  --accent-2: #ff4d6d;
  --ok: #2ecc71;
  --warn: #f39c12;
  --err: #e74c3c;
  --border: rgba(212, 175, 55, 0.2);
  --radius: 8px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Sarabun', 'Noto Serif Thai', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { font-family: 'JetBrains Mono', monospace; }

.muted { color: var(--fg-muted); }
.error { color: var(--err); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* ============== Auth ============== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, #2a1a3a 0%, var(--bg) 60%);
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-mark {
  display: inline-block;
  font-size: 48px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}
.auth-title {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  letter-spacing: 0.2em;
  margin: 8px 0 4px;
}
.auth-sub { color: var(--fg-muted); font-size: 13px; margin: 0; }

.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg-3); padding: 4px; border-radius: 8px; }
.auth-tab {
  flex: 1;
  background: transparent;
  color: var(--fg-muted);
  border: none;
  padding: 10px;
  border-radius: 6px;
  font-size: 14px;
}
.auth-tab.active { background: var(--accent); color: #000; font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; }
.auth-field span { font-size: 13px; color: var(--fg-muted); }
.auth-submit {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border: none;
  padding: 12px;
  border-radius: 6px;
  font-size: 15px;
  margin-top: 8px;
}
.auth-submit:disabled { opacity: 0.5; }
.auth-error { color: var(--err); font-size: 13px; min-height: 18px; }
.auth-hint { font-size: 12px; color: var(--fg-muted); text-align: center; margin-top: 8px; }

/* ============== App ============== */
.app { min-height: 100vh; }

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); }
.brand-mark { color: var(--accent); font-size: 24px; }
.brand-text { font-family: 'Cinzel', serif; letter-spacing: 0.15em; font-size: 14px; }

.topnav-links { display: flex; align-items: center; gap: 20px; }
.topnav-links a { color: var(--fg-muted); font-size: 14px; }
.topnav-links a:hover, .topnav-links a.active { color: var(--fg); }
.user-chip {
  background: var(--bg-3);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  border: 1px solid var(--border);
}
.logout-btn {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  width: 32px; height: 32px;
  border-radius: 6px;
  font-size: 16px;
}
.logout-btn:hover { color: var(--err); border-color: var(--err); }

.tab-panel { padding: 32px; max-width: 1200px; margin: 0 auto; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.section-title { font-family: 'Cinzel', serif; font-size: 28px; margin: 0; letter-spacing: 0.1em; }
.section-sub { font-size: 18px; margin: 24px 0 12px; color: var(--fg-muted); }

.primary-btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
}
.primary-btn:hover { background: #e6c054; }
.primary-btn.small { padding: 6px 12px; font-size: 12px; }
.primary-btn:disabled { opacity: 0.5; }

.ghost-btn {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
}
.ghost-btn:hover { border-color: var(--accent); }
.danger-btn {
  background: transparent;
  color: var(--err);
  border: 1px solid var(--err);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
}
.danger-btn:hover { background: var(--err); color: #fff; }

/* ============== Projects ============== */
.projects-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.project-card-name { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.project-card-meta { display: flex; justify-content: space-between; font-size: 12px; }
.kind-badge {
  background: var(--accent);
  color: #000;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.empty-state { text-align: center; padding: 60px 20px; grid-column: 1 / -1; }
.empty-state p { margin: 4px 0; }

/* ============== Project detail ============== */
.project-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.back-btn {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
}
.back-btn:hover { color: var(--fg); }
.project-name { font-family: 'Cinzel', serif; font-size: 24px; margin: 0; }
.project-actions { margin-left: auto; }

.episodes-list { display: flex; flex-direction: column; gap: 12px; }
.ep-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  gap: 16px;
  align-items: center;
  transition: all 0.2s;
}
.ep-card:hover { border-color: var(--accent); }
.ep-card-num {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  width: 56px; height: 56px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.ep-card-body { flex: 1; }
.ep-card-title { font-size: 16px; font-weight: 600; }
.ep-card-meta { display: flex; gap: 12px; font-size: 13px; align-items: center; }
.badge { background: var(--bg-3); padding: 2px 8px; border-radius: 4px; font-size: 11px; }
.badge.ok { background: rgba(46, 204, 113, 0.2); color: var(--ok); }

.ep-actions { display: flex; gap: 12px; margin-top: 20px; }

/* ============== Episode modal ============== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-card.large { max-width: 900px; }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  color: var(--fg-muted);
  border: none;
  font-size: 24px;
  width: 32px; height: 32px;
}
.modal-close:hover { color: var(--err); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.episode-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0; }
.ep-tab {
  background: transparent;
  color: var(--fg-muted);
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
.ep-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.ep-section h4 { margin-top: 0; }
.script-pre {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
}
.veo-item {
  background: var(--bg-3);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.veo-item-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.veo-item-num {
  background: var(--accent);
  color: #000;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
}
.veo-result { margin-top: 8px; }

/* ============== Settings ============== */
.settings-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}
.settings-card h3 { margin-top: 0; }
.settings-card code { background: var(--bg-3); padding: 2px 6px; border-radius: 4px; }
.jwt-status {
  padding: 8px 12px;
  border-radius: 6px;
  margin: 8px 0;
  font-size: 14px;
}
.jwt-status.ok { background: rgba(46, 204, 113, 0.1); color: var(--ok); border: 1px solid var(--ok); }
.jwt-status.warn { background: rgba(243, 156, 18, 0.1); color: var(--warn); border: 1px solid var(--warn); }
.jwt-actions { display: flex; gap: 8px; margin-top: 12px; }
.test-result { margin-top: 12px; font-size: 14px; }
.test-result code { background: var(--bg-3); padding: 2px 6px; border-radius: 4px; }
.test-result details { margin-top: 8px; font-size: 12px; }
.test-result ul { margin: 4px 0; padding-left: 20px; }
.test-result li { color: var(--fg-muted); margin: 2px 0; }
.ok-box { background: rgba(46,204,113,0.1); border: 1px solid var(--ok); padding: 12px; border-radius: 6px; }
.quota-display {
  background: linear-gradient(135deg, rgba(212,175,55,0.15), rgba(255,77,109,0.08));
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  font-size: 14px;
}
.quota-display .quota-row { display: flex; gap: 24px; flex-wrap: wrap; align-items: center; }
.quota-display .quota-item { display: flex; flex-direction: column; gap: 4px; }
.quota-display .quota-label { color: var(--fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.quota-display .quota-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.quota-display .quota-value.balance { color: var(--fg); }
.quota-display .quota-value.remaining { color: var(--ok); }
.quota-display .quota-value.used { color: var(--fg-muted); }
.quota-display .quota-expiry { font-size: 12px; color: var(--fg-muted); margin-top: 8px; }
.quota-display .quota-bar { background: var(--bg-3); height: 8px; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.quota-display .quota-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.script-result { margin-top: 16px; }
.script-summary { background: var(--bg-3); padding: 12px; border-radius: 6px; margin-bottom: 12px; }
.script-summary p { margin: 4px 0; }
.scenes-list { display: flex; flex-direction: column; gap: 8px; }
.scene-item { display: flex; gap: 12px; background: var(--bg-3); padding: 12px; border-radius: 6px; }
.scene-num { background: var(--accent); color: #000; width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.scene-body { flex: 1; }
.scene-body p { margin: 4px 0; font-size: 13px; }
.scene-body .dialogue { background: rgba(212,175,55,0.1); padding: 6px 10px; border-left: 2px solid var(--accent); border-radius: 4px; margin: 6px 0; }
.episode-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ============== Admin ============== */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}
.stat-num { font-size: 32px; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--fg-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; margin-top: 4px; }
.users-list { display: flex; flex-direction: column; gap: 8px; }
.user-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ============== Toast ============== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-3);
  color: var(--fg);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: all 0.3s;
  z-index: 1000;
  max-width: 80vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--ok); }
.toast.error { border-color: var(--err); }
.toast.warn { border-color: var(--warn); }
.toast.info { border-color: var(--accent); }
