/* Bread & butter styling: plain CSS, flexbox/grid, desktop-first with
   mobile media queries at the bottom. No framework. */

:root {
  --bg: #f5f6f8;
  --card-bg: #fff;
  --text: #1b1e23;
  --muted: #6b7280;
  --border: #e2e4e9;
  --primary: #d64545;
  --primary-dark: #b93636;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* --- Header / nav --- */

.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
}

.brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.search-form {
  flex: 1;
  display: flex;
  max-width: 480px;
}

.search-form input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.95rem;
}

.search-form button {
  padding: 8px 14px;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
  flex-wrap: wrap;
  font-size: 0.92rem;
}

.nav-messages { position: relative; }

.badge {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  padding: 1px 6px;
  margin-left: 4px;
}

/* --- Layout --- */

.site-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 20px 0 40px;
}

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.flash-success { background: #e4f6e8; color: #1c7a37; }
.flash-error   { background: #fbe6e6; color: #a12626; }
.flash-info    { background: #e6f0fb; color: #1a4f8a; }

h1, h2, h3 { line-height: 1.25; }

/* --- Buttons / forms --- */

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #a12626; border-color: #a12626; color: #fff; }
.btn-small { padding: 4px 10px; font-size: 0.8rem; }

form.stacked label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 0.9rem; }
form.stacked input[type=text],
form.stacked input[type=email],
form.stacked input[type=password],
form.stacked input[type=file],
form.stacked textarea,
form.stacked select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
}
form.stacked textarea { min-height: 100px; resize: vertical; }
.field-hint { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }

.upload-progress {
  margin-top: 14px;
  height: 10px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.15s ease-out;
}
.field-error { color: #a12626; font-size: 0.85rem; margin-top: 3px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 480px;
}
.card-wide { max-width: 720px; }

/* --- Video grid --- */

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

.video-card { display: block; color: var(--text); }
.video-card:hover { text-decoration: none; }
.video-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius);
  background: #ddd;
}
.video-card-title {
  font-weight: 600;
  margin: 8px 0 2px;
  font-size: 0.98rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-card-meta { color: var(--muted); font-size: 0.82rem; }

/* --- Watch page --- */

.watch-video {
  width: 100%;
  max-height: 640px;
  background: #000;
  border-radius: var(--radius);
}

.watch-title { margin: 14px 0 4px; }
.watch-meta { color: var(--muted); font-size: 0.9rem; margin-bottom: 10px; }

.tag-list { margin: 6px 0 14px; }
.tag-pill {
  display: inline-block;
  background: #eef0f4;
  color: var(--text);
  border-radius: 14px;
  padding: 3px 12px;
  font-size: 0.82rem;
  margin: 0 6px 6px 0;
}

.rating-widget { display: flex; gap: 2px; font-size: 1.6rem; cursor: pointer; user-select: none; }
.rating-widget .star { color: #ccc; }
.rating-widget .star.filled { color: #f0a020; }
.rating-summary { color: var(--muted); font-size: 0.88rem; }

.comment { border-top: 1px solid var(--border); padding: 12px 0; }
.comment-author { font-weight: 600; margin-right: 6px; }
.comment-time { color: var(--muted); font-size: 0.8rem; }
.comment-body { margin-top: 4px; white-space: pre-wrap; }

.desc-box { white-space: pre-wrap; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }

/* --- Pagination --- */

.pagination { display: flex; gap: 6px; margin-top: 24px; justify-content: center; }
.pagination a, .pagination span {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Tables (admin) --- */

table.data-table { width: 100%; border-collapse: collapse; background: var(--card-bg); }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
table.data-table th { color: var(--muted); font-weight: 600; }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 22px; }
.stat-box .num { font-size: 1.8rem; font-weight: 700; }
.stat-box .label { color: var(--muted); font-size: 0.85rem; }

/* --- Modal (playlist add) --- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: var(--radius); padding: 20px;
  width: 90%; max-width: 380px; max-height: 80vh; overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.playlist-pick-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }

/* --- Messaging --- */

.conversation-list .conv-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.conv-snippet { color: var(--muted); font-size: 0.85rem; }
.conv-unread { font-weight: 700; }

.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.msg-bubble { max-width: 70%; padding: 10px 14px; border-radius: 12px; background: #eef0f4; }
.msg-mine { align-self: flex-end; background: var(--primary); color: #fff; }
.msg-time { font-size: 0.75rem; color: var(--muted); margin-top: 3px; }

/* --- Playlists --- */

.playlist-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.playlist-row .video-thumb { width: 120px; flex-shrink: 0; }
.playlist-row-info { flex: 1; }
.reorder-btns { display: flex; flex-direction: column; gap: 2px; }

/* --- 2FA --- */

.secret-box { font-family: monospace; letter-spacing: 2px; background: #eef0f4; padding: 10px; border-radius: var(--radius); word-break: break-all; }
.backup-codes { font-family: monospace; columns: 2; gap: 20px; }

/* --- Mobile --- */

@media (max-width: 768px) {
  .site-header-inner { flex-wrap: wrap; }
  .search-form { order: 3; width: 100%; max-width: none; }
  .main-nav { gap: 10px; font-size: 0.85rem; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .msg-bubble { max-width: 88%; }
  .playlist-row .video-thumb { width: 80px; }
  .backup-codes { columns: 1; }
}
