/* DAIVideo Sketch v2.0 — CSS */
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

:root {
  --bg-base: #0a0c10;
  --bg-surface: #10131a;
  --bg-elevated: #161b24;
  --bg-hover: #1c2230;
  --bg-card: #131720;
  --bg-input: #0e111a;

  --border: rgba(255,255,255,0.07);
  --border-focus: rgba(99,102,241,0.5);

  --accent: #6366f1;
  --accent-bright: #818cf8;
  --accent-dim: rgba(99,102,241,0.15);
  --accent-glow: 0 0 24px rgba(99,102,241,0.3);

  --status-draft: #64748b;
  --status-review: #f59e0b;
  --status-ready: #10b981;
  --status-locked: #6366f1;

  --text-primary: #e8eaf0;
  --text-secondary: #8892a4;
  --text-muted: #4a5568;
  --text-accent: #818cf8;

  --red: #ef4444;
  --green: #10b981;
  --yellow: #f59e0b;
  --blue: #3b82f6;

  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  --font-display: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Auth pages ─── */
#auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.auth-box {
  width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
}

.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.auth-logo h1 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-logo span { color: var(--text-secondary); font-weight: 400; }

.auth-box h2 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.auth-box p { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.9rem; }

.auth-toggle { margin-top: 20px; text-align: center; color: var(--text-secondary); font-size: 0.9rem; }
.auth-toggle a { color: var(--accent-bright); cursor: pointer; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  display: none;
}

/* ─── App Layout ─── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ─── Top Header ─── */
.app-header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 100;
}

.header-logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: inherit;
  flex-shrink: 0;
}

.header-logo-icon {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}

.header-logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.header-logo-text span { color: var(--text-secondary); font-weight: 500; font-size: 0.8rem; margin-left: 3px; }

.header-project-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: var(--transition);
  min-width: 180px;
  position: relative;
}

.header-project-selector:hover { border-color: var(--border-focus); color: var(--text-primary); }

.header-project-selector .project-name {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.header-spacer { flex: 1; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.user-menu {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
  position: relative;
}

.user-menu:hover { border-color: rgba(255,255,255,0.15); }

.user-avatar {
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
  font-family: var(--font-display);
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ─── Body Layout ─── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-new-project {
  margin: 12px;
  padding: 9px 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  transition: var(--transition);
  width: calc(100% - 24px);
}

.sidebar-new-project:hover { background: var(--accent-bright); box-shadow: var(--accent-glow); }

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 16px 5px;
}

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

.sidebar-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: var(--transition);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav-item.active { background: var(--accent-dim); color: var(--accent-bright); }

.sidebar-nav-item .nav-icon { width: 16px; text-align: center; flex-shrink: 0; opacity: 0.7; }
.sidebar-nav-item.active .nav-icon { opacity: 1; }

.sidebar-nav-badge {
  margin-left: auto;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-nav-item.active .sidebar-nav-badge { background: var(--accent-dim); color: var(--accent-bright); }

.sidebar-characters {
  display: flex; flex-direction: column; gap: 1px;
  padding: 0 8px;
  overflow-y: auto;
  max-height: 200px;
}

.sidebar-character-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: var(--transition);
  border: none; background: none; width: 100%; text-align: left;
}

.sidebar-character-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-character-item.active { color: var(--text-primary); }

.char-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 8px 16px; }
.sidebar-bottom { margin-top: auto; }

/* ─── Main content ─── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
}

.view { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.view.active { display: flex; }

/* ─── View Header ─── */
.view-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--bg-surface);
}

.view-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}

.view-subtitle { color: var(--text-secondary); font-size: 0.82rem; }
.view-header-spacer { flex: 1; }

.view-actions { display: flex; align-items: center; gap: 8px; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-bright); box-shadow: var(--accent-glow); }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); border-color: rgba(255,255,255,0.15); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger { background: rgba(239,68,68,0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.25); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-icon { padding: 7px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Form elements ─── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

label { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 8px 12px;
  width: 100%;
  outline: none;
  transition: var(--transition);
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

/* ─── Search bar ─── */
.search-bar {
  position: relative;
  display: flex; align-items: center;
}

.search-bar input { padding-left: 32px; min-width: 200px; }
.search-bar .search-icon {
  position: absolute; left: 10px;
  color: var(--text-muted);
  pointer-events: none;
  font-size: 13px;
}

/* ─── Status badge ─── */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-badge.draft    { background: rgba(100,116,139,0.15); color: #94a3b8; }
.status-badge.review   { background: rgba(245,158,11,0.15); color: #fcd34d; }
.status-badge.ready    { background: rgba(16,185,129,0.15); color: #6ee7b7; }
.status-badge.locked   { background: rgba(99,102,241,0.15); color: #a5b4fc; }

/* ─── Storyboard view ─── */
.storyboard-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.storyboard-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  align-content: start;
}

/* Scene Card */
.scene-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  display: flex;
  flex-direction: column;
}

.scene-card:hover {
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.scene-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

.scene-card-thumb {
  height: 150px;
  background: var(--bg-elevated);
  position: relative;
  overflow: hidden;
}

.scene-card-thumb img, .scene-card-thumb video {
  width: 100%; height: 100%;
  object-fit: cover;
}

.scene-card-thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  flex-direction: column; gap: 6px;
  font-size: 0.75rem;
}

.scene-card-thumb-placeholder .ph-icon { font-size: 24px; }

.scene-card-number {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 2px 7px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

.scene-card-status {
  position: absolute; top: 8px; right: 8px;
}

.scene-card-body { padding: 12px; flex: 1; }

.scene-card-title {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 5px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scene-card-prompt {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scene-card-footer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.scene-card-chars {
  display: flex; gap: 3px; margin-left: auto;
}

.scene-char-avatar {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1.5px solid var(--bg-card);
  overflow: hidden;
  font-size: 0.6rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-bright);
  font-weight: 700;
}

.scene-char-avatar img { width: 100%; height: 100%; object-fit: cover; }

.scene-card-drag-handle {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 4px;
  background: transparent;
  cursor: grab;
  transition: var(--transition);
}

.scene-card:hover .scene-card-drag-handle { background: var(--border); }
.scene-card.dragging { opacity: 0.5; }

/* Add scene card */
.scene-add-card {
  background: transparent;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.scene-add-card:hover {
  border-color: var(--accent);
  color: var(--accent-bright);
  background: var(--accent-dim);
}

.scene-add-card .add-icon { font-size: 28px; }

/* ─── Characters view ─── */
.character-tabs {
  display: flex; gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.character-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
}

.character-tab:hover { border-color: rgba(255,255,255,0.15); color: var(--text-primary); }
.character-tab.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent-bright); }

.character-tab .tab-dot { width: 7px; height: 7px; border-radius: 50%; }
.character-tab .tab-scenes { font-size: 0.72rem; color: var(--text-muted); }
.character-tab.active .tab-scenes { color: var(--accent-bright); opacity: 0.7; }

.char-tab-close {
  margin-left: 4px;
  opacity: 0;
  transition: var(--transition);
  font-size: 10px;
  color: var(--text-muted);
}
.character-tab:hover .char-tab-close { opacity: 1; }

.character-profile {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.character-profile-left {
  width: 120px;
  flex-shrink: 0;
  padding: 16px 8px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
}

.char-portrait-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
  flex-shrink: 0;
}

.char-portrait-thumb:hover { border-color: rgba(255,255,255,0.2); }
.char-portrait-thumb.active { border-color: var(--accent); }
.char-portrait-thumb img { width: 100%; height: 100%; object-fit: cover; }

.char-portrait-add {
  width: 100%;
  aspect-ratio: 3/4;
  background: var(--bg-elevated);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.72rem;
  transition: var(--transition);
}

.char-portrait-add:hover { border-color: var(--accent); color: var(--accent-bright); }

.character-profile-main {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-base);
}

.char-main-image {
  width: 100%; height: 100%;
  object-fit: contain;
}

.char-main-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  flex-direction: column; gap: 10px;
}

.char-main-placeholder .ph-icon { font-size: 48px; }

.character-profile-right {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.char-right-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
}

.char-right-scroll { flex: 1; overflow-y: auto; padding: 16px; }

.char-field-group {
  margin-bottom: 16px;
}

.char-field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.char-field-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}

.char-right-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(20px) scale(0.98);
  transition: transform var(--transition);
  overflow: hidden;
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-sm { max-width: 440px; }
.modal-md { max-width: 600px; }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1100px; }

.modal-header {
  display: flex; align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 18px;
  transition: var(--transition);
}

.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body { flex: 1; overflow-y: auto; padding: 20px; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

/* Scene editor (large modal) */
.scene-editor {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 0;
  height: 600px;
  overflow: hidden;
}

.scene-editor-main { overflow-y: auto; padding: 20px; border-right: 1px solid var(--border); }
.scene-editor-sidebar { overflow-y: auto; padding: 16px; }

.scene-editor-media {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 14px;
}

.scene-media-header {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  gap: 8px;
}

.scene-media-grid {
  display: flex; gap: 8px; padding: 10px;
  flex-wrap: wrap;
}

.scene-media-thumb {
  width: 72px; height: 72px;
  background: var(--bg-base);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}

.scene-media-thumb:hover { border-color: rgba(255,255,255,0.2); }
.scene-media-thumb img, .scene-media-thumb video { width: 100%; height: 100%; object-fit: cover; }

.scene-media-thumb-del {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  background: rgba(0,0,0,0.8);
  border-radius: 50%;
  display: none;
  align-items: center; justify-content: center;
  font-size: 9px;
  cursor: pointer;
  color: #fca5a5;
}

.scene-media-thumb:hover .scene-media-thumb-del { display: flex; }

.scene-media-add {
  width: 72px; height: 72px;
  background: var(--bg-base);
  border: 2px dashed var(--border);
  border-radius: 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; color: var(--text-muted); font-size: 0.65rem;
  transition: var(--transition);
}

.scene-media-add:hover { border-color: var(--accent); color: var(--accent-bright); }

/* ─── Records Table ─── */
.records-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.records-table-wrap { flex: 1; overflow: auto; }

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.records-table thead { position: sticky; top: 0; z-index: 10; }

.records-table th {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.records-table th:hover { color: var(--text-primary); }
.records-table th.sorted { color: var(--accent-bright); }

.records-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

.records-table tbody tr { transition: var(--transition); cursor: pointer; }
.records-table tbody tr:hover { background: var(--bg-hover); }
.records-table tbody tr.selected { background: var(--accent-dim); }

/* ─── Analytics view ─── */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.analytics-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.analytics-card-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
}

.stat-sub { color: var(--text-secondary); font-size: 0.8rem; margin-top: 4px; }

/* Progress bars */
.progress-item { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.progress-label { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.progress-bar-track { height: 6px; background: var(--bg-elevated); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 3px; transition: width 0.8s ease; }

/* ─── Import/Export view ─── */
.import-export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}

.ie-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.ie-card h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}

.ie-card p { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 16px; line-height: 1.5; }

.json-preview {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 12px;
}

/* ─── Projects overview ─── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}

.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
}

.project-card:hover { border-color: rgba(255,255,255,0.15); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }

.project-card-thumb {
  height: 120px;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 32px;
  overflow: hidden;
}

.project-card-thumb img { width: 100%; height: 100%; object-fit: cover; }

.project-card-body { padding: 14px; }

.project-card-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.project-card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.project-progress-bar {
  height: 3px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  margin: 10px 0;
}

.project-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ─── Dropdown ─── */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  min-width: 160px;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.dropdown-menu.open { display: block; }

.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  border: none; background: none; width: 100%; text-align: left;
}

.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.danger { color: #fca5a5; }
.dropdown-item.danger:hover { background: rgba(239,68,68,0.1); }

.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  display: flex; align-items: center; gap: 8px;
  max-width: 320px;
  pointer-events: auto;
  animation: toastIn 0.25s ease;
}

.toast.success { border-color: rgba(16,185,129,0.3); }
.toast.error { border-color: rgba(239,68,68,0.3); }
.toast.info { border-color: rgba(99,102,241,0.3); }

.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
.toast.info .toast-icon { color: var(--accent-bright); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── Loading ─── */
.loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(10,12,16,0.7);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
  z-index: 50;
}

/* ─── Empty states ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 4px; }
.empty-state h3 { font-family: var(--font-display); font-size: 1rem; font-weight: 700; color: var(--text-secondary); }
.empty-state p { font-size: 0.85rem; max-width: 280px; line-height: 1.5; }

/* ─── Color dots for characters ─── */
.color-0 { background: #6366f1; }
.color-1 { background: #10b981; }
.color-2 { background: #f59e0b; }
.color-3 { background: #ef4444; }
.color-4 { background: #3b82f6; }
.color-5 { background: #ec4899; }
.color-6 { background: #8b5cf6; }
.color-7 { background: #06b6d4; }

/* ─── Drag over ─── */
.drag-over { border-color: var(--accent) !important; background: var(--accent-dim) !important; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -240px; z-index: 300; transition: left var(--transition-slow); top: var(--header-h); bottom: 0; }
  .sidebar.mobile-open { left: 0; }
  .import-export-grid { grid-template-columns: 1fr; }
  .scene-editor { grid-template-columns: 1fr; height: auto; }
  .character-profile { flex-direction: column; }
  .character-profile-right { width: 100%; border-left: none; border-top: 1px solid var(--border); }
}

/* ─── Tabs ─── */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 0;
  flex-shrink: 0;
}

.tab-btn {
  padding: 10px 16px;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none; background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
}

.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--accent-bright); border-bottom-color: var(--accent); }

/* ─── Highlight for filter chips ─── */
.filter-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}

.filter-chip:hover, .filter-chip.active { border-color: var(--accent); color: var(--accent-bright); background: var(--accent-dim); }
.filter-chip .chip-dot { width: 6px; height: 6px; border-radius: 50%; }

/* ─── Character selector in scene editor ─── */
.char-selector-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.char-selector-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.char-selector-item:hover { background: var(--bg-hover); }
.char-selector-item.selected { background: var(--accent-dim); }

.char-selector-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-elevated);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700;
}

.char-selector-avatar img { width: 100%; height: 100%; object-fit: cover; }

.char-selector-name { font-size: 0.82rem; font-weight: 500; }
.char-selector-role { font-size: 0.72rem; color: var(--text-muted); }

.char-check {
  margin-left: auto;
  color: var(--accent-bright);
  display: none;
}
.char-selector-item.selected .char-check { display: block; }

/* Scene header title with status selector */
.scene-header-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}

.scene-status-select {
  width: auto;
  padding: 5px 28px 5px 8px;
}

/* ─── Bulk action bar ─── */
.bulk-action-bar {
  display: none;
  align-items: center; gap: 10px;
  padding: 8px 16px;
  background: var(--accent-dim);
  border-bottom: 1px solid var(--border-focus);
  font-size: 0.83rem;
  color: var(--accent-bright);
  flex-shrink: 0;
}

.bulk-action-bar.visible { display: flex; }

/* ─── Tag input ─── */
.tag-input-wrap {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  cursor: text;
  transition: var(--transition);
}

.tag-input-wrap:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-dim); }

.tag-chip {
  background: var(--accent-dim);
  color: var(--accent-bright);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.75rem;
  display: flex; align-items: center; gap: 4px;
}

.tag-chip-del { cursor: pointer; opacity: 0.7; }
.tag-chip-del:hover { opacity: 1; }

.tag-input-inner {
  border: none; background: transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  min-width: 80px;
  flex: 1;
  padding: 2px 0;
}

/* ─── Tooltip ─── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition);
  z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ─── Context menu ─── */
.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  z-index: 400;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  display: none;
}

.context-menu.open { display: block; }

/* ─── View transition ─── */
.view { animation: none; }
.view.active { animation: viewFadeIn 0.15s ease; }

@keyframes viewFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── Project selector dropdown ─── */
.project-select-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: none;
}

.project-select-dropdown.open { display: block; }

.psd-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.83rem;
  transition: var(--transition);
  border-bottom: 1px solid var(--border);
}

.psd-item:last-child { border-bottom: none; }
.psd-item:hover { background: var(--bg-hover); }
.psd-item.active { color: var(--accent-bright); }

.psd-item-title { font-weight: 600; color: var(--text-primary); }
.psd-item-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* Mini stats bar in modal */
.mini-stats { display: flex; gap: 16px; margin-bottom: 16px; }
.mini-stat { text-align: center; }
.mini-stat-val { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; }
.mini-stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
