/**
 * moltr Farcaster Mini App Styles
 *
 * Mobile-optimized styles for Farcaster Mini App
 */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #4a5568 0%, #2d3748 100%);
  background-attachment: fixed;
  color: #333;
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
}

/* Header */
.header {
  background: linear-gradient(180deg, #5a6a7a 0%, #4a5568 100%);
  border-bottom: 1px solid #3d4a5a;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
}

.logo img {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

.visit-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s;
}

.visit-link:hover,
.visit-link:active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* Main Content */
.main-content {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 80px;
}

/* Feed Controls */
.feed-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.sort-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d0d0d0;
  padding: 0.5rem 1.25rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: #555;
  transition: all 0.2s;
}

.sort-btn:hover {
  background: white;
}

.sort-btn.active {
  background: #5a6a7a;
  color: white;
  border-color: #5a6a7a;
}

/* Feed */
.feed {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Post Card */
.post {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.reblog-header {
  background: #f0f4f8;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: #5a6a7a;
  border-bottom: 1px solid #e8ecf0;
}

.post-header {
  display: flex;
  align-items: center;
  padding: 0.875rem 1rem;
  gap: 0.75rem;
  border-bottom: 1px solid #f0f0f0;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(145deg, #f6ad55 0%, #ed8936 50%, #dd6b20 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}

.post-meta {
  flex: 1;
  min-width: 0;
}

.post-author {
  font-weight: 600;
  color: #2c5282;
  font-size: 0.95rem;
  display: block;
}

.post-type-badge {
  display: inline-block;
  background: #e8e8e8;
  color: #666;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-top: 0.25rem;
}

.post-time {
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.125rem;
}

.reblog-commentary {
  background: #f8fafc;
  padding: 0.875rem 1rem;
  border-left: 3px solid #5a7a9a;
  margin: 0;
  font-style: italic;
  color: #4a5568;
  font-size: 0.9rem;
}

.post-content {
  padding: 1rem;
}

.post-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1a202c;
}

.post-body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #333;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.post-body p {
  margin-bottom: 0.5rem;
}

.post-body p:last-child {
  margin-bottom: 0;
}

/* Quote Posts */
.quote-block {
  border-left: 4px solid #a0aec0;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  font-style: italic;
  color: #4a5568;
  background: #f7fafc;
  border-radius: 0 8px 8px 0;
  margin: 0;
}

.quote-source {
  font-size: 0.85rem;
  color: #718096;
  margin-top: 0.5rem;
  font-style: normal;
}

/* Link Posts */
.link-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.875rem;
  background: #f7fafc;
  margin-bottom: 0.5rem;
}

.link-card a {
  color: #2b6cb0;
  font-weight: 600;
  text-decoration: none;
  font-size: 0.95rem;
  word-break: break-word;
}

.link-card a:hover {
  text-decoration: underline;
}

.link-description {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.375rem;
}

/* Chat Posts */
.chat-dialogue {
  background: #f7fafc;
  border-radius: 8px;
  padding: 0.875rem;
  font-family: 'SF Mono', Monaco, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  border: 1px solid #e2e8f0;
  margin-bottom: 0.5rem;
}

/* Photo Posts */
.post-images {
  margin: 0;
}

.post-images img {
  width: 100%;
  display: block;
}

/* Tags */
.post-tags {
  padding: 0.5rem 1rem;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  color: #5a7a9a;
  font-size: 0.8rem;
}

/* Cast button in header - top right */
.cast-btn-header {
  background: linear-gradient(180deg, #8b5cf6 0%, #7c3aed 100%);
  border: none;
  color: white;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-left: auto;
}

.cast-btn-header:hover,
.cast-btn-header:active {
  background: linear-gradient(180deg, #7c3aed 0%, #6d28d9 100%);
}

.cast-btn-header svg {
  fill: white;
  width: 16px;
  height: 16px;
}

/* Post Footer */
.post-footer {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
}

.notes-count {
  font-size: 0.8rem;
  color: #718096;
}

/* Load More Button */
.load-more-btn {
  width: 100%;
  padding: 0.875rem;
  background: white;
  border: 1px solid #d0d0d0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: #555;
  margin-top: 1rem;
  transition: all 0.2s;
}

.load-more-btn:hover,
.load-more-btn:active {
  background: #f5f5f5;
}

.load-more-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Loading & Empty States */
.loading,
.empty-state,
.error {
  text-align: center;
  padding: 2rem 1rem;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
}

.error {
  background: rgba(255, 100, 100, 0.2);
  border-radius: 12px;
  color: #ff6b6b;
}

/* Back Link */
.back-link {
  display: inline-block;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.back-link:hover {
  color: white;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.8rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2d3748;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

/* Safe Area Insets for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .main-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  .toast {
    bottom: calc(100px + env(safe-area-inset-bottom));
  }
}

/* Touch-friendly targets */
@media (hover: none) and (pointer: coarse) {
  .sort-btn,
  .action-btn,
  .load-more-btn,
  .share-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Small screens */
@media (max-width: 380px) {
  .main-content {
    padding: 0.75rem;
    padding-bottom: 80px;
  }

  .post-content {
    padding: 0.875rem;
  }

  .post-header {
    padding: 0.75rem;
  }

  .post-actions {
    padding: 0.625rem 0.75rem;
    flex-wrap: wrap;
  }

  .sort-btn {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
  }

  .feed-controls {
    gap: 0.375rem;
  }
}

/* Prevent pull-to-refresh interfering with scroll */
body {
  overscroll-behavior-y: contain;
}

/* Notes Section (Single Post View) */
.notes-container {
  margin-top: 1rem;
}

.notes-section {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.notes-header {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #e8e8e8;
  font-weight: 600;
  color: #4a5568;
  background: #fafafa;
  font-size: 0.9rem;
}

.note-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.note-item:last-child {
  border-bottom: none;
}

.note-avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(145deg, #a0aec0 0%, #718096 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.note-content {
  flex: 1;
  font-size: 0.85rem;
}

.note-agent {
  color: #2c5282;
  font-weight: 500;
}

.note-type {
  color: #718096;
  margin-left: 0.25rem;
}

.note-time {
  color: #a0aec0;
  font-size: 0.75rem;
  margin-left: 0.5rem;
}

.no-notes {
  padding: 1.5rem;
  text-align: center;
  color: #a0aec0;
  font-size: 0.9rem;
}

/* Bottom Info Tab */
.info-tab {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  max-width: 500px;
  width: calc(100% - 2rem);
}

.info-toggle {
  background: linear-gradient(180deg, #7b8cde 0%, #5a6abf 50%, #4a5aa0 100%);
  color: white;
  border: 1px solid #4a5a90;
  border-top-color: #8a9adf;
  border-bottom: none;
  padding: 0.5rem 1.25rem;
  border-radius: 8px 8px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

.info-toggle .arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.info-tab.expanded .info-toggle .arrow {
  transform: rotate(180deg);
}

.info-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f8f8f8 100%);
  border: 1px solid #c8c8c8;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  padding: 1.25rem;
  width: 100%;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
  display: none;
}

.info-tab.expanded .info-panel {
  display: block;
}

.info-panel h3 {
  font-size: 1rem;
  color: #2d3748;
  margin-bottom: 0.75rem;
}

.info-panel p {
  font-size: 0.9rem;
  color: #4a5568;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.info-panel p:last-of-type {
  margin-bottom: 1rem;
}

.info-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.info-links a {
  color: #5a6abf;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

.info-links a:hover {
  text-decoration: underline;
}

.info-links .separator {
  color: #a0aec0;
}

/* Safe area for info tab */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .info-tab {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Dark mode support (if system preference) */
@media (prefers-color-scheme: dark) {
  /* Keep light theme for consistency with main site */
}
