/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0d18;
  --surface:    #16162a;
  --surface2:   #1e1e35;
  --surface3:   #26264a;
  --border:     rgba(255,255,255,.07);
  --accent:     #6366f1;
  --accent-h:   #818cf8;
  --accent-dim: rgba(99,102,241,.15);
  --danger:     #ef4444;
  --success:    #22c55e;
  --warn:       #f59e0b;
  --text:       #f1f1f8;
  --text-sub:   #8b8bab;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 4px 24px rgba(0,0,0,.4);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); min-height: 100vh;
       -webkit-font-smoothing: antialiased; }
a { color: var(--accent-h); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Auth ===== */
.auth-body { display: flex; align-items: center; justify-content: center;
             min-height: 100vh; padding: 1.5rem;
             background: radial-gradient(ellipse at 60% 0%, rgba(99,102,241,.18) 0%, transparent 60%), var(--bg); }

.auth-card { background: var(--surface); border: 1px solid var(--border);
             border-radius: 20px; padding: 2.5rem 2rem; width: 100%;
             max-width: 420px; box-shadow: var(--shadow); }

.logo-mark { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.75rem; }
.logo-text  { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.auth-title { font-size: 1.6rem; font-weight: 700; margin-bottom: .35rem; }
.auth-sub   { color: var(--text-sub); font-size: .9rem; margin-bottom: 1.75rem; }
.auth-footer{ text-align: center; font-size: .85rem; color: var(--text-sub); margin-top: 1.5rem; }

/* ===== Forms ===== */
.auth-form, .modal-form { display: flex; flex-direction: column; gap: 1rem; }
.field-group { display: flex; flex-direction: column; gap: .4rem; }
.field-group label { font-size: .8rem; font-weight: 600; color: var(--text-sub);
                     text-transform: uppercase; letter-spacing: .06em; }
.field-group input, .field-group select {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .75rem 1rem;
    color: var(--text); font-size: .95rem; outline: none; transition: border .2s; width: 100%;
}
.field-group input:focus, .field-group select:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim);
}
.field-group input::placeholder { color: var(--text-sub); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
       border: none; border-radius: var(--radius-sm); padding: .75rem 1.25rem;
       font-size: .9rem; font-weight: 600; cursor: pointer; transition: all .18s;
       text-decoration: none; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); transform: translateY(-1px); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface3); }
.btn-full { width: 100%; }
.btn-sm   { padding: .45rem .9rem; font-size: .82rem; border-radius: 6px; }

.btn-icon { background: var(--surface2); border: 1px solid var(--border);
            border-radius: 8px; padding: .5rem; cursor: pointer; color: var(--text);
            display: flex; align-items: center; justify-content: center;
            transition: background .15s; position: relative; }
.btn-icon:hover { background: var(--surface3); }

/* ===== Alerts ===== */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500; }
.alert-error { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }

/* ===== App layout ===== */
.app-body { display: flex; min-height: 100vh; }

.sidebar { width: 240px; min-height: 100vh; background: var(--surface);
           border-right: 1px solid var(--border);
           display: flex; flex-direction: column; flex-shrink: 0; padding: 1.25rem 1rem; }
.sidebar-logo { display: flex; align-items: center; gap: .75rem;
                font-size: 1.1rem; font-weight: 700; margin-bottom: 2rem; padding: .25rem; }
.sidebar-nav  { flex: 1; display: flex; flex-direction: column; gap: .25rem; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem;
            border-radius: var(--radius-sm); color: var(--text-sub);
            font-size: .9rem; font-weight: 500; transition: all .15s;
            text-decoration: none; cursor: pointer; border: none; background: none; }
.nav-item:hover, .nav-item.active { background: var(--accent-dim); color: var(--accent-h); text-decoration: none; }
.sidebar-user { display: flex; align-items: center; gap: .75rem; padding: .75rem;
                border-top: 1px solid var(--border); margin-top: auto; }
.user-info  { flex: 1; min-width: 0; }
.user-name  { font-size: .85rem; font-weight: 600; display: block;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { color: var(--text-sub); display: flex; transition: color .15s;
              background: none; border: none; cursor: pointer; padding: .25rem; }
.logout-btn:hover { color: var(--danger); }

.main-content { flex: 1; padding: 2rem 2.5rem; overflow-y: auto; }
.page-header  { margin-bottom: 2rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: .35rem; }
.page-sub { color: var(--text-sub); font-size: .9rem; }

/* ===== Quick actions ===== */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 2.5rem; }
.action-card { display: flex; align-items: center; gap: 1rem; padding: 1.25rem 1.5rem;
               border-radius: var(--radius); border: 1px solid var(--border);
               cursor: pointer; background: var(--surface); text-align: left; transition: all .2s; }
.action-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.action-new:hover  { background: var(--accent-dim); }
.action-join:hover { background: rgba(16,185,129,.1); border-color: #10b981; }
.action-icon { width: 52px; height: 52px; background: var(--surface2);
               border-radius: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.action-new  .action-icon { background: var(--accent-dim); color: var(--accent-h); }
.action-join .action-icon { background: rgba(16,185,129,.15); color: #34d399; }
.action-title { font-size: .95rem; font-weight: 700; }
.action-sub   { font-size: .8rem; color: var(--text-sub); margin-top: .15rem; }

/* ===== Rooms grid ===== */
.rooms-section { margin-bottom: 2rem; }
.section-title  { font-size: 1rem; font-weight: 700; color: var(--text-sub);
                  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 1rem; }
.rooms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }

.room-card { background: var(--surface); border: 1px solid var(--border);
             border-radius: var(--radius); padding: 1.25rem; transition: all .18s; }
.room-card:hover { border-color: rgba(99,102,241,.4); transform: translateY(-1px); }
.room-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; }
.room-type-badge { display: inline-flex; align-items: center; gap: .35rem;
                   padding: .25rem .65rem; border-radius: 20px; font-size: .75rem;
                   font-weight: 600; background: var(--surface2); color: var(--text-sub); }
.room-type-badge.video { background: var(--accent-dim); color: var(--accent-h); }
.room-type-badge.audio { background: rgba(16,185,129,.12); color: #34d399; }
.live-badge { display: flex; align-items: center; gap: .35rem; font-size: .75rem; color: #4ade80; font-weight: 600; }
.live-dot { width: 7px; height: 7px; background: #4ade80; border-radius: 50%; animation: pulse-live 1.5s ease-in-out infinite; }
@keyframes pulse-live { 0%,100%{opacity:1} 50%{opacity:.4} }
.room-name    { font-size: 1rem; font-weight: 700; margin-bottom: .3rem; }
.room-code    { font-size: .78rem; color: var(--text-sub); font-family: monospace; letter-spacing: .08em; margin-bottom: 1rem; }
.room-actions { display: flex; gap: .5rem; }

/* ===== Avatar ===== */
.avatar-sm { width: 34px; height: 34px; border-radius: 50%; display: flex;
             align-items: center; justify-content: center; font-size: .75rem;
             font-weight: 700; color: #fff; flex-shrink: 0; }

/* ===== Modals ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.65);
                  display: flex; align-items: center; justify-content: center;
                  z-index: 100; backdrop-filter: blur(4px); }
.modal { background: var(--surface); border: 1px solid var(--border);
         border-radius: 20px; padding: 2rem; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.modal h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; padding-top: .5rem; }
.toggle-group { display: flex; gap: .75rem; }
.toggle-opt   { display: flex; align-items: center; gap: .5rem; cursor: pointer;
                padding: .65rem 1rem; border-radius: var(--radius-sm);
                border: 1px solid var(--border); background: var(--surface2);
                transition: all .15s; flex: 1; }
.toggle-opt input { display: none; }
.toggle-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-dim); }
.toggle-opt span { font-size: .9rem; font-weight: 500; }

/* ===== Empty / Toast ===== */
.empty-state { display: flex; flex-direction: column; align-items: center;
               padding: 4rem 2rem; gap: 1rem; color: var(--text-sub); }
.toast { position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
         background: #1c1c3a; border: 1px solid var(--border);
         color: var(--text); padding: .75rem 1.5rem; border-radius: 100px;
         font-size: .875rem; font-weight: 600; z-index: 300; box-shadow: var(--shadow);
         animation: slide-up .2s ease; pointer-events: none; }
@keyframes slide-up { from{opacity:0;transform:translateX(-50%) translateY(10px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }

/* ===== Room page ===== */
.room-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; background: var(--bg); }

.room-header { display: flex; align-items: center; justify-content: space-between;
               padding: .75rem 1.25rem; background: var(--surface);
               border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 1rem; }
.room-info { display: flex; align-items: center; gap: .75rem; }
.back-link { color: var(--text-sub); display: flex; padding: .35rem; border-radius: 6px;
             transition: all .15s; }
.back-link:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.room-title { font-size: .95rem; font-weight: 700; line-height: 1.2; }
.room-code-display { font-size: .7rem; color: var(--text-sub); font-family: monospace;
                     letter-spacing: .1em; margin-top: .1rem; }
.room-header-actions { display: flex; align-items: center; gap: .75rem; }
.participant-count { display: flex; align-items: center; gap: .4rem; font-size: .82rem;
                     color: var(--text-sub); font-weight: 600;
                     background: var(--surface2); border: 1px solid var(--border);
                     padding: .35rem .75rem; border-radius: 20px; }

/* ===== Recording indicator ===== */
.rec-indicator { display: flex; align-items: center; gap: .5rem;
                 background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.4);
                 color: #fca5a5; padding: .3rem .75rem; border-radius: 20px;
                 font-size: .78rem; font-weight: 700; }
.rec-dot { width: 8px; height: 8px; background: var(--danger); border-radius: 50%;
           animation: pulse-rec .9s ease-in-out infinite; }
@keyframes pulse-rec { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.5;transform:scale(.7)} }

/* ===== Room wrapper + chat ===== */
.room-wrapper { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ===== Video grid ===== */
.video-grid { flex: 1; display: grid; gap: .75rem; padding: 1rem; overflow: hidden; align-content: start; }
.video-grid.count-1 { grid-template-columns: 1fr; }
.video-grid.count-2 { grid-template-columns: 1fr 1fr; }
.video-grid.count-3 { grid-template-columns: 1fr 1fr; }
.video-grid.count-4 { grid-template-columns: 1fr 1fr; }
.video-grid.count-5,
.video-grid.count-6 { grid-template-columns: repeat(3,1fr); }
.video-grid         { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.video-tile { position: relative; background: var(--surface); border-radius: var(--radius);
              overflow: hidden; aspect-ratio: 16/9; min-height: 120px; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-tile.no-video video { display: none; }
.tile-overlay { position: absolute; inset: 0; display: flex; align-items: center;
                justify-content: center; pointer-events: none; }
.tile-avatar  { width: 72px; height: 72px; border-radius: 50%; display: flex;
                align-items: center; justify-content: center; font-size: 1.6rem;
                font-weight: 700; color: #fff; }
.tile-label   { position: absolute; bottom: .5rem; left: .75rem;
                background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
                color: #fff; font-size: .73rem; font-weight: 600;
                padding: .2rem .5rem; border-radius: 20px;
                display: flex; align-items: center; gap: .35rem; max-width: 70%; }
.tile-mute-icon { color: var(--danger); }
.tile-hand-icon { font-size: .85rem; }
.audio-mode .tile-avatar { width: 96px; height: 96px; font-size: 2.2rem; }

/* ===== Status overlay ===== */
.status-overlay { position: fixed; inset: 0; background: rgba(13,13,24,.88);
                  display: flex; flex-direction: column; align-items: center;
                  justify-content: center; z-index: 50; gap: 1rem; backdrop-filter: blur(6px); }
.status-overlay.hidden { display: none; }
.status-spinner { width: 40px; height: 40px; border: 3px solid var(--surface3);
                  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#status-text { color: var(--text-sub); font-size: .95rem; font-weight: 500; }

/* ===== Chat panel ===== */
.chat-panel { width: 0; background: var(--surface); border-left: 1px solid transparent;
              display: flex; flex-direction: column; overflow: hidden;
              transition: width .25s ease, border-color .25s; flex-shrink: 0; }
.chat-panel.open { width: 300px; border-left-color: var(--border); }
.chat-header { display: flex; align-items: center; justify-content: space-between;
               padding: .85rem 1rem; border-bottom: 1px solid var(--border);
               font-size: .9rem; font-weight: 700; flex-shrink: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: .75rem; display: flex;
                 flex-direction: column; gap: .5rem; }
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }
.chat-msg { display: flex; flex-direction: column; gap: .15rem; }
.chat-user { font-size: .72rem; font-weight: 700; }
.chat-text { font-size: .875rem; color: var(--text); background: var(--surface2);
             padding: .4rem .6rem; border-radius: 0 8px 8px 8px; word-break: break-word; }
.chat-input-row { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-input-row input { flex: 1; background: var(--surface2); border: 1px solid var(--border);
                        border-radius: var(--radius-sm); padding: .5rem .75rem; color: var(--text);
                        font-size: .875rem; outline: none; }
.chat-input-row input:focus { border-color: var(--accent); }

.chat-badge { position: absolute; top: -4px; right: -4px; background: var(--danger);
              color: #fff; font-size: .65rem; font-weight: 700; min-width: 16px; height: 16px;
              border-radius: 8px; display: flex; align-items: center; justify-content: center;
              padding: 0 3px; pointer-events: none; }

/* ===== Control bar ===== */
.control-bar { display: flex; align-items: center; justify-content: center; gap: .75rem;
               padding: .85rem 1.25rem; background: var(--surface);
               border-top: 1px solid var(--border); flex-shrink: 0; }
.ctrl-group { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.ctrl-label { font-size: .65rem; color: var(--text-sub); font-weight: 600;
              text-transform: uppercase; letter-spacing: .05em; }

.ctrl-btn { width: 48px; height: 48px; border-radius: 50%; border: none;
            cursor: pointer; display: flex; align-items: center; justify-content: center;
            background: var(--surface2); color: var(--text); transition: all .18s;
            border: 1px solid var(--border); position: relative; }
.ctrl-btn:hover  { background: var(--surface3); transform: scale(1.06); }
.ctrl-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ctrl-btn.muted  { background: rgba(239,68,68,.12); border-color: var(--danger); color: var(--danger); }
.ctrl-btn.recording { background: rgba(239,68,68,.2); border-color: var(--danger); color: var(--danger);
                       animation: pulse-rec-btn 1.2s ease-in-out infinite; }
@keyframes pulse-rec-btn { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.4)} 50%{box-shadow:0 0 0 8px rgba(239,68,68,0)} }
.ctrl-btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctrl-btn-danger:hover { background: #dc2626; transform: scale(1.06); }

/* ===== Recordings list ===== */
.recordings-list { display: flex; flex-direction: column; gap: .75rem; }
.rec-card { display: flex; align-items: center; gap: 1rem; background: var(--surface);
            border: 1px solid var(--border); border-radius: var(--radius);
            padding: 1rem 1.25rem; transition: border-color .15s; }
.rec-card:hover { border-color: rgba(99,102,241,.35); }
.rec-icon { color: var(--danger); opacity: .7; flex-shrink: 0; }
.rec-info { flex: 1; min-width: 0; }
.rec-name { font-weight: 700; font-size: .95rem; margin-bottom: .3rem;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-meta { display: flex; align-items: center; gap: .5rem; font-size: .78rem;
            color: var(--text-sub); flex-wrap: wrap; }
.rec-actions { display: flex; gap: .5rem; flex-shrink: 0; }

@media (max-width: 600px) {
    .quick-actions { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main-content { padding: 1.25rem; }
    .rooms-grid { grid-template-columns: 1fr; }
    .video-grid { grid-template-columns: 1fr !important; }
    .control-bar { gap: .4rem; padding: .7rem .5rem; }
    .ctrl-btn { width: 42px; height: 42px; }
    .chat-panel.open { width: 260px; }
    .rec-card { flex-direction: column; align-items: flex-start; }
}
