@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg: #0a0e17;
  --bg-elevated: #131a2b;
  --bg-surface: #1a2340;
  --border: #263354;
  --text: #e4e8f1;
  --text-muted: #8892a8;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --danger: #ff4f6d;
  --danger-hover: #ff6b84;
  --notify: #fbbf24;
  --radius: 10px;
  --radius-lg: 16px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --sidebar-w: 360px;
  --topbar-h: 56px;
  --ctrl-h: 80px;
}

html, body {
  height: 100%; overflow: hidden;
  font-family: var(--font); background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.screen { width: 100%; height: 100%; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elevated); color: var(--text); font-family: var(--font);
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg-surface); border-color: var(--accent); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 40px; font-size: 16px; }
.btn-close { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; padding: 4px; }
.btn-close:hover { color: var(--text); }

/* Logo */
.logo { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.logo span { color: var(--accent); }
.logo-sm { font-size: 18px; }

/* === Lobby === */
#lobby {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #131a2b 0%, var(--bg) 70%);
}
.lobby-card {
  text-align: center; max-width: 520px; padding: 48px 36px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.lobby-card .logo { font-size: 36px; margin-bottom: 16px; }
.lobby-info { color: var(--text-muted); font-size: 15px; line-height: 1.6; margin-bottom: 24px; }
.room-link-box { display: flex; gap: 8px; margin-bottom: 16px; }
.room-link-box input {
  flex: 1; min-width: 0; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--accent); font-family: var(--font-mono); font-size: 13px; outline: none;
  overflow: hidden; text-overflow: ellipsis;
}
.name-box { margin-bottom: 20px; }
.name-box input {
  width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font); font-size: 14px;
  outline: none; text-align: center;
}
.name-box input:focus { border-color: var(--accent); }
.name-box input::placeholder { color: var(--text-muted); }
.lobby-note { margin-top: 20px; font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* === App === */
#app { display: flex; flex-direction: column; height: 100%; position: relative; }

#topbar {
  height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 10;
}

/* Video Grid */
#videoGrid {
  flex: 1; display: grid; gap: 8px; padding: 8px; overflow: hidden;
  transition: margin-right .25s ease;
}
#videoGrid.grid-1 { grid-template-columns: 1fr; }
#videoGrid.grid-2 { grid-template-columns: 1fr 1fr; }
#videoGrid.grid-3, #videoGrid.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#videoGrid.grid-many { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); grid-auto-rows: minmax(200px, 1fr); }
#app.sidebar-open #videoGrid { margin-right: var(--sidebar-w); }

/* Video Tile */
.video-tile {
  position: relative; background: var(--bg-surface); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent; animation: fadeIn .3s ease;
}
.video-tile:hover { border-color: var(--border); }
.video-tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-tile.local video { transform: scaleX(-1); }
.tile-label {
  position: absolute; bottom: 8px; left: 8px; padding: 3px 10px;
  background: rgba(0,0,0,.65); border-radius: 6px; font-size: 12px; font-weight: 500; color: #fff;
}
.tile-muted {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  background: rgba(255,79,109,.85); border-radius: 50%;
  display: none; align-items: center; justify-content: center;
}
.tile-muted.visible { display: flex; }
.tile-muted svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 2; }

/* Fullscreen button */
.tile-fs-btn {
  position: absolute; top: 8px; left: 8px; width: 32px; height: 32px;
  background: rgba(0,0,0,.55); border: none; border-radius: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.video-tile:hover .tile-fs-btn { opacity: 1; }
.tile-fs-btn svg {
  width: 16px; height: 16px; stroke: #fff; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tile-fs-btn:hover { background: rgba(79,140,255,.7); }

/* Fullscreen state */
.video-tile:fullscreen,
.video-tile:-webkit-full-screen {
  background: #000; border: none; border-radius: 0;
}
.video-tile:fullscreen video,
.video-tile:-webkit-full-screen video {
  width: 100%; height: 100%; object-fit: contain;
}
.video-tile:fullscreen .tile-label,
.video-tile:-webkit-full-screen .tile-label {
  font-size: 14px; bottom: 16px; left: 16px; padding: 5px 14px;
}
.video-tile:fullscreen .tile-fs-btn,
.video-tile:-webkit-full-screen .tile-fs-btn {
  opacity: 0; top: 16px; left: 16px; width: 40px; height: 40px;
}
.video-tile:fullscreen:hover .tile-fs-btn,
.video-tile:-webkit-full-screen:hover .tile-fs-btn {
  opacity: 1;
}

/* On mobile, always show fullscreen button (no hover) */
@media (hover: none) {
  .tile-fs-btn { opacity: .7; }
}

/* Controls */
#controls {
  height: var(--ctrl-h); display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 0 16px; background: var(--bg-elevated);
  border-top: 1px solid var(--border); flex-shrink: 0; z-index: 10;
}
.ctrl-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 18px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); cursor: pointer;
  transition: all .15s; font-family: var(--font); font-size: 11px; font-weight: 500;
}
.ctrl-btn:hover { background: var(--bg-surface); }
@media (hover: hover) {
  .ctrl-btn:hover { background: var(--border); border-color: var(--accent); }
}
.ctrl-btn .icon {
  width: 22px; height: 22px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ctrl-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ctrl-btn.danger-active { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Notification flash */
.ctrl-btn.notify-flash { background: var(--notify) !important; border-color: var(--notify) !important; color: #000 !important; }
.ctrl-btn.notify-flash .icon { stroke: #000 !important; }

/* === Sidebar === */
#sidebar {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: var(--ctrl-h);
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transform: translateX(100%);
  transition: transform .25s ease;
}
#sidebar.sidebar-visible {
  transform: translateX(0);
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-tabs { display: flex; gap: 4px; }
.tab-btn {
  padding: 6px 16px; background: transparent; border: 1px solid transparent;
  border-radius: 6px; color: var(--text-muted); font-family: var(--font);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.tab-btn.active { background: var(--bg-surface); border-color: var(--border); color: var(--text); }
.tab-btn:hover:not(.active) { color: var(--text); }

.tab-content { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; }

/* Chat */
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap; }
.chat-msg.sent { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.received { align-self: flex-start; background: var(--bg-surface); color: var(--text); border-bottom-left-radius: 3px; }
.chat-msg .msg-sender { font-size: 11px; font-weight: 600; opacity: .7; margin-bottom: 2px; }
.chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-input textarea {
  flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font); font-size: 14px; resize: none; outline: none;
}
.chat-input textarea:focus { border-color: var(--accent); }

/* Files */
.file-list { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg-surface); border-radius: var(--radius); text-decoration: none;
  color: var(--text); font-size: 13px; transition: background .15s; word-break: break-all;
}
.file-item:hover { background: var(--border); }
.file-item .file-icon { width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 2; flex-shrink: 0; }
.delete-info { padding: 4px 16px 8px; font-size: 11px; color: var(--text-muted); }
.file-upload {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
#uploadStatus { font-size: 12px; color: var(--text-muted); }

/* Mobile */
.mobile-only { display: none; }

@media (max-width: 768px) {
  :root { --sidebar-w: 100%; --ctrl-h: 70px; }
  .mobile-only { display: flex; }
  #controls { gap: 4px; padding: 0 8px; }
  .ctrl-btn { padding: 8px 10px; font-size: 10px; }
  .ctrl-btn .icon { width: 20px; height: 20px; }
  #app.sidebar-open #videoGrid { margin-right: 0; }
  #sidebar { top: 0; bottom: 0; }
  .lobby-card { margin: 16px; padding: 32px 24px; }
  .lobby-card .logo { font-size: 28px; }
  #videoGrid { gap: 4px; padding: 4px; }
  #videoGrid.grid-2 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@keyframes fadeIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
