/* ─── Sidefire Styles ─── */
/* Mobile-first, dark mode default */

:root {
  --primary: #FF6B35;
  --primary-dim: #cc5629;
  --accent: #e94560;
  --success: #0f3460;
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-2: #1b2a4a;
  --surface-3: #223050;
  --text: #eeeeee;
  --text-muted: #8892a4;
  --text-dim: #5a6478;
  --border: #2a3550;
  --danger: #e94560;
  --imported-bg: #1e2a3e;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --surface-2: #f0f0f0;
    --surface-3: #e8e8e8;
    --text: #1a1a2e;
    --text-muted: #666;
    --text-dim: #999;
    --border: #ddd;
    --imported-bg: #f0f4f8;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

#app {
  height: 100%;
  position: relative;
}

/* ─── Screens ─── */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateX(20px);
  background: var(--bg);
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  z-index: 2;
}

.hidden { display: none !important; }

/* ─── Header ─── */

.header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  gap: 8px;
  flex-shrink: 0;
}

.header-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-room-name {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-member-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Buttons ─── */

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--surface-2);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:active {
  background: var(--surface-3);
}

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:active {
  background: rgba(233, 69, 96, 0.1);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
}

.btn-small {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.full-width { width: 100%; }

.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.4);
  cursor: pointer;
  z-index: 10;
  transition: transform 0.15s;
}

.fab:active {
  transform: scale(0.92);
}

/* ─── Login Screen ─── */

.login-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

.logo {
  text-align: center;
  margin-bottom: 48px;
}

.logo-text {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
  margin-top: 12px;
  letter-spacing: -1px;
}

.logo-tagline {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: 4px;
}

.login-step {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.phone-input-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.country-code {
  padding: 14px 12px;
  color: var(--text-muted);
  font-size: 16px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.input-group {
  width: 100%;
}

.input-group.inline {
  display: flex;
  gap: 8px;
}

.input-group.inline input {
  flex: 1;
}

input[type="text"], input[type="tel"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus, input[type="tel"]:focus {
  border-color: var(--primary);
}

.phone-input-row input {
  border: none;
  border-radius: 0;
}

.code-prompt {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.code-inputs {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.code-digit {
  width: 48px !important;
  height: 56px;
  text-align: center;
  font-size: 24px !important;
  font-weight: 700;
  padding: 8px !important;
  border-radius: var(--radius-sm) !important;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}

/* ─── Name Screen ─── */

.name-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
  gap: 16px;
}

.name-container h2 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

/* ─── Room List ─── */

.room-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  gap: 8px;
}

.room-card {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
}

.room-card:active {
  background: var(--surface-2);
}

.room-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.room-info {
  flex: 1;
  min-width: 0;
}

.room-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.room-meta {
  text-align: right;
  flex-shrink: 0;
}

.room-time {
  font-size: 11px;
  color: var(--text-dim);
}

.room-badge {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  margin-left: auto;
  margin-top: 6px;
}

.muted { color: var(--text-muted); font-size: 13px; }

/* ─── Chat Messages ─── */

.message-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  align-self: flex-end;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  padding-left: 4px;
}

.own .message-sender {
  display: none;
}

.message-bubble {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.own .message-bubble {
  background: var(--primary);
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.message-bubble.system {
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  font-style: italic;
  padding: 8px;
}

.message.system {
  align-self: center;
  max-width: 100%;
}

.message-bubble.imported {
  background: var(--imported-bg);
  border-left: 2px solid var(--text-dim);
}

.imported-tag {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

.message-image {
  max-width: 260px;
  max-height: 300px;
  border-radius: var(--radius);
  cursor: pointer;
  object-fit: cover;
}

.message-time {
  font-size: 10px;
  color: var(--text-dim);
  padding-left: 4px;
  align-self: flex-end;
}

.own .message-time {
  padding-left: 0;
  padding-right: 4px;
}

.date-separator {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px 0;
  position: relative;
}

.date-separator::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
  z-index: 0;
}

.date-separator span {
  position: relative;
  background: var(--bg);
  padding: 0 12px;
  z-index: 1;
}

/* ─── Chat Input ─── */

.chat-input-container {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 4px;
  flex-shrink: 0;
}

.chat-input-container input[type="text"] {
  flex: 1;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
}

.send-btn {
  color: var(--primary);
}

.send-btn:disabled {
  color: var(--text-dim);
}

/* ─── Typing Indicator ─── */

.typing-indicator {
  padding: 4px 16px 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  flex-shrink: 0;
}

/* ─── New Messages Pill ─── */

.new-messages-pill {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  animation: fadeIn 0.2s ease;
}

/* ─── Room Info ─── */

.room-info-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.room-info-section {
  margin-bottom: 24px;
}

.info-room-name {
  font-size: 22px;
  font-weight: 700;
}

.info-room-description {
  margin-top: 4px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h4 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.badge {
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.member-name {
  font-size: 15px;
  font-weight: 500;
}

.member-role {
  font-size: 11px;
  color: var(--text-muted);
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  margin-left: auto;
}

/* ─── Settings ─── */

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.settings-section {
  margin-bottom: 28px;
}

.settings-label {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

/* ─── Modal ─── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content h3 {
  font-size: 20px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Image Viewer ─── */

.image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 201;
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: fadeIn 0.2s ease;
}

/* ─── Loading state ─── */

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ─── Join screen inline ─── */

.join-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
  text-align: center;
}

.join-container h2 {
  font-size: 22px;
  font-weight: 700;
}

.join-container .room-preview-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}

/* ─── Login Footer Links ───────────────────────────────────────────────── */
.login-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 15px;
}

.footer-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
  font-weight: 500;
  padding: 8px 4px;
}

.footer-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.footer-sep {
  color: var(--text-muted);
  margin: 0 10px;
}

/* ─── About Screen ─────────────────────────────────────────────────────── */
.about-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px 40px;
}

.about-hero {
  text-align: center;
  margin-bottom: 32px;
}

.about-title {
  font-size: 28px;
  font-weight: 800;
  margin-top: 12px;
}

.about-tagline {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: 4px;
}

.about-section {
  margin-bottom: 28px;
}

.about-section h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--primary);
}

.about-section p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 10px;
}

.about-features {
  list-style: none;
  padding: 0;
}

.about-features li {
  padding: 8px 0;
  padding-left: 20px;
  position: relative;
  font-size: 15px;
  line-height: 1.5;
}

.about-features li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 15px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.about-features li strong {
  color: var(--text);
}

.about-footer-section {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ─── Reaction Picker ──────────────────────────────────────────────────── */
.reaction-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  /* transparent backdrop to catch taps outside */
}

.reaction-picker {
  position: absolute;
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 1000;
  animation: reactionPickerIn 0.15s ease;
}

@keyframes reactionPickerIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.reaction-picker button {
  background: none;
  border: none;
  font-size: 28px;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.1s, transform 0.1s;
  line-height: 1;
}

.reaction-picker button:hover {
  background: var(--surface-3);
  transform: scale(1.2);
}

.reaction-picker button:active {
  transform: scale(0.95);
}

/* ─── Reaction Pills (below message bubble) ───────────────────────────── */
.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding-left: 2px;
}

.own .reactions-row {
  justify-content: flex-end;
  padding-left: 0;
  padding-right: 2px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px 2px 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.reaction-pill:hover {
  background: var(--surface-3);
}

.reaction-pill.mine {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}

.reaction-pill .emoji {
  font-size: 16px;
  line-height: 1;
}

.reaction-pill .count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 8px;
  text-align: center;
}

.reaction-pill.mine .count {
  color: var(--primary);
}

/* Prevent text selection during long-press */
.message-body {
  -webkit-user-select: none;
  user-select: none;
}

.message-bubble {
  -webkit-touch-callout: none;
}
