/* === CSS Variables — Telegram Theme Integration === */
:root {
  --tg-bg: #ffffff;
  --tg-text: #1a1a1a;
  --tg-hint: #8e8e93;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f2f2f7;
  --tg-section-bg: #ffffff;

  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.2s ease;

  --urgent: #e5342b;
  --urgent-bg: #fff2f1;
  --normal: #c47600;
  --normal-bg: #fff8ed;
  --flexible: #248a3d;
  --flexible-bg: #f0faf3;

  --cat-documents: #5856d6;
  --cat-medicine: #ff2d55;
  --cat-things: #ff9500;
  --cat-other: #8e8e93;
}

.dark {
  --tg-bg: #1c1c1e;
  --tg-text: #f2f2f7;
  --tg-hint: #8e8e93;
  --tg-link: #64d2ff;
  --tg-button: #64d2ff;
  --tg-button-text: #000000;
  --tg-secondary-bg: #2c2c2e;
  --tg-section-bg: #2c2c2e;

  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.3);

  --urgent-bg: #3a1c1a;
  --normal-bg: #3a2e1a;
  --flexible-bg: #1a3a22;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  line-height: 1.5;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* === Header === */
.header {
  background: var(--tg-bg);
  padding: 16px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 0.5px solid rgba(128, 128, 128, 0.15);
}

.header-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.header-subtitle {
  font-size: 13px;
  color: var(--tg-hint);
}

.stats-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-hint);
  background: var(--tg-secondary-bg);
  padding: 4px 10px;
  border-radius: 20px;
}

.stat-badge .num {
  color: var(--tg-text);
  font-weight: 700;
}

/* === Filters === */
.filters {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: none;
  background: var(--tg-section-bg);
  color: var(--tg-hint);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--card-shadow);
  white-space: nowrap;
}

.filter-btn:active {
  transform: scale(0.96);
}

.filter-btn.active {
  background: var(--tg-button);
  color: var(--tg-button-text);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--tg-button) 30%, transparent);
}

.filter-btn .icon {
  font-size: 16px;
}

/* === Request Cards === */
.requests-list {
  padding: 4px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.request-card {
  background: var(--tg-section-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.request-card:active {
  transform: scale(0.98);
  box-shadow: var(--card-shadow-hover);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.direction-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
}

.direction-badge .arrow {
  font-size: 11px;
}

.urgency-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.urgency-dot.urgent {
  background: var(--urgent);
  box-shadow: 0 0 6px var(--urgent);
  animation: pulse 2s infinite;
}

.urgency-dot.normal {
  background: var(--normal);
}

.urgency-dot.flexible {
  background: var(--flexible);
}

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

.card-body {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-content {
  flex: 1;
  min-width: 0;
}

.card-chevron {
  font-size: 22px;
  color: var(--tg-hint);
  flex-shrink: 0;
  opacity: 0.5;
}

.card-description {
  font-size: 14px;
  line-height: 1.45;
  color: var(--tg-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--tg-hint);
}

.meta-item .icon {
  font-size: 13px;
}

.category-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.category-tag.documents { background: color-mix(in srgb, var(--cat-documents) 12%, transparent); color: var(--cat-documents); }
.category-tag.medicine { background: color-mix(in srgb, var(--cat-medicine) 12%, transparent); color: var(--cat-medicine); }
.category-tag.things { background: color-mix(in srgb, var(--cat-things) 12%, transparent); color: var(--cat-things); }
.category-tag.other { background: color-mix(in srgb, var(--cat-other) 12%, transparent); color: var(--cat-other); }

/* === Detail Page === */
.detail-page {
  padding: 0 16px 32px;
}

.detail-header {
  background: var(--tg-bg);
  padding: 20px 16px;
  margin: 0 -16px 16px;
  border-bottom: 0.5px solid rgba(128, 128, 128, 0.15);
}

.detail-direction {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.direction-full {
  font-size: 18px;
  font-weight: 700;
}

.direction-arrow {
  font-size: 20px;
  color: var(--tg-link);
}

.urgency-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
}

.urgency-badge.urgent { background: var(--urgent-bg); color: var(--urgent); }
.urgency-badge.normal { background: var(--normal-bg); color: var(--normal); }
.urgency-badge.flexible { background: var(--flexible-bg); color: var(--flexible); }

.detail-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-section {
  background: var(--tg-section-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--card-shadow);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.section-text {
  font-size: 15px;
  line-height: 1.55;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.detail-row:not(:last-child) {
  border-bottom: 0.5px solid rgba(128, 128, 128, 0.1);
}

.detail-label {
  font-size: 14px;
  color: var(--tg-hint);
}

.detail-value {
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}

.sender-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  text-decoration: none;
  color: var(--tg-text);
  transition: all var(--transition);
}

a.sender-row:active {
  opacity: 0.7;
}

.sender-section {
  padding-bottom: 12px;
}

.sender-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-button);
  color: var(--tg-button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.sender-info {
  flex: 1;
}

.sender-name {
  font-size: 15px;
  font-weight: 600;
}

.sender-username {
  font-size: 13px;
  color: var(--tg-link);
}

.sender-username--muted {
  color: var(--tg-hint);
}

.sender-arrow {
  font-size: 20px;
  color: var(--tg-hint);
}

/* Message link button */
.message-link-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--tg-link) 6%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--tg-link) 20%, transparent);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--tg-text);
  transition: all var(--transition);
  margin-bottom: 12px;
}

.message-link-btn:active {
  transform: scale(0.98);
}

.message-link-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.message-link-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.message-link-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--tg-link);
}

.message-link-hint {
  font-size: 12px;
  color: var(--tg-hint);
  margin-top: 2px;
}

/* Take button for dev mode (outside Telegram) */
.take-btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 16px;
}

.take-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.take-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Taken notice === */
.taken-notice {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--flexible-bg);
  color: var(--flexible);
  margin-top: 16px;
}

/* === Contact block (after taking a request) === */
.contact-block {
  margin-top: 12px;
}

.contact-block .section-title {
  margin-bottom: 10px;
}

.contact-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--tg-section-bg);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--tg-text);
  box-shadow: var(--card-shadow);
  transition: all var(--transition);
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 500;
}

.contact-btn:active {
  transform: scale(0.98);
}

.contact-btn.primary {
  background: color-mix(in srgb, var(--tg-link) 8%, var(--tg-section-bg));
  border: 1px solid color-mix(in srgb, var(--tg-link) 20%, transparent);
  color: var(--tg-link);
  font-weight: 600;
}

.contact-btn .sender-arrow {
  margin-left: auto;
}

.contact-hint {
  font-size: 13px;
  color: var(--tg-hint);
  padding: 8px 0 0;
  line-height: 1.4;
}

/* Back button for dev mode */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--tg-link);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 8px;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 60px 32px;
  color: var(--tg-hint);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--tg-text);
  margin-bottom: 6px;
}

.empty-text {
  font-size: 14px;
  line-height: 1.5;
}

.error-link {
  color: var(--tg-link);
}

/* === Loading === */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--tg-hint);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--tg-secondary-bg);
  border-top-color: var(--tg-button);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

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

/* === Animations === */
.fade-in {
  animation: fadeIn 0.3s ease;
}

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

.request-card {
  animation: slideIn 0.3s ease;
  animation-fill-mode: both;
}

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

/* Stagger animation — cards beyond 8th appear instantly */
.request-card:nth-child(1) { animation-delay: 0s; }
.request-card:nth-child(2) { animation-delay: 0.03s; }
.request-card:nth-child(3) { animation-delay: 0.06s; }
.request-card:nth-child(4) { animation-delay: 0.09s; }
.request-card:nth-child(5) { animation-delay: 0.12s; }
.request-card:nth-child(6) { animation-delay: 0.15s; }
.request-card:nth-child(7) { animation-delay: 0.18s; }
.request-card:nth-child(8) { animation-delay: 0.21s; }
.request-card:nth-child(n+9) { animation-delay: 0s; animation-duration: 0.15s; }

/* === Dev mode notice === */
.dev-notice {
  display: none;
  background: #fff3cd;
  color: #856404;
  padding: 8px 16px;
  font-size: 12px;
  text-align: center;
}

.dev-mode .dev-notice {
  display: block;
}

.dark .dev-notice {
  background: #3a3000;
  color: #ffd700;
}
