:root {
  --bg: #ffffff;
  --bg-2: #f2f2f2;
  --bg-3: #e5e5e5;
  --bg-hover: #e5e5e5;
  --text: #0f0f0f;
  --text-2: #606060;
  --border: #d3d3d3;
  --accent: #ff0000;
  --blue: #065fd4;
  --chip-active-bg: #0f0f0f;
  --chip-active-text: #ffffff;
  --shadow: 0 4px 32px rgba(0, 0, 0, .12);
  --topbar-h: 56px;
  --sidebar-w: 240px;
}
:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-2: #272727;
  --bg-3: #3f3f3f;
  --bg-hover: #3f3f3f;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --border: #303030;
  --blue: #3ea6ff;
  --chip-active-bg: #f1f1f1;
  --chip-active-text: #0f0f0f;
  --shadow: 0 4px 32px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
svg { fill: currentColor; }

/* ---------- Верхня панель ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px; background: var(--bg);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--bg-2); }
.icon-btn svg { width: 24px; height: 24px; }
.logo { display: flex; align-items: center; gap: 4px; padding: 0 8px; font-weight: 700; font-size: 20px; letter-spacing: -1px; }
.logo svg { width: 30px; height: 21px; }

.search { flex: 0 1 640px; display: flex; height: 40px; margin: 0 auto; }
.search input {
  flex: 1; min-width: 0; padding: 0 16px; border: 1px solid var(--border); border-right: 0;
  border-radius: 40px 0 0 40px; background: var(--bg); outline: none; font-size: 16px;
}
.search input:focus { border-color: var(--blue); }
.search button {
  width: 64px; border: 1px solid var(--border); border-radius: 0 40px 40px 0;
  background: var(--bg-2); cursor: pointer; display: grid; place-items: center;
}
.search button svg { width: 22px; height: 22px; }

.create-btn {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 16px 0 10px;
  border-radius: 18px; background: var(--bg-2); font-weight: 500;
}
.create-btn:hover { background: var(--bg-3); }
.create-btn svg { width: 24px; height: 24px; }

/* ---------- Бокове меню ---------- */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 20;
  padding: 12px; overflow-y: auto; background: var(--bg);
}
.nav-item {
  display: flex; align-items: center; gap: 24px; height: 40px; padding: 0 12px;
  border-radius: 10px; font-size: 14px;
}
.nav-item:hover { background: var(--bg-2); }
.nav-item.active { background: var(--bg-2); font-weight: 500; }
.nav-item svg { width: 24px; height: 24px; flex-shrink: 0; }
.sidebar hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.sidebar-backdrop { display: none; }

body.mini .sidebar { width: 72px; padding: 4px; }
body.mini .nav-item { flex-direction: column; justify-content: center; gap: 6px; height: 74px; padding: 0; font-size: 10px; }
body.mini .sidebar hr { display: none; }
body.mini main { margin-left: 72px; }

main {
  margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 24px) 24px 40px;
  min-height: 100vh;
}

/* На сторінці перегляду меню ховається, як на YouTube */
body.watching .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
body.watching.menu-open .sidebar { transform: none; }
body.watching main { margin-left: 0; }
body.watching.menu-open .sidebar-backdrop,
body.menu-open.narrow .sidebar-backdrop {
  display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .5);
}

/* ---------- Чіпи-фільтри ---------- */
.chips { display: flex; gap: 12px; margin-bottom: 24px; overflow-x: auto; }
.chip {
  padding: 6px 12px; border: 0; border-radius: 8px; background: var(--bg-2);
  font-weight: 500; white-space: nowrap; cursor: pointer;
}
.chip:hover { background: var(--bg-3); }
.chip.active { background: var(--chip-active-bg); color: var(--chip-active-text); }

/* ---------- Сітка відео ---------- */
.grid {
  display: grid; gap: 40px 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.card { display: block; cursor: pointer; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden;
  background: var(--bg-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.card:hover .thumb { border-radius: 0; transition: border-radius .2s; }
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-2); }
.thumb .placeholder svg { width: 48px; height: 48px; }
.duration {
  position: absolute; right: 8px; bottom: 8px; padding: 1px 4px; border-radius: 4px;
  background: rgba(0, 0, 0, .8); color: #fff; font-size: 12px; font-weight: 500;
}
.card-info { display: flex; gap: 12px; margin-top: 12px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: linear-gradient(135deg, #ff4e50, #f9d423); color: #fff; font-weight: 700; font-size: 16px;
}
.avatar.lg { width: 40px; height: 40px; }
.card-title {
  margin: 0 0 4px; font-size: 16px; font-weight: 500; line-height: 22px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { color: var(--text-2); font-size: 14px; line-height: 20px; }

.empty { text-align: center; padding: 80px 20px; color: var(--text-2); }
.empty svg { width: 120px; height: 120px; opacity: .4; }
.empty h2 { color: var(--text); font-weight: 500; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border: 0; border-radius: 18px; cursor: pointer;
  background: var(--bg-2); font-weight: 500; font-size: 14px;
}
.btn:hover { background: var(--bg-3); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: .85; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.danger { color: #e53935; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 22px; height: 22px; }

/* ---------- Сторінка перегляду ---------- */
.watch { display: flex; gap: 24px; max-width: 1750px; margin: 0 auto; }
.watch-main { flex: 1; min-width: 0; }
.player {
  width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - 170px);
  background: #000; border-radius: 12px; display: block;
}
.watch-title { font-size: 20px; font-weight: 700; margin: 12px 0 8px; line-height: 28px; word-wrap: break-word; }
.watch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.channel { display: flex; align-items: center; gap: 12px; }
.channel-name { font-weight: 500; font-size: 16px; }
.channel-sub { color: var(--text-2); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.liked { background: var(--text); color: var(--bg); }

.description {
  margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bg-2);
  white-space: pre-wrap; word-wrap: break-word; line-height: 20px;
}
.description b { display: block; margin-bottom: 4px; }
.description.collapsed .desc-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.desc-toggle { margin-top: 6px; font-weight: 500; cursor: pointer; background: none; border: 0; padding: 0; }

.comments h3 { font-size: 20px; margin: 24px 0; }
.comment-form { display: flex; gap: 16px; margin-bottom: 32px; }
.comment-form .fields { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.line-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent;
  padding: 4px 0; outline: none; resize: none;
}
.line-input:focus { border-bottom: 2px solid var(--text); }
.comment-form .form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.comment { display: flex; gap: 16px; margin-bottom: 20px; }
.comment-head { font-size: 13px; font-weight: 500; margin-bottom: 2px; }
.comment-head span { color: var(--text-2); font-weight: 400; margin-left: 4px; }
.comment-text { white-space: pre-wrap; word-wrap: break-word; line-height: 20px; }

.related { width: 402px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.related .card { display: flex; gap: 8px; }
.related .thumb { width: 168px; flex-shrink: 0; border-radius: 8px; }
.related .card-title { font-size: 14px; line-height: 20px; }
.related .meta { font-size: 12px; line-height: 18px; }

/* ---------- Сторінка завантаження ---------- */
.upload-page { max-width: 960px; margin: 0 auto; }
.upload-page h1 { font-size: 24px; font-weight: 700; }
.panel { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 24px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 16px; padding: 56px 24px; text-align: center; cursor: pointer;
}
.dropzone.over { border-color: var(--blue); background: var(--bg-2); }
.dropzone .circle {
  width: 136px; height: 136px; border-radius: 50%; background: var(--bg-2); margin: 0 auto 24px;
  display: grid; place-items: center; color: var(--text-2);
}
.dropzone .circle svg { width: 64px; height: 64px; }
.dropzone p { margin: 4px 0; }
.upload-form { display: grid; grid-template-columns: 1fr 320px; gap: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.box-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; outline: none;
}
.box-input:focus { border-color: var(--blue); }
textarea.box-input { min-height: 140px; resize: vertical; }
.preview-card { background: var(--bg-2); border-radius: 12px; overflow: hidden; }
.preview-card video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; }
.preview-card .info { padding: 12px; font-size: 13px; color: var(--text-2); word-break: break-all; }
.thumb-preview { margin-top: 12px; }
.thumb-preview img { width: 100%; border-radius: 8px; display: block; }
.progress { height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; margin: 16px 0 6px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { color: var(--text-2); font-size: 13px; }
.form-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.password-box { max-width: 420px; margin: 40px auto; text-align: center; }
.password-box p { color: var(--text-2); }

/* ---------- Повідомлення ---------- */
.toast {
  position: fixed; left: 24px; bottom: 24px; z-index: 50; padding: 12px 20px; border-radius: 8px;
  background: #282828; color: #fff; opacity: 0; transform: translateY(20px); transition: .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

.skeleton .thumb, .skeleton .avatar, .skeleton .bar { background: var(--bg-2); }
.skeleton .bar { height: 14px; border-radius: 4px; margin-bottom: 8px; }

/* ---------- Адаптивність ---------- */
@media (max-width: 1300px) {
  .watch { flex-direction: column; }
  .related { width: 100%; }
}
@media (max-width: 1100px) {
  main { margin-left: 72px; }
  .sidebar { width: 72px; padding: 4px; }
  .nav-item { flex-direction: column; justify-content: center; gap: 6px; height: 74px; padding: 0; font-size: 10px; }
  .sidebar hr { display: none; }
}
@media (max-width: 800px) {
  main, body.mini main { margin-left: 0; padding: calc(var(--topbar-h) + 12px) 12px 40px; }
  .sidebar, body.mini .sidebar { transform: translateX(-100%); transition: transform .2s; width: var(--sidebar-w); padding: 12px; box-shadow: var(--shadow); }
  .sidebar .nav-item, body.mini .sidebar .nav-item { flex-direction: row; justify-content: flex-start; gap: 24px; height: 40px; padding: 0 12px; font-size: 14px; }
  body.menu-open .sidebar { transform: none; }
  .create-btn span { display: none; }
  .create-btn { padding: 0 6px; }
  .logo span { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .search button { width: 48px; }
  .upload-form { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .player { border-radius: 0; }
  .related .thumb { width: 140px; }
}
