/* ============================================
   YapApp — Mobile-first PWA Styles
   ============================================ */

:root {
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --primary-dark: #5541D7;
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --text: #2D3436;
  --text-muted: #888;
  --border: #E9ECEF;
  --danger: #E74C3C;
  --success: #27AE60;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
}

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

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 56px;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#header-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

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

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

/* ============================================
   Avatars
   ============================================ */

.avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: white;
  font-weight: 700;
  font-size: 14px;
}

.avatar-large.avatar-placeholder {
  font-size: 32px;
}

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

.hidden { display: none !important; }

.page-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 16px;
  text-align: center;
  min-height: 50vh;
}

.page-pad {
  padding: 16px;
}

.text-muted { color: var(--text-muted); }
.text-small { font-size: 13px; }
.subtitle { color: var(--text-muted); font-size: 15px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

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

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
}

.btn-google {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ============================================
   Landing
   ============================================ */

.landing-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--primary);
  color: white;
  font-size: 40px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Auth Form (landing page)
   ============================================ */

.auth-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-full {
  width: 100%;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
}

.auth-error {
  text-align: center;
  font-size: 13px;
  color: var(--danger);
  padding: 8px;
  border-radius: var(--radius-sm);
  background: rgba(231, 76, 60, 0.08);
}

/* ============================================
   Forms
   ============================================ */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

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

/* ============================================
   Topic list
   ============================================ */

.topic-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topic-card {
  display: block;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s;
}

.topic-card:active { transform: scale(0.98); }

.topic-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.topic-card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.topic-card-desc {
  margin-top: 4px;
  font-size: 14px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.topic-card-footer {
  margin-top: 8px;
}

/* ============================================
   FAB (floating action button)
   ============================================ */

.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
  transition: transform 0.15s;
  z-index: 50;
}

.fab:active { transform: scale(0.9); }

/* ============================================
   Topic view / Posts
   ============================================ */

.topic-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topic-desc-bar {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
}

.posts-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 140px;
}

.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.post-author {
  font-size: 14px;
  font-weight: 600;
}

.post-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.post-body {
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-photo-wrap {
  margin: 8px -14px;
}

.post-photo {
  width: 100%;
  display: block;
  max-height: 400px;
  object-fit: cover;
}

.post-location {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.post-location::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E") no-repeat center;
}

/* ============================================
   Reactions
   ============================================ */

.reaction-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 32px;
}

.reaction-btn:active { transform: scale(0.92); }

.reaction-btn.active {
  border-color: var(--primary-light);
  background: rgba(108, 92, 231, 0.08);
}

.reaction-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ============================================
   Replies
   ============================================ */

.replies-section {
  margin-top: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reply {
  padding-top: 8px;
}

.reply .post-header {
  margin-bottom: 4px;
}

.reply .avatar-small {
  width: 24px;
  height: 24px;
}

.btn-reply {
  margin-top: 8px;
  border: none;
  background: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

/* ============================================
   Post form
   ============================================ */

.post-form-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  z-index: 90;
}

.post-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-form-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.post-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

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

.photo-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}

.post-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.location-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.location-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* Photo preview */
.photo-preview-item {
  position: relative;
  display: inline-block;
}

.photo-preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.photo-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Reply indicator */
#reply-indicator {
  font-size: 13px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cancel-reply {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

/* Sign in prompt */
.sign-in-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ============================================
   Profile page
   ============================================ */

.profile-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding-top: 40px;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-card h2 {
  font-size: 22px;
}

/* ============================================
   Toast
   ============================================ */

.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
  pointer-events: none;
}

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

/* ============================================
   Spinner
   ============================================ */

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Scrollbar (subtle)
   ============================================ */

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

/* ============================================
   Main content area
   ============================================ */

#app-content {
  flex: 1;
  overflow-y: auto;
}
