:root {
  --bg: #0e0e10;
  --surface: #18181b;
  --surface2: #1f1f23;
  --surface3: #26262c;
  --border: #2d2d35;
  --accent: #EAB308;
  --accent-dark: #CA8A04;
  --accent-light: #FDE047;
  --text: #efeff1;
  --text-muted: #adadb8;
  --text-dim: #6c6c7c;
  --red: #eb0400;
  --green: #00c852;
  --chat-w: 340px;
  --header-h: 56px;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: 14px;
  border-radius: 6px;
  transition: background 0.15s, transform 0.1s;
}
button:active { transform: scale(0.97); }

input, textarea, select {
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  border-radius: 6px;
  padding: 8px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* === HEADER === */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  color: #22c55e;
  text-decoration: none;
  letter-spacing: -0.5px;
}
.logo:hover { text-decoration: none; color: #EAB308; }
.logo svg { width: 28px; height: 28px; fill: #EAB308; }

.header-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.header-search input {
  padding-left: 36px;
  background: var(--surface2);
}
.header-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: #c50300; }
.btn-green { background: var(--green); color: #000; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-menu {
  position: relative;
}
.user-menu-btn {
  background: none;
  border-radius: 50%;
  padding: 0;
  display: flex;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
  overflow: hidden;
  display: none;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  background: none;
  color: var(--text);
  font-size: 13px;
  border-radius: 0;
  text-decoration: none;
}
.user-dropdown a:hover, .user-dropdown button:hover {
  background: var(--surface3);
  text-decoration: none;
}
.user-dropdown .divider { height: 1px; background: var(--border); margin: 4px 0; }

/* === LAYOUT === */
.layout {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-section { margin-bottom: 24px; }
.sidebar-title {
  padding: 0 16px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.sidebar-channel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  text-decoration: none;
  color: var(--text-muted);
  transition: background 0.1s;
}
.sidebar-channel:hover { background: var(--surface2); text-decoration: none; color: var(--text); }
.sidebar-channel.live .channel-name { color: var(--text); }
.live-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.channel-info { flex: 1; min-width: 0; }
.channel-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-badge {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px;
  max-width: 100%;
}

/* === HOME PAGE === */
.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}
.page-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

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

.stream-card {
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s;
  cursor: pointer;
  text-decoration: none;
  display: block;
}
.stream-card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }

.stream-thumbnail {
  position: relative;
  aspect-ratio: 16/9;
  background: var(--surface2);
  overflow: hidden;
}
.stream-thumbnail img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.stream-thumbnail-placeholder {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: linear-gradient(135deg, var(--surface2), var(--surface3));
}
.live-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}
.viewer-count-badge {
  position: absolute;
  bottom: 8px; left: 8px;
  background: rgba(0,0,0,0.8);
  color: var(--text);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
}

.stream-card-body { padding: 12px; }
.stream-card-header { display: flex; align-items: flex-start; gap: 10px; }
.stream-card-info { flex: 1; min-width: 0; }
.stream-card-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  margin-bottom: 4px;
}
.stream-card-user { font-size: 12px; color: var(--text-muted); }
.stream-card-category {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--accent-light);
  background: rgba(234, 179, 8, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state h2 { font-size: 22px; margin-bottom: 8px; color: var(--text-muted); }
.empty-state p { margin-bottom: 20px; }

/* === CHANNEL PAGE === */
.channel-layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
  overflow: hidden;
}

.channel-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.video-wrapper {
  position: relative;
  background: #000;
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 70vh;
  flex-shrink: 0;
}

#video-player {
  width: 100%;
  height: 100%;
}

.offline-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  gap: 12px;
  color: var(--text-muted);
}
.offline-screen h2 { color: var(--text); font-size: 22px; }

.channel-info-bar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 14px;
}
.channel-avatar-lg {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}
.channel-details { flex: 1; }
.channel-display-name { font-size: 18px; font-weight: 700; }
.channel-stream-title { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.channel-stats { display: flex; gap: 16px; align-items: center; flex-shrink: 0; }
.stat-item { text-align: center; }
.stat-value { font-size: 16px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-dim); }

/* === CHAT === */
.chat-panel {
  width: var(--chat-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  padding: 4px 12px;
  line-height: 1.5;
  word-break: break-word;
  animation: msgIn 0.15s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg:hover { background: var(--surface2); }
.chat-msg-user {
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.chat-msg-user:hover { text-decoration: underline; }
.chat-msg-text { font-size: 13px; color: var(--text); }

.chat-system {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.chat-input-area {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-wrap { position: relative; }
.chat-input {
  padding-right: 44px;
  resize: none;
  height: 36px;
  line-height: 20px;
}
.chat-send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.chat-send-btn:hover { background: var(--accent-dark); }

.chat-login-prompt {
  padding: 12px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.chat-login-prompt a { color: var(--accent-light); }

/* === AUTH PAGES === */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo h1 { font-size: 28px; font-weight: 800; color: var(--accent); }
.auth-logo p { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.auth-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: 6px;
  margin-top: 8px;
}
.auth-submit:hover { background: var(--accent-dark); }

.auth-switch {
  text-align: center;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-switch a { color: var(--accent-light); }

.error-msg {
  background: rgba(235, 4, 0, 0.15);
  border: 1px solid rgba(235, 4, 0, 0.3);
  color: #ff6b6b;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.show { display: block; }
.success-msg {
  background: rgba(0, 200, 82, 0.15);
  border: 1px solid rgba(0, 200, 82, 0.3);
  color: var(--green);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.success-msg.show { display: block; }

/* === DASHBOARD === */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 900px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-full { grid-column: 1 / -1; }

.stream-key-box {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.stream-key-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  filter: blur(4px);
  transition: filter 0.2s;
}
.stream-key-value.revealed { filter: none; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-box {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.stat-box .value { font-size: 28px; font-weight: 800; color: var(--accent-light); }
.stat-box .label { font-size: 11px; color: var(--text-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

.rtmp-info {
  background: var(--surface3);
  border-radius: 8px;
  padding: 14px;
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 2;
}
.rtmp-label { color: var(--text-dim); font-size: 11px; }

/* === NOTIFICATION TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  font-size: 14px;
  z-index: 999;
  animation: toastIn 0.3s ease;
  max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--red); color: #ff6b6b; }
.toast.success { border-color: var(--green); color: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* === SEARCH AUTOCOMPLETE === */
.header-search { position: relative; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: none;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.search-dropdown.open { display: block; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--surface3); text-decoration: none; }
.search-result-info { flex: 1; min-width: 0; }
.search-result-name { font-size: 13px; font-weight: 600; }
.search-result-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === CATEGORY FILTER BAR === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header .page-title { margin-bottom: 0; }

.categories-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.categories-bar::-webkit-scrollbar { display: none; }

.cat-btn {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}
.cat-btn:hover { background: var(--surface3); color: var(--text); border-color: var(--text-dim); }
.cat-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* === STREAM CARDS — THUMBNAILS === */
.stream-thumbnail .thumb-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.stream-thumbnail.no-thumb .thumb-img { display: none; }
.stream-thumbnail:not(.no-thumb) .stream-thumbnail-placeholder { display: none; }

.uptime-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.75);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
}

/* === CHAT IMPROVEMENTS === */
.chat-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-right: 6px;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
}

.chat-mention {
  color: var(--accent-light);
  font-weight: 600;
}
.chat-mention-me {
  background: rgba(6, 182, 212, 0.2);
  border-radius: 3px;
  padding: 0 3px;
}
.chat-mention-row {
  background: rgba(234, 179, 8, 0.08);
  border-left: 2px solid var(--accent);
}

.chat-char-counter {
  font-size: 11px;
  color: var(--text-dim);
  transition: color 0.15s;
}
.chat-char-counter.near-limit { color: #ffa94d; }
.chat-char-counter.at-limit { color: var(--red); }

/* === DASHBOARD IMPROVEMENTS === */
.rtmp-info { line-height: 1.8; }

/* === RESPONSIVE === */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .channel-layout { flex-direction: column; }
  .chat-panel { width: 100%; height: 400px; border-left: none; border-top: 1px solid var(--border); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .streams-grid { grid-template-columns: 1fr; }
  .header-search { display: none; }
}
