/* ============================================================
   Vidvisual Lite — style.css  (faithful homepage rebuild)
   1. Reset  2. Themes  3. Base  4. App bar  5. Drawer
   6. Chips  7. Grid & Card  8. Add dialog  9. Modal
   10. Toast  11. How-to-use  12. Media queries
   ============================================================ */

/* 1. Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }
.overlay-hidden { display: none !important; }

/* 2. Themes — light mirrors original ThemeData.light, dark ThemeData.dark */
:root {
  --bg: #ffffff;
  --appbar-bg: #ffffff;
  --text: #000000;
  --text-muted: #606060;
  --surface: #f2f2f2;
  --border: #e5e5e5;
  --chip-bg: #f2f2f2;
  --chip-active-bg: #0f0f0f;
  --chip-active-text: #ffffff;
  --primary-btn-bg: #0f0f0f;
  --primary-btn-text: #ffffff;
  --badge-bg: rgba(0, 0, 0, 0.7);
  --scrim: rgba(0, 0, 0, 0.45);
  --shadow: rgba(0, 0, 0, 0.12);
}
[data-theme="dark"] {
  --bg: #121212;
  --appbar-bg: #212121;
  --text: #f1f1f1;
  --text-muted: #aaaaaa;
  --surface: #272727;
  --border: #303030;
  --chip-bg: #272727;
  --chip-active-bg: #f1f1f1;
  --chip-active-text: #0f0f0f;
  --primary-btn-bg: #f1f1f1;
  --primary-btn-text: #0f0f0f;
  --badge-bg: rgba(0, 0, 0, 0.7);
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow: rgba(0, 0, 0, 0.5);
}

html { scroll-behavior: smooth; }

/* 3. Base */
/* YouTube's UI font is Roboto (bundled locally, latin subset).
   YouTube Sans is proprietary and used only for branding, so Roboto is correct here. */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/roboto-400-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/roboto-500-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/roboto-700-latin.woff2') format('woff2');
}
body {
  font-family: "Roboto", "Arial", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid #3ea6ff;
  outline-offset: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--text);
  transition: background-color 0.15s ease;
}
.icon-btn:hover { background: var(--surface); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: background-color 0.15s ease;
}
.btn:hover { filter: brightness(0.96); }
.btn--primary { background: var(--primary-btn-bg); color: var(--primary-btn-text); }
.btn--primary:hover { opacity: 0.88; filter: none; }

[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* 4. App bar */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 12px;
  background: var(--appbar-bg);
}
.appbar__left { display: flex; align-items: center; gap: 4px; }
.appbar__brand img {
  width: 92px;
  height: auto;
  object-fit: contain;
}
.appbar__actions { display: flex; align-items: center; gap: 2px; }

/* 5. Drawer */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--scrim);
  animation: fadeIn 0.2s ease;
}
.scrim--hidden { display: none; }
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  width: 280px;
  background: var(--bg);
  box-shadow: 4px 0 16px var(--shadow);
  transform: translateX(0);
  transition: transform 0.25s ease;
  overflow-y: auto;
}
.drawer--closed { transform: translateX(-105%); box-shadow: none; }
.drawer__header {
  border-bottom: 1px solid var(--border);
  padding: 20px 16px 16px;
}
.drawer__logo { width: 80px; height: 80px; object-fit: contain; margin-bottom: 10px; }
.drawer__title { font-size: 25px; font-weight: bold; }
.drawer__list { list-style: none; padding: 8px 0; }
.drawer__item {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 13px 24px;
  font-size: 14px;
  text-align: left;
  color: var(--text);
}
.drawer__item:hover { background: var(--surface); }

/* 6. Chips */
.chips {
  position: sticky;
  top: 56px;
  z-index: 40;
  background: var(--bg);
  padding: 10px 15px;
}
.chips__scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch; /* momentum scrolling on iOS */
  overscroll-behavior-x: contain;    /* don't hijack page gestures */
  touch-action: pan-x pan-y;         /* allow both horizontal chip swipe + vertical page scroll from this area */
  padding-bottom: 2px;
}
.chips__scroll::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 9px;
  background: var(--chip-bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.chip:hover { filter: brightness(0.95); }
.chip--active {
  background: var(--chip-active-bg);
  color: var(--chip-active-text);
}

/* 7. Grid & Card — mirrors GridView.builder (childAspectRatio 16/11) */
.main {
  padding: 20px 15px 60px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}
.card-wrap { position: relative; }

/* Ad slot (pinned grid position #1) */
.ad-card {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-label {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 2;
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 4px;
}
.ad-ph-text {
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: .04em;
}

/* House ad — HTMLive promo styled like a video card */
.ad-promo {
  display: block;
  color: inherit;
}
.ad-promo__media {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.ad-promo__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s ease;
}
.ad-promo:hover .ad-promo__media img { transform: scale(1.04); }
.ad-promo__badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ad-promo__badge::before {
  content: '\25B6';
  font-size: 9px;
  color: #34a853;
}
.ad-promo__avatar {
  background: linear-gradient(135deg, var(--red), var(--red-2)) !important;
  color: #fff !important;
  font-weight: 700;
}
.ad-promo__cta {
  display: inline-block;
  margin-top: 7px;
  padding: 5px 13px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--red), var(--red-2));
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
}
.ad-promo:hover .ad-promo__cta { transform: scale(1.05); }

.card { cursor: pointer; animation: cardIn 0.28s ease both; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.card__media {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: grey;
}
.card__media img { width: 100%; height: 100%; object-fit: cover; }
.card__duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px;
  background: var(--badge-bg);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.2;
}
.card__body {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding-top: 8px;
}
.card__avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}
.card__avatar img { width: 100%; height: 100%; object-fit: cover; }
.card__avatar--lg { width: 44px; height: 44px; font-size: 19px; position: relative; }
.card__text { min-width: 0; flex: 1; }
.card__title {
  font-size: 14px;
  font-weight: bold;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__channel { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.card__meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card__more {
  flex-shrink: 0;
  align-self: flex-start;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.card__more:hover { background: var(--surface); color: var(--text); }
.card__menu {
  position: absolute;
  right: 0;
  top: 36px;
  z-index: 30;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
  overflow: hidden;
}
.card__menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  font-size: 14px;
}
.card__menu-item:hover { background: var(--surface); }
.card__menu-item--danger { color: #e53935; }

/* 8. Add New Video dialog (mirrors Flutter AlertDialog) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: var(--scrim);
  overflow-y: auto;
  animation: fadeIn 0.18s ease;
}
.overlay--hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  width: 100%;
  max-width: 380px;
  background: var(--bg);
  border-radius: 8px;
  box-shadow: 0 16px 48px var(--shadow);
  padding: 22px 22px 14px;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.dialog__title { font-size: 19px; font-weight: 600; margin-bottom: 18px; }
#addForm { display: flex; flex-direction: column; gap: 12px; }
#addForm input[type="text"], #addForm select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 6px;
  border: 1px solid var(--text-muted);
  background: transparent;
  color: var(--text);
}
#addForm select option { background: var(--bg); color: var(--text); }
#addForm input[type="text"]::placeholder { color: var(--text-muted); }
#addForm input[type="text"]:focus, #addForm select:focus {
  outline: none;
  border-color: var(--text);
  border-width: 2px;
  padding: 10px 12px;
}
.grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  padding: 48px 0;
}
.dialog__logo-btn {
  justify-content: center;
  border: 1px solid var(--border);
}
.dialog__logo-done {
  color: #2e7d32;
  font-size: 13.5px;
  text-align: center;
}
.dialog__warning {
  color: #e53935;
  font-size: 13px;
  text-align: center;
}
.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding-top: 10px;
}
.dialog__foot .btn { background: transparent; }
.dialog__foot .btn:hover { background: var(--surface); }
.dialog__foot .btn--primary {
  background: var(--primary-btn-bg);
  color: var(--primary-btn-text);
}
.dialog__foot .btn--primary:hover { background: var(--primary-btn-bg); opacity: 0.88; filter: none; }

/* 9. Preview modal — studio */
.modal {
  position: relative;
  width: 100%;
  max-width: 960px;
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 48px var(--shadow);
  animation: slideUp 0.2s ease;
}
.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  background: var(--badge-bg);
  color: #fff;
}

/* F6/F7 stage + frames */
.modal__stage {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 20px 0;
}
.pv-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  transition: width 0.25s ease;
  flex-shrink: 0;
}
.modal__stage[data-size="desktop"] .pv-frame { width: 100%; max-width: 854px; }
.modal__stage[data-size="mobile"] .pv-frame { width: 402px; }
.modal__stage[data-size="sidebar"] .pv-frame { width: 168px; }
.pv-frame--light { background: #fff; }
.pv-frame--dark { background: #181818; }
.pv-frame img { width: 100%; height: 100%; object-fit: contain; }

/* F10 safe-zone overlay (duration badge region, bottom-right) */
.safezone {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 26%;
  height: 26%;
  border: 2px dashed #ff0000;
  background: rgba(255, 0, 0, 0.14);
  pointer-events: none;
}
.safezone span {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.safezone--hidden { display: none; }

/* toolbar */
.modal__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 4px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg__btn {
  padding: 7px 14px;
  font-size: 13px;
  background: transparent;
  color: var(--text);
}
.seg__btn--active { background: var(--primary-btn-bg); color: var(--primary-btn-text); }
.tool-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}
.tool-btn { padding: 7px 14px; font-size: 13px; }
.readability { font-size: 13.5px; font-weight: 500; }
.readability--good { color: #2e7d32; }
.readability--ok { color: #e6a700; }
.readability--bad { color: #e53935; }

.modal__info {
  display: flex;
  gap: 14px;
  padding: 14px 20px 20px;
  align-items: flex-start;
}
.modal__title { font-size: 19px; font-weight: 600; line-height: 1.3; }
.modal__channel { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* F1 compare overlay */
.compare { max-width: 1100px; }
.compare__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  padding: 18px 20px 22px;
}
.compare__cell img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
}
.compare__cell h3 { font-size: 15px; margin-top: 10px; }
.compare__cell p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* F1 selection bar + card check */
.select-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 32px var(--shadow);
}
.select-bar--hidden { display: none; }
.select-bar__count { font-size: 14px; font-weight: 500; }
.card.selected { outline: 3px solid #ff0000; outline-offset: 3px; border-radius: 10px; }
.card__check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ff0000;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* F2 drag states */
.card.dragging { opacity: 0.45; }
.card.drop-target { outline: 2px dashed var(--text-muted); outline-offset: 4px; }

/* F9 competitor thumbnails */
.competitors {
  margin-bottom: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.competitors__title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.competitors__add {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.competitors__add input {
  flex: 1;
  padding: 10px 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  min-width: 0;
}
.competitors__add input:focus { outline: none; border-color: var(--text); }
.competitors__row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-top: 12px;
}
.competitor {
  position: relative;
  flex-shrink: 0;
  width: 240px;
}
.competitor img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface);
}
.competitor.broken {
  width: auto;
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 6px 0;
}
.competitor.broken img { display: none; }
.competitor__del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  background: var(--badge-bg);
  color: #fff;
  font-size: 15px;
}

/* 10. Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 200;
  padding: 12px 20px;
  border-radius: 8px;
  background: var(--primary-btn-bg);
  color: var(--primary-btn-text);
  font-size: 14px;
  box-shadow: 0 8px 24px var(--shadow);
  animation: toastIn 0.2s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast--hidden { display: none; }
.toast__action {
  margin-left: 14px;
  padding: 4px 12px;
  border-radius: 6px;
  background: var(--accent, #ff0000);
  background: #ff0000;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}
.dialog__bulk {
  font-size: 13px;
  color: var(--text-muted);
  margin: -8px 0 10px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 12. Media queries — identical breakpoints to _calculateCrossAxisCount */
/* F9b: grid density (comfy default = 3/2/1) */
.grid[data-density="cozy"] { grid-template-columns: repeat(4, 1fr); gap: 14px 12px; }
.grid[data-density="compact"] { grid-template-columns: repeat(5, 1fr); gap: 12px 10px; }
@media (max-width: 1199px) {
  .grid[data-density="cozy"] { grid-template-columns: repeat(3, 1fr); }
  .grid[data-density="compact"] { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 799px) {
  .grid[data-density="cozy"] { grid-template-columns: repeat(2, 1fr); }
  .grid[data-density="compact"] { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1199px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 799px) {
  .grid { grid-template-columns: 1fr; }
  .appbar__brand img { width: 76px; }
}
