/* ============================================
   Link2 — Flat zinc + blue accent
   Monochrome utility UI (no teal/green brand).
   ============================================ */

:root {
  /* Brand — zinc + blue CTA */
  --primary: #2563eb;
  --primary-hover: #3b82f6;
  --primary-active: #1d4ed8;
  --primary-subtle: rgba(37, 99, 235, 0.1);
  --primary-glow: rgba(37, 99, 235, 0.18);
  --accent: #2563eb;

  /* Surfaces — neutral zinc */
  --bg-primary: #fafafa;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #e4e4e7;
  --bg-elevated: #ffffff;
  --bg-chat: #fafafa;
  --bg-received-start: #ffffff;
  --bg-received-end: #f4f4f5;
  --bg-received-subtle: rgba(24, 24, 27, 0.06);
  --bg-received-subtle-hover: rgba(24, 24, 27, 0.1);
  --bg-received-icon: rgba(24, 24, 27, 0.06);
  --bg-received-frame: #f4f4f5;
  --bg-mine: #eef2ff;
  --bg-mine-border: rgba(37, 99, 235, 0.16);
  --bg-system: rgba(24, 24, 27, 0.05);

  /* Text */
  --text-primary: #09090b;
  --text-secondary: #52525b;
  --text-tertiary: #a1a1aa;
  --text-inverse: #ffffff;
  --text-on-primary: #ffffff;

  /* Semantic (status only — not brand) */
  --success: #22c55e;
  --success-subtle: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-subtle: rgba(245, 158, 11, 0.12);
  --error: #ef4444;
  --error-subtle: rgba(239, 68, 68, 0.1);
  --info: #2563eb;

  /* Borders */
  --border: rgba(24, 24, 27, 0.1);
  --border-strong: rgba(24, 24, 27, 0.16);
  --border-focus: var(--primary);
  --border-received: rgba(24, 24, 27, 0.08);

  /* Shadows — flat, subtle */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.1);
  --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);

  /* Typography — system stack (no external font dependency) */
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-full: 9999px;

  --transition-fast: 150ms ease;
  --transition-base: 180ms ease;
  --transition-slow: 220ms ease;

  --z-base: 1;
  --z-elevated: 10;
  --z-dropdown: 100;
  --z-modal: 1000;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-active: #2563eb;
    --primary-subtle: rgba(59, 130, 246, 0.14);
    --primary-glow: rgba(59, 130, 246, 0.22);
    --accent: #3b82f6;

    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    --bg-elevated: #18181b;
    --bg-chat: #09090b;
    --bg-received-start: #27272a;
    --bg-received-end: #1f1f23;
    --bg-received-subtle: rgba(255, 255, 255, 0.08);
    --bg-received-subtle-hover: rgba(255, 255, 255, 0.12);
    --bg-received-icon: rgba(255, 255, 255, 0.08);
    --bg-received-frame: #1f1f23;
    --bg-mine: rgba(59, 130, 246, 0.14);
    --bg-mine-border: rgba(59, 130, 246, 0.28);
    --bg-system: rgba(255, 255, 255, 0.06);

    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --text-on-primary: #ffffff;

    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.16);
    --border-received: rgba(255, 255, 255, 0.08);

    --shadow-xs: none;
    --shadow-sm: none;
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.45);
    --shadow-panel: 0 0 0 1px var(--border);
  }
}

/* Reset & Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

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

img, svg {
  display: block;
}

/* ============================================
   Layout
   ============================================ */

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

body[data-view="chat"] .app {
  align-items: stretch;
  padding: 0;
}

.panel {
  width: 100%;
  max-width: 420px;
  min-height: 520px;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-view="chat"] .panel {
  max-width: 840px;
  min-height: 100vh;
  height: 100vh;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: var(--bg-elevated);
}

/* ============================================
   Brand / Header
   ============================================ */

.brand {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.brand-logo h1 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.logo-mark {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text-primary);
  border-radius: var(--radius-md);
  color: var(--bg-elevated);
  position: relative;
  overflow: hidden;
}

.logo-mark svg {
  width: 18px;
  height: 18px;
}

.brand-status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  min-height: 44px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  padding: var(--space-2) 0;
}

.status-indicator.large {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--text-tertiary);
  transition: background var(--transition-base);
  box-shadow: 0 0 0 4px transparent;
}

.status-dot[data-status="idle"] {
  background: var(--text-tertiary);
}

.status-dot[data-status="ready"] {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-subtle);
}

.status-dot[data-status="connecting"] {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

.status-dot[data-status="connected"] {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-subtle);
}

.status-dot[data-status="error"] {
  background: var(--error);
}

.status-dot[data-status="waiting"] {
  background: var(--warning);
  animation: pulse 2s infinite;
  box-shadow: 0 0 0 4px var(--warning-subtle);
}

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

.status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-value {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

.status-detail {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

.status-message {
  font-size: var(--font-size-base);
  color: var(--text-secondary);
}

.room-badge {
  padding: 5px 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.room-badge:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-tertiary);
}

.brand-actions {
  display: flex;
  gap: var(--space-2);
}

/* ============================================
   Views
   ============================================ */

.view {
  display: none;
  flex: 1;
  overflow: hidden;
}

.view.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn var(--transition-slow);
}

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

.view-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-6);
  gap: var(--space-5);
  overflow-y: auto;
}



/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-5);
  font-size: var(--font-size-base);
  font-weight: 600;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  transition: background var(--transition-base), color var(--transition-base),
    border-color var(--transition-base), box-shadow var(--transition-base);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.btn .btn-text {
  color: inherit;
  font: inherit;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: none;
}

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

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border-strong));
}

.btn-danger {
  background: var(--error-subtle);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 18%, transparent);
}

.btn-danger:hover {
  background: var(--error);
  color: var(--text-inverse);
  border-color: var(--error);
}

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

/* display:inline-flex / flex utilities must never override the hidden attribute */
[hidden],
.btn-icon[hidden],
.btn-text[hidden],
.brand-actions > [hidden],
.brand-actions button[hidden],
button[hidden],
.room-badge[hidden] {
  display: none !important;
}

.btn-icon:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-icon:active {
  background: var(--bg-tertiary);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  transition: all var(--transition-base);
}

.btn-text:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.btn-leave {
  border: 1px solid color-mix(in srgb, var(--error) 14%, transparent);
  background: var(--error-subtle);
  color: var(--error);
}

.btn-leave:hover {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 16%, transparent);
  border-color: color-mix(in srgb, var(--error) 28%, transparent);
}

.btn-leave svg {
  flex-shrink: 0;
}

/* ============================================
   Forms & Inputs
   ============================================ */

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-4);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
  appearance: none;
  -webkit-appearance: none;
}

.input::placeholder {
  color: var(--text-tertiary);
}

.input:hover {
  border-color: var(--border-strong);
  background: var(--bg-secondary);
}

.input:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px var(--primary-subtle);
}

.input:invalid:not(:placeholder-shown) {
  border-color: var(--error);
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.input-group {
  display: flex;
  gap: var(--space-3);
  align-items: stretch;
}

.input-group .input {
  flex: 1;
}

.join-form {
  width: 100%;
}

.join-form .input-group {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-1);
  transition: all var(--transition-base);
}

.join-form .input-group:focus-within {
  background: var(--bg-elevated);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-subtle);
}

.join-form .input {
  background: transparent;
  border: none;
  min-height: 44px;
}

.join-form .input:focus {
  box-shadow: none;
}

.join-form .btn {
  flex-shrink: 0;
  min-width: 88px;
  font-weight: 600;
}

/* ============================================
   Home View
   ============================================ */

.home-content {
  justify-content: center !important;
  padding: var(--space-8) var(--space-5) !important;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.action-group > .btn {
  width: 100%;
  min-height: 48px;
  font-size: var(--font-size-base);
}

.join-form {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

/* ============================================
   Room View
   ============================================ */

.room-display {
  text-align: center;
  padding: var(--space-4) var(--space-6);
  flex-shrink: 0;
}

.label {
  display: block;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

.room-code-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.room-code-display strong {
  font-size: var(--font-size-4xl);
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.room-code-display .btn-icon {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  opacity: 0.6;
  transition: all var(--transition-base);
}

.room-code-display .btn-icon:hover {
  opacity: 1;
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
}

.connection-status {
  padding: var(--space-4);
  text-align: center;
  flex-shrink: 0;
}

.room-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 420px;
  margin: var(--space-4) auto 0;
  flex-shrink: 0;
}

.room-actions .btn {
  flex: 1;
  min-width: 140px;
  max-width: 200px;
}

.room-actions button[hidden] {
  display: none;
}

/* ============================================
   Chat View
   ============================================ */

.catch-up-panel {
  flex: 0 0 auto;
  margin: var(--space-3) var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
}

.catch-up-panel[hidden] {
  display: none;
}

.catch-up-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  font-weight: 600;
  color: var(--text-primary);
}

.catch-up-list {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.catch-up-item {
  margin: 0;
}

.catch-up-label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  cursor: pointer;
}

.catch-up-label input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
}

.catch-up-label input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.catch-up-text {
  flex: 1 1 auto;
  word-break: break-word;
  color: var(--text-secondary);
}

.catch-up-label:has(input:disabled) .catch-up-text {
  color: var(--text-tertiary);
}

.catch-up-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.catch-up-actions .btn {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--font-size-sm);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: stretch;
  scroll-behavior: smooth;
  background: var(--bg-chat);
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

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

.message {
  flex: 0 0 auto;
  max-width: min(78%, 420px);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  animation: slideIn var(--transition-base);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

.message:not(.mine):not(.system) {
  align-self: flex-start;
  background: var(--bg-received-start);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-received);
  box-shadow: var(--shadow-xs);
}

.message.mine {
  align-self: flex-end;
  background: var(--bg-mine);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid var(--bg-mine-border);
  box-shadow: var(--shadow-xs);
}

.message.system {
  align-self: center;
  max-width: 92%;
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 0;
  border: none;
  margin: var(--space-1) 0;
  text-align: center;
}

.text-message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.message-body {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

.copy-message {
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition-base);
  font-size: var(--font-size-xs);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-received-subtle);
  border-radius: var(--radius-sm);
}

.message:hover .copy-message {
  opacity: 0.7;
}

.copy-message:hover {
  opacity: 1 !important;
  background: var(--bg-received-subtle-hover);
}

.message.mine .copy-message {
  background: var(--primary-subtle);
  color: var(--primary);
}

.message.mine .copy-message:hover {
  background: color-mix(in srgb, var(--primary) 18%, transparent);
}

/* File Messages */
.file-message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: center;
  padding: 14px 16px;
  max-width: 340px;
  width: min(100%, 340px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  margin-top: 0;
  margin-bottom: 0;
  background: var(--bg-elevated);
}

.file-message:not(.mine) {
  background: linear-gradient(180deg, var(--bg-received-start) 0%, var(--bg-received-end) 100%);
  border-color: var(--border-received);
}

.file-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-received-icon);
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.message.mine .file-icon {
  background: var(--primary-subtle);
  color: var(--primary);
}

.message.mine.file-message {
  background: var(--bg-mine);
  color: var(--text-primary);
  border-color: var(--bg-mine-border);
  box-shadow: var(--shadow-xs);
}

.file-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.transfer-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transfer-state {
  font-size: var(--font-size-xs);
  opacity: 0.8;
}

.file-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.file-message progress {
  grid-column: 1 / -1;
  margin-top: var(--space-2);
}

.file-message:not(.complete) .file-actions {
  display: none;
}

.file-download {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background: var(--bg-received-subtle);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 500;
  text-decoration: none;
  color: inherit;
  transition: all var(--transition-base);
}

.file-download:hover {
  background: var(--bg-received-subtle-hover);
}

.message.mine .file-download {
  background: var(--primary-subtle);
  color: var(--primary);
}

.message.mine .file-download:hover {
  background: color-mix(in srgb, var(--primary) 18%, transparent);
}

/* Image Messages */
.image-message {
  width: fit-content;
  max-width: min(56%, 460px);
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, var(--bg-received-start) 0%, var(--bg-received-end) 100%);
  border: 1px solid var(--border-received);
  box-shadow: var(--shadow-sm);
  margin-top: 0;
  margin-bottom: 0;
}

.image-message.mine {
  background: var(--bg-mine);
  color: var(--text-primary);
  border-color: var(--bg-mine-border);
  box-shadow: var(--shadow-sm);
}

.image-message.portrait {
  max-width: min(36%, 300px);
}

.image-message.landscape {
  max-width: min(56%, 460px);
}

.image-frame {
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow: hidden;
  background: var(--bg-received-frame);
  max-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.image-message img {
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
  object-position: center;
  background: var(--bg-primary);
}

.image-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  font-size: var(--font-size-xs);
  gap: var(--space-2);
  background: transparent;
  border-top: 1px solid var(--border-received);
  color: var(--text-secondary);
}

.image-footer span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.image-footer a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-received-subtle);
  color: var(--text-primary);
  font-weight: 600;
  text-decoration: none;
  flex-shrink: 0;
}

.image-footer a:hover {
  background: var(--bg-received-subtle-hover);
}

.image-message.mine .image-footer {
  background: transparent;
}

.image-message.mine .image-footer a {
  background: var(--primary-subtle);
  color: var(--primary);
}

/* Progress Bars */
progress {
  width: 100%;
  height: 6px;
  border: none;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.1);
  margin-top: var(--space-3);
}

progress::-webkit-progress-bar {
  background: rgba(0, 0, 0, 0.1);
}

progress::-webkit-progress-value {
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

progress::-moz-progress-bar {
  background: var(--primary);
  border-radius: var(--radius-full);
}

.message.mine progress {
  background: rgba(255, 255, 255, 0.2);
}

.message.mine progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.2);
}

.message.complete progress {
  display: none;
}

/* Message Form */
.message-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.file-trigger {
  flex-shrink: 0;
  color: var(--text-secondary);
  background: transparent;
  box-shadow: none;
}

.file-trigger:hover {
  color: var(--primary);
  background: var(--primary-subtle);
}

.file-trigger:active {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
}

.file-trigger:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* label.file-trigger is not a button — force full centering of the clip icon */
.message-form .file-trigger.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-md);
  line-height: 0;
}

.message-form .file-trigger.btn-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  margin: 0;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.message-input {
  flex: 1;
  min-height: 44px;
  max-height: 132px;
  padding: 10px 14px;
  font-size: var(--font-size-base);
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  resize: none;
  transition: background var(--transition-base), border-color var(--transition-base),
    box-shadow var(--transition-base);
  appearance: none;
  -webkit-appearance: none;
}

.message-input:hover {
  border-color: var(--border-strong);
}

.message-input:focus {
  outline: none;
  background: var(--bg-elevated);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.btn-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-md);
  line-height: 0;
}

.btn-send svg {
  display: block;
  width: 18px;
  height: 18px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 640px) {
  .app {
    padding: 0;
  }

  .panel {
    max-width: 100%;
    min-height: 100vh;
    border-radius: 0;
  }

  body[data-view="chat"] .panel {
    min-height: 100vh;
  }

  .brand {
    padding: var(--space-4) var(--space-5);
  }

  .brand-status {
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  .room-badge[hidden] {
    display: none;
  }

  .view-content {
    padding: var(--space-6) var(--space-5);
  }

  .room-code-display strong {
    font-size: var(--font-size-3xl);
  }

  .input-group {
    flex-direction: column;
  }

  .input-group .input,
  .input-group .btn {
    width: 100%;
  }

  .message {
    max-width: 85%;
  }

  .file-message {
    max-width: 85%;
    width: 85%;
  }

  .image-message {
    max-width: 82%;
  }

  .image-message.portrait {
    max-width: 58%;
  }
}

@media (max-width: 480px) {
  .message-form {
    padding: var(--space-3);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }

  .btn-icon {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }
}

/* Accessibility: reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .status-dot[data-status="connecting"],
  .status-dot[data-status="waiting"] {
    animation: none;
  }
}

/* Selection */
::selection {
  background: color-mix(in srgb, var(--primary) 28%, transparent);
  color: var(--text-primary);
}
