:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --green: #16a34a; --blue: #2563eb; --danger: #dc2626; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.tag { font-size: 11px; font-weight: 600; background: var(--blue); color: #fff; padding: 2px 6px; border-radius: 6px; vertical-align: middle; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); width: 100%; max-width: 360px; padding: 28px; border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.06); display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.login-card button { padding: 11px; border: 0; border-radius: 8px; background: var(--blue); color: #fff; font-weight: 600; }
.alert { background: #fef2f2; color: var(--danger); padding: 10px 12px; border-radius: 8px; transition: opacity .6s; }
.alert.fade { opacity: 0; }

/* Shell */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; }
.brand { font-weight: 700; font-size: 18px; padding: 0 8px; }
nav { display: grid; gap: 4px; }
.nav-item, .sub-item { text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; color: var(--text); }
.nav-item.active { background: #eef2ff; font-weight: 600; }
.sub { display: grid; gap: 2px; padding-left: 14px; }
.sub-item { font-size: 14px; color: var(--muted); }
.sub-item.active { color: var(--green); font-weight: 600; }
.me { margin-top: auto; padding: 0 8px; font-size: 14px; }
.me a { color: var(--muted); }
main { padding: 24px; }
.title { margin: 0 0 16px; }
.title.personal { color: var(--green); }
.title.org { color: var(--blue); }

/* Sidebar groups */
.sub-group { display: grid; gap: 2px; margin-top: 6px; }
.sub-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 10px; }
.sub-picker { margin-top: 6px; }

/* Context dropdown: personal profile (green) + organizations (blue) */
.ctx-dropdown { position: relative; }
.ctx-toggle { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--line); }
.ctx-toggle span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-toggle .caret { font-size: 11px; color: var(--muted); }
.sub-item.ctx-toggle.active.personal { color: var(--green); }
.sub-item.ctx-toggle.active.org { color: var(--blue); }
.ctx-menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.08); padding: 4px; display: grid; gap: 2px; max-height: 50vh; overflow: auto; }
.ctx-option { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font-size: 14px; font-weight: 600; }
.ctx-option.personal { color: var(--green); }
.ctx-option.org { color: var(--blue); }
.ctx-option:hover, .ctx-option:focus-visible { background: #f3f4f6; outline: none; }
.ctx-option[aria-selected="true"] { background: #eef2ff; }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.personal-label { cursor: default; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar select, .toolbar input[type=search] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }

/* Video grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: grid; }
.tile-media { position: relative; border: 0; padding: 0; background: none; display: block; }
.duration { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.tile-info { position: relative; padding: 8px 34px 10px 10px; }
.tile-move { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star { position: absolute; right: 6px; top: 6px; border: 0; background: none; font-size: 18px; color: var(--muted); line-height: 1; }
.star.on { color: #f59e0b; }
.tile-error { position: absolute; inset: auto 6px 6px 6px; background: #fef2f2; color: var(--danger); font-size: 12px; padding: 4px 6px; border-radius: 6px; }
.tile.fav { border: 2px solid transparent; background: linear-gradient(var(--panel), var(--panel)) padding-box, linear-gradient(135deg, #f59e0b, #ec4899) border-box; }
.tile img { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #e5e7eb; }
.tile img.missing { visibility: hidden; }

/* Player */
.player { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 10; }
.player-inner { position: relative; width: min(960px, 94vw); }
.player video { width: 100%; max-height: 85vh; background: #000; border-radius: var(--radius); }
.player-meta { color: #fff; margin-top: 10px; font-size: 14px; }
.player-meta p { margin: 6px 0 0; white-space: pre-wrap; }
.player-meta .muted { color: #cbd5e1; }
.close { position: absolute; top: -40px; right: 0; background: none; border: 0; color: #fff; font-size: 22px; }

/* Console */
.console-row { display: flex; gap: 8px; margin-bottom: 12px; }
.console-row input { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font: 13px ui-monospace, monospace; }
.console-row select, .console-row button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
pre { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: var(--radius); overflow: auto; max-height: 60vh; font-size: 12px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .me { margin-top: 0; }
}
