/* PeerLink — Mobile-First Accessible Stylesheet */
:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --text-dim: #94a3b8;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: rgba(20, 184, 166, 0.16);
  --accent-text: #5eead4;
  --info: #38bdf8;
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent-text);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 800;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.icon-btn:hover {
  background: #273549;
}

/* Main container */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Status Pill */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.online { background: var(--success); }
.status-dot.warn { background: var(--warn); }
.status-dot.error { background: var(--danger); }
.status-dot.pulse {
  background: var(--info);
  animation: pulse 1.4s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.transport-pill {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Cards & Buttons */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.hero-title {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
  line-height: 1.25;
}

.hero-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 680px) {
  .mode-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.mode-card {
  text-align: left;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 160px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.mode-card:hover {
  border-color: var(--accent-text);
  transform: translateY(-1px);
}

.mode-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mode-tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.mode-tag.warn {
  background: var(--warn-soft);
  color: #fcd34d;
}

.mode-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.mode-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn {
  min-height: 46px;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #273549;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.btn-block {
  width: 100%;
}

/* Forms & Inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input, .textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  min-height: 46px;
}

.textarea {
  min-height: 92px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

/* Alerts / Callouts */
.callout {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 0.88rem;
  color: var(--text-muted);
}

.callout.warn {
  border-color: rgba(245, 158, 11, 0.5);
  background: var(--warn-soft);
  color: #fde68a;
}

.callout.info {
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.1);
  color: #bae6fd;
}

/* Pairing Steps & QR */
.stepper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.step-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.step-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0;
}

.qr-box {
  background: #ffffff;
  padding: 12px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

.qr-box img, .qr-box canvas {
  display: block;
  max-width: 220px;
  height: auto;
}

.scanner-box {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin: 0.5rem auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--accent-text);
  background: #000;
}

.scanner-box video {
  width: 100%;
  display: block;
}

/* In-Call Layout (Portrait & Landscape) */
.call-layout {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}

@media (orientation: landscape) and (min-width: 760px) {
  .call-layout {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    align-items: stretch;
  }
}

.video-stage {
  position: relative;
  background: #020617;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (orientation: landscape) and (min-width: 760px) {
  .video-stage {
    aspect-ratio: auto;
    min-height: 420px;
  }
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #020617;
}

.local-video {
  position: absolute;
  right: 0.75rem;
  bottom: 4.5rem;
  width: 108px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--accent-text);
  background: #0f172a;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  z-index: 5;
}

@media (orientation: landscape) {
  .local-video {
    width: 132px;
    aspect-ratio: 16 / 9;
  }
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  color: var(--text-dim);
  padding: 1rem;
  text-align: center;
  pointer-events: none;
}

.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.6rem;
  background: linear-gradient(transparent, rgba(2, 6, 23, 0.92));
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  z-index: 6;
}

.ctrl-btn {
  min-width: 48px;
  min-height: 48px;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.ctrl-btn.active-off {
  background: #334155;
  color: #fca5a5;
  border-color: #f87171;
}

.ctrl-btn.end-call {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

/* Chat & File Panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 300px;
  max-height: 460px;
  overflow: hidden;
}

.chat-header {
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 700;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg {
  max-width: 85%;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  font-size: 0.92rem;
  word-wrap: break-word;
}

.msg.self {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.msg.peer {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.25rem 0.5rem;
}

.msg-meta {
  font-size: 0.72rem;
  opacity: 0.82;
  margin-top: 0.25rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.msg-file {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.msg-file img {
  max-width: 200px;
  max-height: 180px;
  border-radius: 8px;
  object-fit: cover;
}

.chat-compose {
  padding: 0.65rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
}

.chat-compose input[type="text"] {
  flex: 1;
  min-width: 0;
}

.transfer-bar {
  padding: 0.5rem 0.85rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.82rem;
}

.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent-text);
  width: 0%;
  transition: width 0.1s linear;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  pointer-events: auto;
}

.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }
