/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --success: #3fb950;
  --danger: #f85149;
  --danger-hover: #ff6b63;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────────── */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px;
}

/* ── Header ────────────────────────────────────────────── */
header { margin-bottom: 40px; text-align: center; }

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.subtitle {
  color: var(--text-dim);
  text-align: center;
  margin-top: -0.75rem;
}

/* ── Result links ── */
.result-links {
  max-width: 600px;
  margin: 0 auto;
}

.result-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
}

.result-name {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-processing {
  font-size: 0.8rem;
  color: var(--accent);
  margin-left: 0.5rem;
  animation: processing-pulse 2s ease-in-out infinite;
  display: inline-block;
}

@keyframes processing-pulse {
  0%, 100% { width: 30%; opacity: 0.6; }
  50% { width: 60%; opacity: 1; }
}

.result-error-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.error-name {
  color: var(--text);
  font-weight: 600;
}

.error-msg {
  color: #e74c3c;
}

nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  transition: all 0.15s;
  border: 1px solid transparent;
}

nav a:hover { color: var(--text); background: var(--surface-hover); }
nav a.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  border-color: rgba(88, 166, 255, 0.2);
}

/* ── Upload Zone ───────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface);
}

.upload-zone:hover { border-color: var(--accent); background: var(--surface-hover); }
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
  transform: scale(1.01);
}

.upload-icon { font-size: 3rem; margin-bottom: 12px; }

.upload-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.upload-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Progress ──────────────────────────────────────────── */
.upload-progress { padding: 40px 20px; }

.progress-bar {
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-text {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ── Result ────────────────────────────────────────────── */
.upload-result, .upload-error { padding: 40px 20px; text-align: center; }
.result-icon { font-size: 2.5rem; margin-bottom: 8px; }
.result-text { font-size: 1.1rem; font-weight: 500; margin-bottom: 16px; }

.result-link input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.85rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  outline: none;
}

.result-link input:focus { border-color: var(--accent); }

.user-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.user-link:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

.copy-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.copy-btn:hover { background: var(--accent-hover); }

.error-text { color: var(--danger); font-size: 0.95rem; margin-bottom: 16px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn-secondary {
  padding: 8px 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover { background: var(--surface-hover); border-color: var(--text-dim); }

.btn-primary {
  display: inline-block;
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  padding: 8px 20px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover { background: rgba(248, 81, 73, 0.1); }

/* ── Video Player ──────────────────────────────────────── */
.video-player-wrapper {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.video-player {
  width: 100%;
  display: block;
  max-height: 75vh;
}

.video-details { margin-bottom: 24px; }

.video-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
  word-break: break-word;
}

.video-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ── Share Section ─────────────────────────────────────── */
.share-section { margin-bottom: 32px; }

.share-section label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-dim);
}

.share-link-row {
  display: flex;
  gap: 8px;
}

.share-link-row input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.85rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  outline: none;
}

.share-link-row input:focus { border-color: var(--accent); }

.share-hint {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ── Download Section ────────────────────────────────── */
.download-section {
  padding: 16px 0;
}

.btn-download {
  display: inline-block;
  padding: 10px 24px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.btn-download:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-edit-link {
  display: inline-block;
  padding: 10px 24px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  margin-left: 8px;
}

.btn-edit-link:hover {
  background: rgba(88, 166, 255, 0.1);
}

.trim-hint {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

/* ── Delete Section ────────────────────────────────────── */
.delete-section { padding-top: 24px; border-top: 1px solid var(--border); }
.delete-hint { font-size: 0.8rem; margin-top: 6px; color: var(--text-dim); }

/* ── Browse Grid ───────────────────────────────────────── */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.video-card {
  display: block;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
}

.video-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.card-thumb {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
}

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

.card-no-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 2rem;
}

.card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.8);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.card-info { padding: 10px 12px 12px; }

.card-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-state p { font-size: 1.3rem; margin-bottom: 8px; }
.empty-state .subtitle { font-size: 0.95rem; }
.empty-state .btn-primary { margin-top: 16px; }

/* ── Hidden ────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Auth ────────────────────────────────────────────── */
.auth-form {
  max-width: 400px;
  margin: 0 auto;
  padding: 24px;
  background: #1a1a2e;
  border-radius: 12px;
  border: 1px solid #2a2a3e;
}
.auth-form form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-form label {
  font-size: 0.85rem;
  color: #888;
  margin-top: 4px;
}
.auth-form input {
  background: #0f0f1a;
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  padding: 12px;
  color: #e0e0e0;
  font-size: 1rem;
}
.auth-form input:focus {
  outline: none;
  border-color: #7c5cbf;
}
.auth-form .btn-primary {
  margin-top: 8px;
  width: 100%;
}
.auth-error {
  background: #3a1a1a;
  border: 1px solid #5c2a2a;
  border-radius: 8px;
  padding: 10px 14px;
  color: #ff6b6b;
  font-size: 0.9rem;
  text-align: center;
}
.setup-info {
  text-align: center;
  color: #aaa;
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.5;
}
.field-hint { font-size: 0.75rem; color: #666; margin: -4px 0 0; }

/* ── User management ───────────────────────────────── */
.user-list-section,
.create-user-section {
  margin-bottom: 32px;
}
.user-list-section h2,
.create-user-section h2 {
  font-size: 1.1rem;
  color: #ccc;
  margin-bottom: 12px;
}
.user-table {
  width: 100%;
  border-collapse: collapse;
}
.user-table th,
.user-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #2a2a3e;
  font-size: 0.9rem;
}
.user-table th {
  color: #666;
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.user-table td {
  color: #ccc;
}
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin { background: #2a1a3e; color: #b388ff; border: 1px solid #4a2a6e; }
.role-friend { background: #1a2e1a; color: #69f0ae; border: 1px solid #2a4e2a; }
.you-badge {
  font-size: 0.75rem;
  color: #666;
  font-style: italic;
}
.btn-small-danger {
  background: none;
  border: 1px solid #5c2a2a;
  color: #ff6b6b;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-small-danger:hover {
  background: #3a1a1a;
}
.create-user-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
}
.create-user-form label {
  font-size: 0.85rem;
  color: #888;
}
.create-user-form input {
  background: #0f0f1a;
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  padding: 10px 12px;
  color: #e0e0e0;
  font-size: 0.95rem;
}
.create-user-form input:focus {
  outline: none;
  border-color: #7c5cbf;
}

/* ── Nav right-aligned items ────────────────────────── */
.nav-right {
  margin-left: auto;
  color: #888 !important;
  font-size: 0.85rem;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 600px) {
  .container { padding: 20px 12px; }
  .video-grid { grid-template-columns: 1fr; }
  .result-link { flex-direction: column; }
  .share-link-row { flex-direction: column; }
  .video-meta { gap: 10px; }
}

/* ── Edit button (upload results) ───────────────────── */
.btn-edit {
  display: inline-block;
  padding: 10px 16px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-edit:hover {
  background: rgba(88, 166, 255, 0.1);
}

/* ── Edit page ──────────────────────────────────────── */
.edit-layout {
  max-width: 720px;
  margin: 0 auto;
}

.edit-preview {
  margin-bottom: 24px;
}

.edit-preview .video-player {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 60vh;
}

/* Trim controls */
.trim-controls {
  margin-top: 16px;
}

.trim-times {
  display: flex;
  gap: 20px;
}

.trim-field {
  flex: 1;
}

.trim-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trim-input-row {
  display: flex;
  gap: 6px;
}

.trim-input-row input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  outline: none;
}

.trim-input-row input:focus {
  border-color: var(--accent);
}

.btn-small {
  padding: 10px 14px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-small:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

/* Edit form section */
.edit-form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

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

.form-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.title-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.title-input:focus {
  border-color: var(--accent);
}

.edit-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

@media (max-width: 600px) {
  .trim-times {
    flex-direction: column;
    gap: 12px;
  }
  .edit-actions {
    flex-direction: column-reverse;
  }
  .edit-actions .btn-primary,
  .edit-actions .btn-secondary {
    width: 100%;
    text-align: center;
  }
}
