/* Loop - design system: light (white + purple) and dark (grays + fuchsia) */

:root {
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
  --transition: .2s ease;

  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: #ede9fe;
  --accent: #8b5cf6;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --success: #10b981;
  --success-soft: #d1fae5;
}

[data-theme="dark"] {
  --bg: #111827;
  --surface: #1f2937;
  --surface-2: #374151;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --border: #374151;
  --primary: #d946ef;
  --primary-hover: #c026d3;
  --primary-soft: #4a044e;
  --accent: #e879f9;
  --danger: #f87171;
  --danger-soft: #450a0a;
  --success: #34d399;
  --success-soft: #064e3b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

[x-cloak] { display: none !important; }

/* utilities */
.desktop-only { display: block; }
.mobile-only { display: none; }
.muted { color: var(--text-muted); font-size: .85rem; }

@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex; }
}

/* LOGIN */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 10% 20%, color-mix(in srgb, var(--primary) 12%, transparent) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, color-mix(in srgb, var(--accent) 10%, transparent) 0%, transparent 40%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
  position: relative;
}

.brand { display: flex; align-items: center; justify-content: center; gap: .75rem; margin-bottom: 1rem; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center; font-size: 1.1rem;
}
.brand h1 { margin: 0; font-size: 1.75rem; }
.login-lead { color: var(--text-muted); margin-bottom: 2rem; line-height: 1.5; }

.google-btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: .75rem;
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}
.google-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.google-btn svg { width: 20px; height: 20px; }

.theme-toggle {
  position: absolute; top: 1rem; right: 1rem;
  background: transparent; border: 1px solid var(--border);
  border-radius: 999px; width: 36px; height: 36px; cursor: pointer;
  display: grid; place-items: center; font-size: 1rem;
}

/* DASHBOARD SHELL */
.dashboard {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  min-height: 100vh;
}

.dashboard.collapsed {
  grid-template-columns: 80px 1fr;
}

@media (max-width: 768px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "topbar"
      "main"
      "appbar";
    padding-bottom: 72px;
  }
  .dashboard.collapsed {
    grid-template-columns: 1fr;
  }
}

/* TOPBAR */
.topbar {
  grid-area: topbar;
  position: sticky; top: 0; z-index: 30;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: center; gap: .75rem; }
.topbar-brand .logo { width: 32px; height: 32px; border-radius: 8px; font-size: .9rem; }
.app-name { font-weight: 700; font-size: 1.25rem; }

.topbar-user { display: flex; align-items: center; gap: .75rem; }

/* user dropdown */
.user-menu { position: relative; }
.avatar-btn {
  display: flex; align-items: center; gap: .35rem;
  background: transparent; border: none; cursor: pointer; padding: .25rem;
  border-radius: var(--radius);
}
.avatar-btn:hover { background: var(--surface-2); }
.avatar-btn .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.avatar-btn .caret { color: var(--text-muted); }

.dropdown {
  position: absolute; right: 0; top: calc(100% + .5rem);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .5rem;
  z-index: 60;
}
.dropdown-user {
  padding: .75rem .5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .5rem;
}
.dropdown-user strong {
  display: block; font-size: .9rem; margin-bottom: .15rem;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dropdown-user .muted { display: block; font-size: .8rem; }
.dropdown-item {
  width: 100%; text-align: left;
  background: transparent; border: none; border-radius: var(--radius-sm);
  padding: .65rem .5rem; color: var(--text);
  font: inherit; font-size: .9rem; cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: .75rem; }
.user-name { font-weight: 600; font-size: .9rem; }
.logout-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); padding: .35rem .75rem;
  border-radius: var(--radius-sm); font-size: .85rem; cursor: pointer;
}
.logout-btn:hover { border-color: var(--primary); color: var(--primary); }
.logout-btn.full { width: 100%; margin-top: 1rem; }

.icon-btn {
  background: transparent; border: none; color: var(--text);
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.menu-btn { display: none; }
.collapse-btn { display: none; }
.topbar .collapse-btn.desktop-only { display: grid; }

@media (max-width: 768px) {
  .menu-btn { display: grid; }
  .topbar .collapse-btn.desktop-only { display: none; }
}

/* SIDEBAR */
.sidebar {
  grid-area: sidebar;
  position: sticky; top: 64px; height: calc(100vh - 64px);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex; flex-direction: column;
  background: var(--surface);
  transition: padding var(--transition);
}

.dashboard.collapsed .sidebar { padding: 1rem .5rem; }

.nav-item {
  width: 100%; display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; border-radius: var(--radius);
  border: none; background: transparent; color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
  margin-bottom: .35rem;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item.record { color: var(--danger); }
.nav-item.record:hover { background: var(--danger-soft); }
.nav-item svg { flex-shrink: 0; }

.dashboard.collapsed .sidebar .nav-item { justify-content: center; padding: .75rem .25rem; }
.dashboard.collapsed .sidebar .nav-item span { display: none; }
.dashboard.collapsed .sidebar .sidebar-footer span { display: none; }
.dashboard.collapsed .sidebar .sidebar-footer::after { content: 'Lv0.1'; color: var(--text-muted); font-size: .7rem; }

.sidebar-footer { margin-top: auto; text-align: center; padding: 1rem 0; }

/* MOBILE MENU */
.mobile-menu {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.4);
  display: none;
  justify-content: flex-start;
}
.mobile-menu-panel {
  width: 280px; max-width: 80%;
  background: var(--surface);
  height: 100%;
  padding: 1rem;
  display: flex; flex-direction: column;
}
.mobile-menu-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.mobile-menu-user {
  display: flex; align-items: center; gap: .75rem;
  margin-top: auto; padding: 1rem 0; border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .mobile-menu { display: flex; }
}

/* MAIN */
.main-content {
  grid-area: main;
  padding: 1.5rem;
  overflow-y: auto;
}

.home-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem;
}
.home-header h2 { margin: 0; font-size: 1.5rem; }
.home-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.primary-btn {
  background: var(--primary); color: #fff; border: none;
  padding: .65rem 1.25rem; border-radius: var(--radius);
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .5rem;
  transition: background var(--transition), transform var(--transition);
}
.primary-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.primary-btn.small { padding: .45rem .9rem; font-size: .85rem; }
.primary-btn.full { width: 100%; justify-content: center; }
.primary-btn:disabled { opacity: .7; cursor: not-allowed; transform: none; }

.danger-btn {
  background: var(--danger); color: #fff; border: none;
  padding: .65rem 1.25rem; border-radius: var(--radius);
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .5rem;
  transition: background var(--transition), transform var(--transition);
}
.danger-btn:hover { background: #dc2626; transform: translateY(-1px); }
.danger-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.secondary-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: .65rem 1.25rem; border-radius: var(--radius);
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.secondary-btn:hover { background: var(--surface); }
.secondary-btn.full { width: 100%; }

.empty-state {
  text-align: center; padding: 4rem 1rem; color: var(--text-muted);
}
.empty-state p { margin-bottom: 1rem; }

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

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
}
.video-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.video-card.selected { outline: 2px solid var(--primary); outline-offset: -2px; }

.thumb {
  aspect-ratio: 16/9;
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--text-muted);
  position: relative;
  overflow: hidden;
}
.thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.thumb-placeholder {
  display: grid; place-items: center;
  width: 100%; height: 100%;
}

.play-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,.12);
  border: none; cursor: pointer; opacity: 0;
  transition: opacity var(--transition);
}
.video-card:hover .play-overlay { opacity: 1; }
.play-overlay svg { filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }

.edit-badge, .delete-badge {
  position: absolute; top: .5rem;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.9); color: var(--text);
  border: none; display: grid; place-items: center; cursor: pointer;
  opacity: 0; transition: opacity var(--transition);
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.edit-badge { right: .5rem; }
.delete-badge { right: 2.75rem; }
[data-theme="dark"] .edit-badge, [data-theme="dark"] .delete-badge { background: rgba(31,41,55,.9); color: var(--text); }
.video-card:hover .edit-badge, .video-card:hover .delete-badge { opacity: 1; }
.edit-badge:hover { color: var(--primary); }
.delete-badge:hover { color: var(--danger); }

.card-select {
  position: absolute; top: .5rem; left: .5rem; z-index: 5;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,.9);
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
[data-theme="dark"] .card-select { background: rgba(31,41,55,.9); }
.card-select input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.card-body { padding: 1rem; }
.card-body h3 { margin: 0 0 .5rem; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: .2rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--text-muted);
}
.st-READY .badge { background: var(--success-soft); color: var(--success); }
.st-FAILED .badge { background: var(--danger-soft); color: var(--danger); }
.st-DRIVE_UPLOADING .badge { background: var(--primary-soft); color: var(--primary); }
.st-UPLOADING .badge { background: #fef3c7; color: #b45309; }

.actions { display: flex; gap: .5rem; }
.text-btn {
  background: transparent; border: none; color: var(--primary);
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; padding: 0;
}
.text-btn.retry { color: var(--danger); }
.text-btn.danger { color: var(--danger); }

/* DRAWER */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.35);
}
.right-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(520px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 41;
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.right-drawer.open { transform: translateX(0); }

.drawer-header {
  height: 64px; padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0; font-size: 1.1rem; }

.drawer-body { padding: 1.25rem; overflow-y: auto; flex: 1; }

.preview-wrap {
  background: #000; border-radius: var(--radius-lg);
  overflow: hidden; margin-bottom: 1rem;
  aspect-ratio: 16/9;
  display: grid; place-items: center;
}
.preview-wrap canvas { width: 100%; height: 100%; object-fit: contain; }
.preview-placeholder {
  color: var(--text-muted); text-align: center; padding: 1rem;
}

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--primary-soft); color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem;
}

.error { color: var(--danger); font-weight: 600; margin-bottom: 1rem; }
.notice { color: var(--success); font-weight: 600; margin-bottom: 1rem; }

.options-panel {
  display: flex; flex-direction: column; gap: 1rem;
  margin-bottom: 1rem;
}
.option-group { display: flex; flex-direction: column; gap: .5rem; }
.option-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.toggle-row { display: flex; flex-wrap: wrap; gap: .5rem; }

.chip-check, .chip-radio {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem .75rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.chip-check:has(input:checked), .chip-radio:has(input:checked) {
  background: var(--primary-soft); border-color: var(--primary); color: var(--primary);
}
.chip-check input, .chip-radio input { display: none; }

.local-result {
  display: flex; flex-direction: column; gap: .75rem;
  margin-bottom: 1rem;
}
.local-result p { margin: 0; color: var(--text-muted); }

.recorder-controls {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem;
}
.record-btn, .stop-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  border: none; border-radius: var(--radius);
  padding: .75rem 1.25rem; font: inherit; font-weight: 700; cursor: pointer;
  color: #fff;
}
.record-btn { background: var(--danger); }
.record-btn:hover { background: #dc2626; }
.stop-btn { background: #374151; }
.stop-btn:hover { background: #1f2937; }
.record-btn .dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.stop-btn .square { width: 10px; height: 10px; background: #fff; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; }

.progress-wrap { margin-bottom: 1rem; }
progress { width: 100%; height: 6px; border-radius: 999px; overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--primary); }

/* MOBILE APP BAR */
.mobile-appbar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 64px; background: var(--surface);
  border-top: 1px solid var(--border);
  justify-content: space-around; align-items: center;
  z-index: 30; padding-bottom: env(safe-area-inset-bottom);
}
.appbar-item {
  flex: 1; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .25rem; background: transparent; border: none; color: var(--text-muted);
  font: inherit; font-size: .7rem; cursor: pointer;
}
.appbar-item.active { color: var(--primary); }
.appbar-item.record { color: var(--danger); }

@media (max-width: 768px) {
  .mobile-appbar { display: flex; }
  .main-content { padding-bottom: 1rem; }
  .home-header { flex-direction: column; align-items: flex-start; }
  .video-grid { grid-template-columns: 1fr; }
  .right-drawer { width: 100vw; }
  .play-overlay, .edit-badge { opacity: 1; }
}

/* MODALS */
.modal-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(640px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-header {
  height: 56px; padding: 0 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; }

.video-modal {
  width: min(960px, 100%);
}
.video-modal .modal-body {
  padding: 0;
  background: #000;
  display: grid; place-items: center;
}
.video-modal video {
  width: 100%; max-height: 70vh;
  display: block;
}

.edit-modal .field {
  display: flex; flex-direction: column; gap: .4rem;
  margin-bottom: 1rem;
}
.edit-modal .field span { font-size: .9rem; font-weight: 600; }
.edit-modal input[type="text"],
.edit-modal input[type="file"] {
  width: 100%; padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font: inherit;
}
.edit-modal input[type="text"]:focus {
  outline: 2px solid var(--primary-soft); border-color: var(--primary);
}
.cover-preview {
  aspect-ratio: 16/9; border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2); margin-bottom: 1rem;
}
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: .75rem;
}

/* WATCH PAGE */
.watch-page {
  min-height: 100vh;
  background: var(--bg);
}
.watch-topbar {
  height: 64px; padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.watch-topbar .brand { display: flex; align-items: center; gap: .75rem; margin: 0; }
.watch-topbar .logo { width: 32px; height: 32px; border-radius: 8px; font-size: .9rem; }
.watch-topbar .app-name { font-weight: 700; font-size: 1.25rem; }

.watch-container {
  max-width: 1100px; margin: 0 auto; padding: 2rem 1rem;
}
.watch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.watch-video-wrap {
  background: #000;
  aspect-ratio: 16/9;
  display: grid; place-items: center;
}
.watch-video-wrap video {
  width: 100%; height: 100%;
  max-height: 70vh;
  object-fit: contain;
}
.watch-info { padding: 1.5rem; }
.watch-info h1 { margin: 0 0 .5rem; font-size: 1.5rem; }
.watch-meta { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.watch-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

.password-gate {
  max-width: 420px; margin: 6rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.password-gate .logo { margin: 0 auto 1rem; }
.password-gate h2 { margin: 0 0 .5rem; }
.password-gate p { color: var(--text-muted); margin-bottom: 1.5rem; }
.password-gate input {
  width: 100%; padding: .75rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font: inherit;
  margin-bottom: 1rem;
}
.password-gate input:focus {
  outline: 2px solid var(--primary-soft); border-color: var(--primary);
}
.password-gate .error { margin-bottom: 1rem; }

.not-found {
  text-align: center; padding: 6rem 1rem; color: var(--text-muted);
}
.not-found h2 { color: var(--text); margin-bottom: .5rem; }
