:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

body.is-login {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

.view { min-height: 100vh; }

.view[hidden] {
  display: none !important;
}

/* Login — overlay plein écran */
#view-login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#view-login.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  transition: transform 0.4s ease, opacity 0.35s ease;
}

#view-login.is-leaving .login-card {
  opacity: 0;
  transform: scale(0.94) translateY(-16px);
}

/* Dashboard — entrée en fondu */
#view-dashboard {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.45s ease 0.08s, transform 0.45s ease 0.08s;
}

#view-dashboard.is-visible {
  opacity: 1;
  transform: none;
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-icon {
  display: inline-flex;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  background: #eff6ff;
  color: var(--primary);
  border-radius: 12px;
  font-size: 20px;
  margin-bottom: 12px;
}
.brand h1 { font-size: 1.5rem; font-weight: 700; }
.brand p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

.login-form label {
  display: block;
  margin-bottom: 16px;
}
.login-form label span {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.login-form input:focus {
  outline: 2px solid #93c5fd;
  border-color: var(--primary);
}

.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}
.btn-icon:hover { background: #f1f5f9; color: var(--text); }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-mini { font-weight: 700; font-size: 0.95rem; }

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h2 { font-size: 1.5rem; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }

.filter-label span {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
select, .upload-options input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  min-width: 180px;
}
select:focus, input:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }

/* Dropzone */
.dropzone {
  background: var(--surface);
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 16px;
}
.dropzone:hover, .dropzone:focus, .dropzone.is-dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.dropzone-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.7; }
.dropzone-title { font-weight: 600; font-size: 1.05rem; }
.dropzone-hint { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.upload-progress { margin-top: 20px; }
.upload-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
.upload-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.2s;
}
.upload-status { font-size: 0.85rem; color: var(--muted); margin-top: 8px; }

.yt-import {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}
.yt-import-label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.yt-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.yt-form input,
.yt-form select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  min-width: 0;
}
.yt-status {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.yt-hint { font-size: 0.78rem; margin-top: 8px; }

.upload-options {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}
.upload-options label span {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.upload-options input, .upload-options select { width: 100%; min-width: 0; }
.upload-options-actions { display: flex; gap: 8px; }

/* Video grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.video-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.video-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}
.video-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  background: #eff6ff;
  color: var(--primary);
}
.video-meta {
  font-size: 0.78rem;
  color: var(--muted);
}
.video-link {
  font-size: 0.78rem;
  color: var(--primary);
  word-break: break-all;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, monospace;
}
.video-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 0.95rem;
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 480px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(15, 23, 42, 0.4); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.05rem; }
.category-form, .edit-form { padding: 16px 20px; }
.category-form {
  display: flex;
  gap: 8px;
}
.category-form input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; }
.category-list {
  list-style: none;
  padding: 0 20px 20px;
  max-height: 320px;
  overflow-y: auto;
}
.category-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}
.category-list li:last-child { border-bottom: none; }
.category-list .cat-name { font-weight: 500; flex: 1; }
.category-list .cat-count { font-size: 0.75rem; color: var(--muted); }
.category-list .cat-actions { display: flex; gap: 4px; }

.edit-form label { display: block; margin-bottom: 14px; }
.edit-form label span { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.edit-form input, .edit-form select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }

/* Modal montage */
.modal-montage { max-width: 720px; }
.montage-body { padding: 0 0 8px; max-height: 90vh; overflow-y: auto; }
.montage-intro {
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  padding: 12px 20px;
  font-size: 0.88rem;
  color: #1e3a5f;
}
.montage-target-badge {
  margin: 12px 20px 0;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.montage-target-badge strong { color: var(--text); }
.montage-step {
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
}
.montage-step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.step-num {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.montage-step-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.45;
}
.montage-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.montage-video {
  width: 100%;
  max-height: 240px;
  background: #0f172a;
  border-radius: 8px;
}
.montage-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.montage-mode {
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.montage-mode.is-active {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}
.montage-panel-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}
.trim-track {
  position: relative;
  height: 10px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 12px;
}
.trim-track-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 99px;
  left: 0;
  width: 100%;
}
.trim-track-fill.is-keep { background: var(--primary); }
.trim-track-fill.is-cut { background: #f87171; }
.montage-time-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}
.montage-time-row label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.montage-time-row input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  accent-color: var(--primary);
}
.montage-summary {
  font-size: 0.88rem;
  margin-bottom: 12px;
  color: var(--text);
}
.montage-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.montage-total { font-weight: 500; color: var(--primary); font-size: 0.85rem; }
.montage-segments {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
}
.montage-segments li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.montage-seg-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.montage-seg-info { flex: 1; min-width: 0; }
.montage-seg-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.montage-seg-time { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.montage-seg-actions { display: flex; gap: 2px; flex-shrink: 0; }
.montage-empty-box {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.5;
}
.montage-empty-box p + p { margin-top: 6px; }
.montage-step-save .trim-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.trim-status {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow);
  transition: opacity 0.25s;
}
.toast.is-error { background: var(--danger); }

@media (max-width: 720px) {
  .yt-form { grid-template-columns: 1fr; }
  .upload-options { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
  .video-grid { grid-template-columns: 1fr; }
  .montage-modes { grid-template-columns: 1fr; }
  .montage-time-row { grid-template-columns: 1fr; }
}
