:root {
  --bg: #0b1120;
  --bg-elev: #111a2e;
  --card: #16213a;
  --card-2: #1b2743;
  --border: #26324f;
  --border-soft: #1e2a3c;
  --text: #e8edf7;
  --muted: #94a3b8;
  --faint: #64748b;
  --primary: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --danger: #ef4444;
  --danger-600: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'Vazirmatn', 'IRANSans', 'Segoe UI', Tahoma, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 600px at 100% -10%, rgba(59, 130, 246, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(99, 102, 241, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: #7cb0ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  background: rgba(17, 26, 46, 0.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}
.brand-title { font-weight: 700; font-size: 1rem; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }

.topbar-user { display: flex; align-items: center; gap: 0.6rem; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.7rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
}
.user-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }

/* ── Layout ──────────────────────────────────────────── */
.container { max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.35rem; margin: 0; }
.page-head p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 1.25rem; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 1.02rem; }
.card-body { padding: 1.25rem; }

/* ── Stats row ───────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.stat .label { color: var(--muted); font-size: 0.82rem; }
.stat .value { font-size: 1.7rem; font-weight: 800; margin-top: 0.15rem; }
.stat .value.accent { color: #93c5fd; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-700); }
.btn-danger { background: var(--danger-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--card-2); }
.btn-sm { padding: 0.38rem 0.75rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ── Forms ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span { font-size: 0.82rem; color: var(--muted); }
input {
  font-family: inherit; font-size: 0.92rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #0d1526;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18); }
input::placeholder { color: var(--faint); }

/* ── Table ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 0.8rem 1rem; }
thead th {
  color: var(--muted); font-weight: 600; font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}
tbody td { border-bottom: 1px solid var(--border-soft); font-size: 0.92rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(59, 130, 246, 0.06); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
}
.badge-live { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge-live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 rgba(34,197,94,0.6); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5);} 70% { box-shadow: 0 0 0 6px rgba(34,197,94,0);} 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0);} }

.empty-state { text-align: center; color: var(--faint); padding: 2.5rem 1rem; font-size: 0.95rem; }

/* ── Login ───────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 2rem 1.75rem;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-bottom: 1.5rem; text-align: center; }
.auth-brand .brand-mark { width: 52px; height: 52px; font-size: 1.1rem; border-radius: 14px; }
.auth-brand h1 { font-size: 1.15rem; margin: 0.2rem 0 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 0.83rem; }
.auth-card .field { margin-bottom: 0.9rem; }

.error-text { color: #fca5a5; font-size: 0.85rem; min-height: 1.2rem; margin: 0.2rem 0 0.6rem; }

/* ── Monitor viewer ──────────────────────────────────── */
.monitor-controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; padding: 1.25rem; }
.monitor-controls .field { flex: 1; min-width: 180px; }
.monitor-actions { display: flex; gap: 0.5rem; }
.status-line { padding: 0 1.25rem; color: var(--muted); font-size: 0.86rem; min-height: 1.2rem; }
.notice { padding: 0 1.25rem 1.25rem; color: var(--warning); font-size: 0.82rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; margin-top: 1.25rem; }
.tile { background: #000; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; position: relative; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile .label { position: absolute; bottom: 0.5rem; inset-inline-start: 0.6rem; background: rgba(0,0,0,0.6); padding: 0.15rem 0.5rem; border-radius: 6px; font-size: 0.78rem; }

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 7, 18, 0.7);
  backdrop-filter: blur(4px); display: none; place-items: center; z-index: 50; padding: 1.5rem;
}
.modal-backdrop.open { display: grid; }
.modal {
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.modal-head { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 1.02rem; }
.modal-body { padding: 1.25rem; }
.modal-body .field { margin-bottom: 0.9rem; }
.modal-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: 0.6rem; justify-content: flex-start; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.icon-btn:hover { color: var(--text); }
.form-hint { font-size: 0.78rem; color: var(--faint); margin: -0.4rem 0 0.6rem; }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; inset-inline-start: 1.5rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.75rem 1rem; box-shadow: var(--shadow); font-size: 0.88rem;
  opacity: 0; transform: translateY(10px); transition: opacity 0.2s, transform 0.2s; z-index: 60;
  pointer-events: none; max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-inline-start: 3px solid var(--success); }
.toast.error { border-inline-start: 3px solid var(--danger); }

@media (max-width: 560px) {
  .topbar { padding: 0.75rem 1rem; }
  .brand-sub { display: none; }
  th, td { padding: 0.65rem 0.6rem; }
}

/* ── Live monitor layout ─────────────────────────────── */
.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.live-layout { display: grid; grid-template-columns: 1fr 370px; gap: 1rem; align-items: start; margin-top: 1.25rem; }
@media (max-width: 920px) { .live-layout { grid-template-columns: 1fr; } }
.video-area .tiles { margin-top: 0; }
.video-area .empty-state { border: 1px dashed var(--border); border-radius: var(--radius); }
.sidebar { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 80px; }

.tabs { display: flex; gap: 0.25rem; padding: 0.5rem; border-bottom: 1px solid var(--border); }
.tab-btn { flex: 1; background: transparent; border: none; color: var(--muted); padding: 0.55rem; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 0.9rem; }
.tab-btn.active { background: var(--card-2); color: var(--text); font-weight: 600; }
.tab-btn .count { font-size: 0.72rem; color: var(--faint); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.chat-scroll { height: 48vh; min-height: 260px; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.chat-empty { color: var(--faint); text-align: center; margin: auto 0; font-size: 0.88rem; }
.msg { background: var(--card-2); border: 1px solid var(--border-soft); border-radius: 10px; padding: 0.5rem 0.7rem; }
.msg .meta { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.72rem; color: var(--faint); margin-bottom: 0.2rem; }
.msg .sender { color: #93c5fd; font-weight: 600; }
.msg .content { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }
.msg.private { border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.06); }
.badge-private { background: rgba(245, 158, 11, 0.15); color: #fcd34d; padding: 0.05rem 0.4rem; border-radius: 999px; font-size: 0.68rem; }

.files-scroll { max-height: 48vh; min-height: 120px; overflow-y: auto; padding: 0.4rem; }
.files-empty { color: var(--faint); text-align: center; padding: 2rem 1rem; font-size: 0.88rem; }
.file-row { display: flex; gap: 0.6rem; align-items: center; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border-soft); }
.file-row:last-child { border-bottom: none; }
.file-icon { width: 36px; height: 36px; border-radius: 9px; background: var(--card-2); display: grid; place-items: center; flex: none; font-size: 1rem; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 0.75rem; color: var(--faint); }
.file-new { animation: flashNew 2.5s ease; }
@keyframes flashNew { 0% { background: rgba(59,130,246,0.22); } 100% { background: transparent; } }

/* Per-tile actions + maximize */
.tile .tile-actions { position: absolute; top: 0.45rem; inset-inline-end: 0.45rem; display: flex; gap: 0.3rem; opacity: 0; transition: opacity 0.15s ease; }
.tile:hover .tile-actions { opacity: 1; }
.tile-btn { background: rgba(0, 0, 0, 0.55); border: none; color: #fff; width: 30px; height: 30px; border-radius: 7px; cursor: pointer; font-size: 0.95rem; display: grid; place-items: center; line-height: 1; }
.tile-btn:hover { background: rgba(0, 0, 0, 0.85); }
.tile.maximized { position: fixed; inset: 0; z-index: 80; aspect-ratio: auto; border-radius: 0; }
.tile.maximized video { object-fit: contain; background: #000; }
.tile.maximized .tile-actions { opacity: 1; }

/* ── Members list ────────────────────────────────────── */
.member-avatar { position: relative; }
.member-avatar .online { position: absolute; bottom: -1px; inset-inline-end: -1px; width: 11px; height: 11px; border-radius: 50%; background: var(--success); border: 2px solid var(--card); }
.role-badge { padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.role-owner { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.role-manager { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
.role-contributor { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.role-member { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
.file-actions { flex: none; }
.file-actions .btn { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
