/* ── Variables ── */
:root {
  --bg:          #0d1117;
  --bg-card:     #161b22;
  --bg-input:    #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --primary:     #58a6ff;
  --primary-dim: rgba(88,166,255,0.12);
  --success:     #3fb950;
  --danger:      #f85149;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 16px 48px rgba(0,0,0,0.5);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #0d1117; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-success { background: var(--success); color: #0d1117; }
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: var(--radius); width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ── Inputs ── */
.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--primary); }
.form-input::placeholder { color: var(--text-muted); }

/* ── Alerts ── */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.alert-error   { background: rgba(248,81,73,0.12); border: 1px solid rgba(248,81,73,0.3); color: #f85149; }
.alert-success { background: rgba(63,185,80,0.12); border: 1px solid rgba(63,185,80,0.3); color: #3fb950; }

/* ── Shared card used on caller + admin login ── */
.card-center {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ══════════════════════════════════════════════════════════
   CALLER PAGE  (/index.html)
══════════════════════════════════════════════════════════ */

.caller-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

/* Screen switcher */
.screen { display: none; width: 100%; max-width: 420px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* Join screen */
.join-header { text-align: center; }
.join-header h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.join-header p { color: var(--text-muted); margin-top: 6px; font-size: 15px; }

.join-logo {
  width: 64px;
  height: 64px;
  background: var(--primary-dim);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 4px;
  border: 1px solid rgba(88,166,255,0.25);
}

.join-form { display: flex; flex-direction: column; gap: 12px; }

/* Waiting screen pulse */
.pulse-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 90px;
}

.pulse-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.pulse-ring::before, .pulse-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--primary);
  animation: pulse-out 2s ease-out infinite;
}
.pulse-ring::after { animation-delay: 0.7s; }

.pulse-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
}

@keyframes pulse-out {
  0%   { transform: scale(0.9); opacity: 0.9; }
  100% { transform: scale(2.8); opacity: 0; }
}

/* Ended screen */
.ended-icon {
  font-size: 52px;
  text-align: center;
}

/* ── Video call screen ── */
#screen-call {
  position: fixed;
  inset: 0;
  max-width: none;
  background: #000;
  flex-direction: column;
  display: none;
}
#screen-call.active { display: flex; }

#video-wrapper {
  flex: 1;
  position: relative;
  background: #111;
  overflow: hidden;
  min-width: 0;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#local-video {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 168px;
  height: 126px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.18);
  background: #1a1a1a;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

#call-bar {
  background: rgba(13,17,23,0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 11px 22px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 82px;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.16); }
.ctrl-btn.toggled { background: rgba(88,166,255,0.2); border-color: rgba(88,166,255,0.4); color: var(--primary); }
.ctrl-btn-icon { font-size: 22px; line-height: 1; }
.ctrl-end { background: var(--danger); border-color: transparent; padding: 11px 34px; }
.ctrl-end:hover { background: #c0392b !important; }

/* ══════════════════════════════════════════════════════════
   ADMIN PAGE  (/admin.html)
══════════════════════════════════════════════════════════ */

.admin-page { min-height: 100vh; }

/* Admin login overlay */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
  z-index: 200;
}

/* Dashboard layout */
#dashboard {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 230px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h2 { font-size: 17px; font-weight: 700; }
.sidebar-logo p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.sidebar-nav { padding: 10px 8px; flex: 1; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
}
.nav-btn:hover { color: var(--text); background: var(--bg-input); }
.nav-btn.active { color: var(--primary); background: var(--primary-dim); }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.call-indicator {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Main panel */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.main-header {
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.main-header h1 { font-size: 19px; font-weight: 700; }
.main-header p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.main-content { flex: 1; overflow-y: auto; padding: 28px; }

/* Views */
.view { display: none; }
.view.active { display: block; }

/* Pending call cards */
.pending-empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 14px; }
.empty-icon p { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }

.call-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  transition: border-color 0.15s;
  animation: slide-in 0.2s ease;
}
.call-card:hover { border-color: rgba(88,166,255,0.4); }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.call-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-dim);
  border: 1px solid rgba(88,166,255,0.3);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}
.call-info { flex: 1; }
.call-name { font-weight: 600; font-size: 15px; }
.call-time { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.call-actions { display: flex; gap: 8px; }

/* Active call view */
#view-call { height: calc(100vh - 121px); }
#view-call.active { display: flex; flex-direction: column; gap: 12px; }

.active-call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.active-call-header h2 { font-size: 17px; font-weight: 600; }
.call-timer { font-size: 13px; color: var(--text-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }

.admin-video-wrap {
  flex: 1;
  position: relative;
  background: #111;
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

#admin-remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#admin-local-video {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 160px;
  height: 120px;
  object-fit: cover;
  border-radius: 9px;
  border: 2px solid rgba(255,255,255,0.15);
  background: #1a1a1a;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.no-video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.admin-call-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 16px 0 4px;
  flex-shrink: 0;
}

/* Settings */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.settings-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.settings-section .desc { color: var(--text-muted); font-size: 14px; margin-bottom: 18px; }
.settings-fields { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.settings-footer { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ── Video + chat wrapper ── */
#video-chat-wrap,
.video-chat-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* .video-chat-wrap is the admin variant — needs border-radius match */
.video-chat-wrap {
  border-radius: var(--radius);
  margin-bottom: 0;
}

/* ── Chat panel ── */
.chat-panel {
  width: 300px;
  flex-shrink: 0;
  background: rgba(13,17,23,0.96);
  border-left: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
}
/* Admin chat has rounded right edge to match video-wrap */
.video-chat-wrap .chat-panel {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.chat-close:hover { color: var(--text); background: rgba(255,255,255,0.08); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.sent {
  align-self: flex-end;
  background: var(--primary);
  color: #0d1117;
  border-bottom-right-radius: 4px;
}
.chat-msg.received {
  align-self: flex-start;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 11px;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s;
}
.chat-input::placeholder { color: rgba(255,255,255,0.3); }
.chat-input:focus { border-color: rgba(88,166,255,0.5); }

.btn-chat-send {
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: #0d1117;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-chat-send:hover { filter: brightness(1.1); }

/* Unread dot on chat button */
.ctrl-rel { position: relative; }
.chat-unread {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* ── Quality badge ── */
.quality-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 4px;
  cursor: default;
}
.quality-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.quality-good .quality-dot { background: var(--success); }
.quality-fair .quality-dot { background: #e3b341; }
.quality-poor .quality-dot { background: var(--danger); animation: blink 1s ease-in-out infinite; }

/* ── Recording button ── */
.ctrl-btn.recording { background: rgba(248,81,73,0.2); border-color: rgba(248,81,73,0.4); color: var(--danger); }

/* ── Call bar / controls flex-wrap ── */
#call-bar,
.admin-call-controls { flex-wrap: wrap; }

/* ── History ── */
.history-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.call-avatar.sm {
  width: 34px;
  height: 34px;
  font-size: 12px;
}

.history-duration {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  min-width: 72px;
  text-align: center;
  letter-spacing: 0.02em;
}
.status-accepted  { background: rgba(63,185,80,0.15);   color: var(--success); }
.status-rejected  { background: rgba(248,81,73,0.15);   color: var(--danger); }
.status-missed    { background: rgba(139,148,158,0.12); color: var(--text-muted); }
.status-cancelled { background: rgba(139,148,158,0.12); color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .sidebar { width: 200px; }
  .main-content { padding: 16px; }
  .card-center { padding: 32px 24px; }
  #admin-local-video { width: 100px; height: 75px; }
  #local-video { width: 110px; height: 82px; }
  .ctrl-btn { padding: 10px 14px; min-width: 64px; font-size: 12px; }
}

@media (max-width: 480px) {
  .sidebar { display: none; }
  .call-actions { flex-direction: column; }
}
