/* ========================================================================
   AI租房军师 - Mobile App Styles
   ======================================================================== */

/* --- Reset & Variables --- */
:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --safe: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg: #F8FAFC;
  --card-bg: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- App Shell --- */
.app-shell {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.app-header {
  background: var(--card-bg);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
}

.back-btn {
  font-size: 24px;
  padding: 4px 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
}

/* --- Page Container --- */
.page {
  display: none;
  padding: 16px;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 200;
  max-width: 430px;
  margin: 0 auto;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 16px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 11px;
  transition: color 0.2s;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item .nav-icon {
  font-size: 22px;
  line-height: 1;
}

/* --- Search Input --- */
.search-section {
  margin-bottom: 20px;
}

.search-input-wrap {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  display: flex;
  align-items: flex-end;
  transition: border-color 0.2s;
}

.search-input-wrap:focus-within {
  border-color: var(--primary);
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.4;
  border-radius: var(--radius);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
  background: transparent;
}

.search-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
  margin: 4px;
}

.search-btn:active {
  background: var(--primary-dark);
}

.search-btn:disabled {
  opacity: 0.5;
}

/* --- Suggestions --- */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.suggestion-chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* --- House Card --- */
.house-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.house-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-md);
}

.house-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.house-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.house-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--danger);
  white-space: nowrap;
}

.house-price-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

.house-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
  flex-wrap: wrap;
}

.house-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.tag {
  background: #EEF2FF;
  color: var(--primary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
}

.tag.danger {
  background: #FEF2F2;
  color: var(--danger);
}

.tag.warning {
  background: #FFFBEB;
  color: var(--warning);
}

.tag.tag-mock {
  background: #FFFBEB;
  color: #B45309;
  font-size: 10px;
  padding: 1px 6px;
}

.tag.tag-real {
  background: #ECFDF5;
  color: #059669;
  font-size: 10px;
  padding: 1px 6px;
}

.house-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.agent-info {
  font-size: 12px;
  color: var(--text-secondary);
}

/* --- Score Badge --- */
.score-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.score-badge.high { background: var(--safe); }
.score-badge.mid { background: var(--warning); }
.score-badge.low { background: var(--danger); }

/* --- Risk Alert --- */
.risk-alert {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--danger);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.risk-alert .alert-icon { font-size: 18px; }

/* --- AI Analysis Card --- */
.ai-card {
  background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.ai-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-card-content {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

/* --- Detail Page --- */
.detail-image {
  width: 100%;
  height: 200px;
  background: #E2E8F0;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
  overflow: hidden;
}

.detail-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.detail-section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.detail-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.detail-info-row:last-child { border-bottom: none; }
.detail-info-label { color: var(--text-secondary); }
.detail-info-value { font-weight: 500; }

/* --- Score Breakdown --- */
.score-bar-wrapper {
  margin-top: 8px;
}

.score-bar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.score-bar-label {
  font-size: 12px;
  color: var(--text-secondary);
  width: 50px;
  flex-shrink: 0;
}

.score-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.score-bar-fill.high { background: var(--safe); }
.score-bar-fill.mid { background: var(--warning); }
.score-bar-fill.low { background: var(--danger); }

.score-bar-value {
  font-size: 12px;
  font-weight: 600;
  width: 24px;
  text-align: right;
}

/* --- Unlock Button --- */
.unlock-section {
  position: sticky;
  bottom: 0;
  background: var(--card-bg);
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
}

.unlock-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.unlock-btn:active { opacity: 0.9; }
.unlock-btn.disabled { opacity: 0.5; }

/* --- Payment Page --- */
.payment-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin-top: 20px;
}

.payment-amount {
  font-size: 48px;
  font-weight: 700;
  color: var(--primary);
}

.payment-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.payment-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 16px 0;
  line-height: 1.6;
}

.payment-btn {
  width: 100%;
  background: var(--safe);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

/* --- Searching Animation --- */
.searching-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.searching-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.searching-text {
  margin-top: 20px;
  font-size: 15px;
  color: var(--text-secondary);
}

.searching-steps {
  margin-top: 24px;
  text-align: left;
  width: 100%;
  max-width: 280px;
}

.searching-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.searching-step.completed {
  color: var(--safe);
}

.searching-step .step-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* --- Results Page --- */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.results-count {
  font-size: 14px;
  color: var(--text-secondary);
}

.results-sort select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text);
}

/* --- History Page --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-text {
  font-size: 14px;
}

/* --- Loading State --- */
.skeleton {
  background: linear-gradient(90deg, #E2E8F0 25%, #F1F5F9 50%, #E2E8F0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Toast --- */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  max-width: 86%;
}

.toast.show {
  opacity: 1;
}

/* --- Agent Section --- */
.agent-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.agent-level {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.agent-level.A { background: #D1FAE5; color: #065F46; }
.agent-level.B { background: #FEF3C7; color: #92400E; }
.agent-level.C { background: #FEE2E2; color: #991B1B; }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 430px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
