/* ==========================================================================
   P2P Sync & File Share - Ultra-Clean Mobile-First Stylesheet (v3.0)
   ========================================================================== */

:root {
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Premium Dark Palette */
  --bg-app: #090d16;
  --bg-header: rgba(13, 19, 33, 0.85);
  --bg-card: rgba(20, 29, 49, 0.7);
  --bg-bubble-recv: rgba(26, 37, 63, 0.8);
  --bg-bubble-sent: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --bg-input: rgba(15, 23, 42, 0.8);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.4);

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);

  --accent: #38bdf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);

  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Theme overrides */
body.light-theme {
  --bg-app: #f1f5f9;
  --bg-header: rgba(255, 255, 255, 0.9);
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-bubble-recv: #ffffff;
  --bg-bubble-sent: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --bg-input: #ffffff;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.5);

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.08);
}

/* Base Reset & Layout */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(circle at 10% 10%, rgba(99, 102, 241, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 90% 90%, rgba(56, 189, 248, 0.09) 0%, transparent 45%);
  background-attachment: fixed;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==================== APP HEADER ==================== */
.app-header {
  height: 60px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #6366f1 0%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Room Capsule Pill in Header */
.room-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  transition: var(--transition);
}

.room-pill-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

.room-pill-code {
  font-family: monospace;
  letter-spacing: 0.05em;
}

.qr-mini-icon {
  color: var(--accent);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  color: var(--text-main);
  background: var(--bg-card);
  border-color: var(--border-subtle);
}

.btn-pwa-install {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

/* ==================== SEGMENTED TABS NAV ==================== */
.tabs-nav {
  display: flex;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.4rem 1rem;
  gap: 0.5rem;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 3px 12px var(--primary-glow);
}

/* ==================== MAIN CONTENT AREA ==================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
}

/* ==================== TAB 1: CLIPBOARD MESSENGER FEED ==================== */
.toolbar-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.4);
  flex-shrink: 0;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--text-muted);
  transition: var(--transition);
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--success);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

.toggle-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-text-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.775rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-xs);
  transition: var(--transition);
}

.btn-text-action:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Messages Feed (Scrollable chat history) */
.messages-feed {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  -webkit-overflow-scrolling: touch;
}

/* Empty State */
.empty-state {
  margin: auto;
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 320px;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.empty-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.empty-desc {
  font-size: 0.825rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Chat-style Bubble Item */
.history-item {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  background: var(--bg-bubble-recv);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-xs);
  padding: 0.75rem 0.95rem;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  align-self: flex-start;
  animation: slideUp 0.2s ease;
}

.history-item.sent {
  align-self: flex-end;
  background: var(--bg-bubble-sent);
  border-color: transparent;
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-xs);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.history-item.sent .history-header {
  color: rgba(255, 255, 255, 0.75);
}

.history-item.sent .history-content {
  color: #ffffff;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.725rem;
  color: var(--text-muted);
}

.history-content {
  font-size: 0.9rem;
  color: var(--text-main);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
}

.history-img {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  margin-top: 0.25rem;
}

.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.btn-copy-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
}

.btn-copy-item:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Bottom Composer Bar */
.composer-container {
  padding: 0.65rem 1rem;
  background: var(--bg-header);
  border-top: 1px solid var(--border-subtle);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom));
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.35rem 0.5rem;
  transition: var(--transition);
}

.composer-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.composer-btn-paste {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.5rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.composer-btn-paste:hover {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.composer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.925rem;
  line-height: 1.4;
  padding: 0.45rem 0.25rem;
  resize: none;
  max-height: 110px;
}

.composer-btn-send {
  background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 10px var(--primary-glow);
  transition: var(--transition);
}

.composer-btn-send:hover {
  transform: scale(1.05);
}

.composer-btn-send:active {
  transform: scale(0.95);
}

/* Image preview container above composer */
.image-preview-container {
  display: none;
  position: relative;
  background: var(--bg-card);
  border: 1px dashed var(--border-highlight);
  border-radius: var(--radius-sm);
  padding: 0.4rem;
  margin-bottom: 0.5rem;
  text-align: center;
  max-height: 150px;
  overflow: hidden;
}

.image-preview-container.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview-container img {
  max-height: 130px;
  border-radius: var(--radius-xs);
  object-fit: contain;
}

.btn-remove-img {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* ==================== TAB 2: FILE TRANSFER (AIRDROP STYLE) ==================== */
.file-transfer-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.dropzone {
  border: 2px dashed var(--border-highlight);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
}

.dropzone:hover, .dropzone.dragover {
  background: rgba(99, 102, 241, 0.08);
  border-color: var(--accent);
  transform: scale(1.01);
}

.dropzone-glow-ring {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 25px rgba(99, 102, 241, 0.2);
}

.dropzone-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
}

.dropzone-text h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.dropzone-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.queue-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
  padding-bottom: 0.25rem;
}

.transfer-queue {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.transfer-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.transfer-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.file-details {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  overflow: hidden;
}

.file-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.file-meta {
  font-size: 0.725rem;
  color: var(--text-muted);
}

.transfer-stats {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-full);
  transition: width 0.15s ease;
}

/* ==================== MODALS (SLIDE UP / CENTER) ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  padding: 1rem;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-md);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  text-align: center;
  transform: scale(0.95);
  transition: transform 0.22s ease;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.qr-frame {
  background: white;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  display: inline-block;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.qr-frame img {
  display: block;
  width: 200px;
  height: 200px;
}

.modal-room-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-room-number {
  color: var(--accent);
  font-family: monospace;
}

.modal-actions-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.modal-divider {
  width: 100%;
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0.25rem 0;
}

.modal-divider::before, .modal-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-divider span {
  padding: 0 0.5rem;
}

.modal-join-box {
  display: flex;
  width: 100%;
  gap: 0.4rem;
}

.modal-join-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-main);
  outline: none;
  font-family: monospace;
}

.modal-join-input:focus {
  border-color: var(--primary);
}

/* Settings Form */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.5rem;
}

.settings-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.settings-select, .settings-input {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  width: 100%;
  font-family: inherit;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
  width: 90%;
  max-width: 360px;
}

.toast {
  background: var(--bg-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.6rem 1.1rem;
  font-size: 0.825rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
  pointer-events: auto;
  animation: popIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.info { border-color: var(--accent); color: var(--text-main); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@keyframes popIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Generic Button helpers */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
  color: white;
}

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

.flex-1 { flex: 1; }
