/* Copy-paste opera — styles
 * Aesthetic: Editorial warmth — parchment ground, ink type, electric accent
 * Fonts: Syne (headings/ui) + DM Mono (tokens/code)
 */

/* ─── Reset & Variables ───────────────────────────────────────────────────── */

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

:root {
  --bg: #F7F4EF;
  --bg-card: #FFFFFF;
  --bg-hover: #F0EDE7;
  --ink: #1C1917;
  --ink-soft: #78716C;
  --ink-faint: #C2BBAF;
  --accent: #5B4FE8;
  --accent-hover: #4A3FD6;
  --accent-soft: #EEF0FC;
  --success: #16A34A;
  --success-soft: #DCFCE7;
  --warning: #D97706;
  --warning-soft: #FEF3C7;
  --error: #DC2626;
  --error-soft: #FEE2E2;
  --border: #E5E1D8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(28,25,23,0.06), 0 4px 20px rgba(28,25,23,0.06);
  --shadow-card: 0 2px 8px rgba(28,25,23,0.08), 0 16px 48px rgba(28,25,23,0.08);
  --font-sans: 'Syne', system-ui, sans-serif;
  --font-mono: 'DM Mono', 'Fira Code', monospace;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Base ────────────────────────────────────────────────────────────────── */

html {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Grain overlay for warmth */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
  z-index: 9999;
}

.mono {
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ─── Views ───────────────────────────────────────────────────────────────── */

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

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

/* ─── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.app-header-mobile {
  justify-content: center;
  border-bottom: none;
  padding-bottom: 0;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  flex-grow: 1;
}

/* ─── Status pill ─────────────────────────────────────────────────────────── */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 100px;
  background: var(--bg-hover);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

.status-ready .status-dot {
  background: var(--accent);
  opacity: 1;
  animation: pulse 2s infinite;
}

.status-session .status-dot {
  background: var(--success);
  opacity: 1;
}

.status-connected {
  background: var(--success-soft);
  color: var(--success);
}

.status-connected .status-dot {
  background: var(--success);
  opacity: 1;
}

.status-disconnected { color: var(--warning); }
.status-error { color: var(--error); }

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

/* ─── Waiting view ────────────────────────────────────────────────────────── */

.waiting-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 48px 24px;
}

.qr-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transition: transform var(--transition), box-shadow var(--transition);
}

.qr-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(28,25,23,0.1), 0 24px 64px rgba(28,25,23,0.1);
}

.qr-image {
  display: block;
  border-radius: 6px;
  width: 220px;
  height: 220px;
}

.qr-hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.device-token-label {
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.device-token-label .mono {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* ─── Paired view ─────────────────────────────────────────────────────────── */

.paired-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  padding: 32px;
  gap: 16px;
  min-height: 0;
}

.panel-send {
  border-right: 1px solid var(--border);
}

.panel-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.panel-label i {
  width: 14px;
  height: 14px;
}

/* ─── Send area ───────────────────────────────────────────────────────────── */

.send-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.send-area:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.send-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--ink);
  background: transparent;
  line-height: 1.6;
  min-height: 120px;
}

textarea::placeholder {
  color: var(--ink-faint);
}

.send-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ─── Image preview ───────────────────────────────────────────────────────── */

.image-preview-wrap {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 160px;
}

.image-preview-wrap img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.btn-remove-image {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(28,25,23,0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-remove-image i {
  width: 14px;
  height: 14px;
}

/* ─── Receive area ────────────────────────────────────────────────────────── */

.receive-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.receive-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--ink-faint);
  padding: 48px 24px;
  text-align: center;
}

.receive-empty i {
  width: 32px;
  height: 32px;
  opacity: 0.4;
}

.receive-empty p {
  font-size: 0.85rem;
  max-width: 200px;
  line-height: 1.5;
}

.receive-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slideIn 0.25s ease;
}

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

.receive-text {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
  line-height: 1.6;
}

.receive-image {
  width: 100%;
  border-radius: 6px;
  display: block;
  max-height: 300px;
  object-fit: contain;
  background: var(--bg);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn i {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  opacity: 0.5;
  margin-left: 2px;
}

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

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

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

.btn-ghost {
  background: var(--bg-hover);
  color: var(--ink-soft);
}

.btn-ghost:hover {
  background: var(--border);
  color: var(--ink);
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 0.95rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.btn-icon i {
  width: 16px;
  height: 16px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.btn-disconnect:hover {
  background: var(--error-soft);
  color: var(--error);
}

.btn-copy {
  align-self: flex-start;
}

/* ─── Mobile view ─────────────────────────────────────────────────────────── */

.view-mobile {
  background: var(--bg);
}

.mobile-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

.pair-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.pair-device-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.pair-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.pair-icon i {
  width: 26px;
  height: 26px;
}

.pair-connecting-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}

.pair-device-token {
  font-size: 1rem;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.pair-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.btn-new-group {
  color: var(--ink-soft);
  background: transparent;
}

.btn-new-group:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.session-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.04em;
}

/* ─── Mobile success view ─────────────────────────────────────────────────── */

.pair-card-success {
  text-align: center;
  align-items: center;
}

.success-icon {
  color: var(--success);
}

.success-icon i {
  width: 48px;
  height: 48px;
}

.success-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.success-body {
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.6;
  max-width: 260px;
}

.session-id-display {
  font-size: 0.72rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* ─── Notifications ───────────────────────────────────────────────────────── */

.notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-card);
  z-index: 1000;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  pointer-events: none;
}

.notification.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.notification-success {
  background: var(--success);
}

.notification-error {
  background: var(--error);
}

.notification-warning {
  background: var(--warning);
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-header {
    padding: 16px 20px;
  }

  .paired-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }

  .panel-send {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel {
    padding: 20px;
  }

  .waiting-main {
    padding: 32px 20px;
  }

  .qr-card {
    padding: 24px;
  }
}

@media (max-width: 480px) {
  .pair-card {
    padding: 24px 20px;
  }
}
