/* ============================================================
   PeerLink — style.css
   Aesthetic: Dark terminal / industrial utility
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans:wght@300;400;600&display=swap');

/* ── Variables ── */
:root {
  --bg:         #0d0f12;
  --surface:    #141720;
  --surface2:   #1c2030;
  --border:     #2a2f3e;
  --accent:     #4ff0a8;
  --accent-dim: #1e6a4a;
  --red:        #f05b5b;
  --yellow:     #f0c45b;
  --text:       #cdd5e0;
  --text-dim:   #5a6478;
  --mono:       'IBM Plex Mono', monospace;
  --sans:       'IBM Plex Sans', sans-serif;
  --radius:     6px;
  --gap:        16px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
}

/* ── HTTPS Warning ── */
.warning-banner {
  background: var(--yellow);
  color: #1a1400;
  text-align: center;
  padding: 8px 16px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* ── App Shell ── */
.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
  gap: 0;
}

/* ── Panels ── */
.panel {
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.panel-left {
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 100vh;
}

.panel-right {
  background: var(--bg);
}

/* ── Logo ── */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.logo-icon {
  font-size: 22px;
  color: var(--accent);
}
.logo-text {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent);
}

/* ── Cards ── */
.card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Form fields ── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-family: var(--mono);
}

input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
input[type="text"]:focus {
  border-color: var(--accent);
}
input[type="text"]::placeholder {
  color: var(--text-dim);
}

.input-row {
  display: flex;
  gap: 6px;
}
.input-row input { flex: 1; }

/* ── Buttons ── */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.05em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn-primary:active, .btn-secondary:active, .btn-danger:active { 
  transform: translateY(1px); 
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #3dd694 100%);
  color: #0d0f12;
}
.btn-primary:hover:not(:disabled) { 
  opacity: 0.9;
  box-shadow: 0 10px 15px -3px rgba(79, 240, 168, 0.3);
  transform: translateY(-1px);
}
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.5); }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.btn-secondary:hover:not(:disabled) { 
  border-color: var(--accent);
  background: var(--surface2);
  color: var(--accent);
  box-shadow: 0 4px 12px rgba(79, 240, 168, 0.1);
}
.btn-secondary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-danger {
  background: linear-gradient(135deg, #f05b5b 0%, #c93d3d 100%);
  color: white;
}
.btn-danger:hover:not(:disabled) { 
  box-shadow: 0 10px 15px -3px rgba(240, 91, 91, 0.3);
  transform: translateY(-1px);
}
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
}
.btn-ghost:hover { 
  color: var(--accent); 
  border-color: var(--accent-dim);
  background: var(--surface2);
}

.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 14px;
  backdrop-filter: blur(4px); /* Helpful for visibility on video */
}
.btn-icon:hover { 
  color: var(--accent); 
  border-color: var(--accent);
  background: var(--surface);
  transform: scale(1.05);
}
.btn-icon:active { transform: scale(0.95); }

.card-title .btn-icon {
  margin-left: auto;
}

/* ── Status messages ── */
.status-msg {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  min-height: 14px;
}
.status-msg.ok  { color: var(--accent); }
.status-msg.err { color: var(--red); }

/* ── Badge ── */
.badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 10px;
  border-radius: 20px;
  padding: 1px 7px;
  font-weight: 600;
}

/* ── User list ── */
.user-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}
.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-track { background: transparent; }
.user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.user-list-empty {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.user-item:hover {
  border-color: var(--accent-dim);
  background: var(--surface2);
}
.user-item.self {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-call-btn {
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: var(--mono);
  flex-shrink: 0;
}
.user-call-btn:hover { border-color: var(--accent); }

/* ── Call actions ── */
.call-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Media label row ── */
.media-label-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  padding: 0 4px;
}
.media-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-align: center;
}

/* ── Media grid ── */
.media-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.media-cell {
  position: relative;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
}

.media-cell-title {
  position: absolute;
  top: 8px;
  left: 10px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  z-index: 2;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.media-cell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  position: relative;
  z-index: 1;
}

.media-controls {
  position: absolute;
  top: 8px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 10;
  opacity: 1; /* Always visible as requested */
  transition: opacity 0.2s;
}

.mute-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  color: var(--red);
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  z-index: 5;
  backdrop-filter: blur(4px);
  border: 1px solid var(--red);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mute-indicator.hidden {
  display: none;
}

.media-controls .btn-icon {
  color: var(--text); /* Brighter icon for constant visibility */
  background: rgba(20, 23, 32, 0.7); /* Semi-transparent background */
}

.media-cell:hover .media-controls {
  opacity: 1;
}

.media-cell.minimized {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 280px;
  height: auto;
  aspect-ratio: 16/9;
  z-index: 1000;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  border-color: var(--accent);
  background: var(--bg);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#localCell.minimized {
  right: 320px; /* Offset if both are minimized */
}

/* If only one is minimized, keep it to the right */
#localCell.minimized:only-of-type,
#remoteCell.minimized:only-of-type {
  right: 20px;
}
/* More robust stack: if remote is NOT minimized, move local to the right */
#localCell.minimized {
  right: 20px;
}
#remoteCell.minimized ~ #localCell.minimized,
#localCell.minimized + #remoteCell.minimized {
  right: 320px;
}
/* simpler logic: just offset local if it's minimized */
#localCell.minimized { bottom: 20px; right: 20px; }
#remoteCell.minimized { bottom: 20px; right: 320px; }

@media (max-width: 700px) {
  #remoteCell.minimized { right: 20px; bottom: 150px; }
  #localCell.minimized { right: 20px; bottom: 20px; width: 180px; }
}

.media-cell.minimized .media-cell-title {
  font-size: 8px;
}

.media-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  z-index: 0;
  gap: 6px;
  line-height: 1.8;
}
.media-placeholder span { font-size: 28px; opacity: 0.3; }
.media-placeholder.hidden { display: none; }

/* ── Connection state bar ── */
.conn-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 2px;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.3s;
}
.conn-dot.connecting { background: var(--yellow); animation: pulse 1s infinite; }
.conn-dot.connected  { background: var(--accent); }
.conn-dot.failed     { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: unset;
    padding-bottom: 30px;
  }
  .panel-right {
    padding-top: 0;
  }
}

@media (max-width: 600px) {
  :root {
    --gap: 12px;
  }
  .media-grid {
    grid-template-columns: 1fr;
  }
  .media-label-row {
    display: none;
  }
  .call-actions {
    flex-direction: column;
  }
  .call-actions button {
    width: 100%;
  }
  .logo {
    justify-content: center;
  }
  .media-cell.minimized {
    width: 180px;
    bottom: 10px;
    right: 10px;
  }
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.3s;
}
.modal-backdrop.hidden {
  display: none;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  padding: 30px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  animation: modalSlide 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-header {
  margin-bottom: 20px;
}
.modal-icon {
  font-size: 40px;
  margin-bottom: 15px;
  display: block;
  animation: phoneRing 1s infinite alternate;
}
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 25px;
}
.modal-actions button {
  flex: 1;
  padding: 12px;
}

@keyframes modalSlide {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes phoneRing {
  from { transform: rotate(-10deg); }
  to { transform: rotate(10deg); }
}
