:root {
  --primary-color: #1890FF;
  --primary-dark: #096dd9;
  --primary-light: #E6F7FF;
  --success-color: #52C41A;
  --warning-color: #FAAD14;
  --error-color: #FF4D4F;
  --text-primary: #1F1F1F;
  --text-secondary: #666666;
  --text-light: #999999;
  --border-color: #E8E8E8;
  --bg-color: #F5F5F5;
  --card-bg: #FFFFFF;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

body {
  background: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 0 clamp(18px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 900;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  letter-spacing: 0;
}

.brand-name {
  font-size: 18px;
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
}

.nav-item, .tab {
  min-height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  transition: all 0.2s ease;
}

.nav-item:hover, .tab:hover {
  background: var(--bg-color);
}

.nav-item.active, .tab.active {
  background: var(--primary-light);
  color: var(--primary-color);
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 88px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 420px);
  gap: 28px;
  align-items: stretch;
  margin-bottom: 26px;
}

.hero-copy {
  display: flex;
  min-height: 320px;
  flex-direction: column;
  justify-content: center;
  padding: clamp(28px, 5vw, 58px);
  border-radius: 16px;
  background: linear-gradient(145deg, #ffffff 0%, #f0f5ff 100%);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.hero-copy::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(24, 144, 255, 0.1), transparent);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--primary-color);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
}

.hero h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(32px, 5.5vw, 56px);
  line-height: 1.1;
  letter-spacing: -0.5px;
  position: relative;
  z-index: 1;
}

.hero-text {
  max-width: 560px;
  margin: 18px 0 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.75;
  position: relative;
  z-index: 1;
}

.hero-actions, .inline-actions, .card-actions, .load-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hero-actions {
  margin-top: 28px;
  position: relative;
  z-index: 1;
}

.auth-card, .workspace, .form-surface, .trip-card, .order-card, .empty-state, .dialog {
  border-radius: 16px;
  background: var(--card-bg);
  box-shadow: var(--shadow-md);
}

.auth-card {
  padding: 24px;
}

.auth-head, .section-head, .dialog-head, .order-head, .card-header, .meta-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.auth-head h2, .section-head h2, .dialog-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.auth-head p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.auth-form, .account-summary {
  display: grid;
  gap: 14px;
}

.auth-hint {
  margin: 12px 0 0;
  color: var(--text-light);
  font-size: 13px;
  line-height: 1.5;
}

.account-summary {
  padding: 16px;
  background: var(--bg-color);
  border-radius: 12px;
}

.advanced-settings {
  color: var(--text-secondary);
  font-size: 14px;
}

.advanced-settings summary {
  cursor: pointer;
  font-weight: 600;
}

.workspace {
  padding: clamp(16px, 3vw, 28px);
}

.page-settings {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-top: 14px;
}

.mobile-tabs {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

.section-head {
  margin-bottom: 20px;
}

.compact-head {
  align-items: center;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
}

.segmented.full {
  width: 100%;
  margin: 16px 0;
}

.segment {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  transition: all 0.2s ease;
}

.segment.active {
  background: var(--primary-color);
  color: #fff;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field span {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(24, 144, 255, 0.1);
}

input::placeholder, textarea::placeholder {
  color: var(--text-light);
}

.primary-button, .secondary-button, .ghost-button, .icon-button, .wechat-button {
  min-height: 42px;
  border-radius: 10px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.primary-button {
  padding: 0 20px;
  border: none;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
}

.primary-button:active {
  transform: translateY(0);
}

.wechat-button {
  border: none;
  background: linear-gradient(135deg, #12b76a, #0da55f);
  color: #fff;
}

.secondary-button {
  padding: 0 18px;
  border: 1px solid var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
}

.secondary-button:hover {
  background: rgba(24, 144, 255, 0.15);
}

.ghost-button {
  padding: 0 18px;
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-secondary);
}

.ghost-button:hover {
  background: var(--bg-color);
}

.ghost-button.danger {
  color: var(--error-color);
  border-color: rgba(255, 77, 79, 0.3);
}

.ghost-button.danger:hover {
  background: rgba(255, 77, 79, 0.05);
}

.compact {
  min-height: 36px;
}

.coordinate-field {
  opacity: 0.8;
}

.coordinate-field input {
  background: #f8f9fa;
}

.location-field {
  position: relative;
}

.location-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.location-status {
  color: var(--text-light);
  font-size: 12px;
}

.location-status.selected {
  color: var(--success-color);
  font-weight: 600;
}

.poi-results {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
}

.poi-option {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: auto;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--bg-color);
  color: var(--text-primary);
  text-align: left;
  transition: all 0.2s ease;
}

.poi-option:hover, .poi-option:focus {
  border-color: var(--primary-light);
  background: var(--primary-light);
}

.poi-option strong, .poi-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.poi-option strong {
  font-size: 14px;
}

.poi-option span {
  color: var(--text-light);
  font-size: 12px;
}

.wide-button {
  width: 100%;
}

.account-pill, .pill, .badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-color);
  font-size: 12px;
  font-weight: 600;
}

.badge.driver {
  background: #F6FFED;
  color: var(--success-color);
}

.badge.passenger {
  background: #FFF7E6;
  color: var(--warning-color);
}

.badge.cancelled {
  background: #FFF2F0;
  color: var(--error-color);
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--text-light);
}

.state-dot.ok {
  background: var(--success-color);
}

.state-dot.bad {
  background: var(--error-color);
}

.filter-bar, .form-grid {
  display: grid;
  gap: 14px;
}

.filter-bar {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
  align-items: end;
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
}

.match-notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--primary-light);
  border-radius: 12px;
  background: var(--primary-light);
  color: #244a7f;
  font-size: 14px;
  line-height: 1.5;
}

.match-notice strong {
  color: var(--primary-color);
}

.form-surface {
  padding: clamp(16px, 3vw, 28px);
}

.form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

.wide {
  grid-column: span 2;
}

.trip-list, .order-list {
  display: grid;
  gap: 14px;
}

.trip-card, .order-card, .empty-state {
  padding: 20px;
}

.trip-card {
  display: grid;
  gap: 16px;
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.trip-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.user-line {
  min-width: 0;
}

.user-line strong, .route-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted, .trust-line, .meta-text {
  color: var(--text-light);
  font-size: 13px;
}

.route {
  display: grid;
  gap: 10px;
}

.route-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--success-color);
  box-shadow: 0 0 0 3px rgba(82, 196, 26, 0.2);
}

.dot.end {
  background: var(--error-color);
  box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.2);
}

.route-name {
  min-width: 0;
  font-weight: 600;
  font-size: 14px;
}

.meta-row {
  align-items: center;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

.price {
  color: var(--primary-color);
  font-size: 20px;
  font-weight: 700;
}

.card-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.empty-state {
  color: var(--text-light);
  text-align: center;
  border-radius: 14px;
  background: var(--card-bg);
}

.load-row {
  justify-content: center;
  margin-top: 20px;
}

.select-inline {
  width: auto;
  min-width: 160px;
}

.compact-form {
  max-width: 560px;
}

.profile-grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  grid-template-areas:
    "account trips"
    "residence trips";
  gap: 20px;
  align-items: start;
}

.profile-panel {
  min-width: 0;
}

.profile-account {
  grid-area: account;
}

.profile-trips {
  grid-area: trips;
}

.profile-residence {
  grid-area: residence;
}

.profile-grid .compact-form {
  max-width: none;
}

.profile-grid .field + .field,
.profile-grid .field + .wide-button {
  margin-top: 14px;
}

.residence-grid {
  grid-template-columns: 1fr;
}

.residence-grid .wide {
  grid-column: auto;
}

.profile-grid .form-surface {
  padding: 24px;
}

.profile-trips {
  min-height: 420px;
}

.profile-trips .trip-list {
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.profile-residence .wide-button,
.profile-account .wide-button {
  margin-top: 4px;
}

.my-trip-card .price {
  font-size: 18px;
}

.icon-button {
  width: 40px;
  border: 1px solid var(--border-color);
  background: #fff;
}

.dialog {
  width: min(720px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 28px));
  border: none;
  border-radius: 16px;
  padding: 0;
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.dialog-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}

.dialog-head h2 {
  font-size: 18px;
}

#dialogBody {
  padding: 24px;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

/* ===== 消息会话卡片 ===== */
.chat-session {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-session:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}
.chat-session:focus-visible {
  outline: 2px solid var(--primary-color, #1890ff);
  outline-offset: 2px;
}
.chat-latest {
  margin: 6px 0;
  color: var(--text-primary, #1f1f1f);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.chat-row-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-open-hint {
  color: var(--primary-color, #1890ff);
  font-size: 13px;
}
.pill-danger {
  background: #fff1f0 !important;
  color: #cf1322 !important;
}

/* ===== 聊天弹窗 ===== */
.chat-window {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: min(60vh, 520px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f7f9fc;
  border-radius: 12px;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.chat-msg-self {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg-peer {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg-self .chat-bubble {
  background: var(--primary-color, #1890ff);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-peer .chat-bubble {
  background: #ffffff;
  color: #1f1f1f;
  border: 1px solid var(--border-color, #e8e8e8);
  border-bottom-left-radius: 4px;
}
.chat-time {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
  padding: 0 4px;
}
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e8e8e8);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}
.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--primary-color, #1890ff);
}
.chat-input-row .primary-button {
  align-self: stretch;
  padding: 0 22px;
}

.detail-grid {
  display: grid;
  gap: 14px;
}

.detail-item {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-color);
}

.detail-item strong {
  font-size: 14px;
  color: var(--text-secondary);
}

.detail-item span {
  font-size: 14px;
  color: var(--text-primary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 50;
  max-width: min(520px, calc(100% - 28px));
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: all 0.2s ease;
  pointer-events: none;
}

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

.hidden {
  display: none !important;
}

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .desktop-nav {
    display: none;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    min-height: 280px;
  }

  .filter-bar, .form-grid, .profile-grid, .settings-row {
    grid-template-columns: 1fr;
  }

  .profile-grid {
    grid-template-areas:
      "account"
      "residence"
      "trips";
  }

  .profile-trips {
    min-height: 0;
  }

  .profile-trips .trip-list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

@media (max-width: 640px) {
  .topbar {
    min-height: 64px;
    padding: 0 14px;
  }

  .brand-name, .account-pill {
    display: none;
  }

  .topbar-actions .primary-button {
    padding: 0 14px;
  }

  .main {
    width: 100%;
    padding: 0 12px 92px;
  }

  .hero {
    gap: 12px;
    margin-bottom: 12px;
  }

  .auth-card {
    padding: 18px;
    box-shadow: var(--shadow-sm);
  }

  .auth-head h2, .section-head h2, .dialog-head h2 {
    font-size: 20px;
  }

  .wechat-browser .auth-card {
    order: -1;
  }

  .wechat-browser .auth-card .segmented,
  .wechat-browser .auth-card #loginForm,
  .wechat-browser .auth-card #registerForm {
    display: none;
  }

  .wechat-browser .auth-head {
    margin-bottom: 14px;
  }

  .wechat-browser.logged-in .auth-card {
    display: none;
  }

  .hero-copy {
    min-height: auto;
    padding: 22px;
    box-shadow: var(--shadow-sm);
  }

  .hero h1 {
    font-size: 28px;
    line-height: 1.15;
  }

  .hero-text {
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.6;
  }

  .hero-actions {
    margin-top: 20px;
  }

  .hero-actions, .auth-head, .section-head, .meta-row, .order-head, .card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace {
    padding: 14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mobile-tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
  }

  .tab {
    min-height: 44px;
    padding: 0 6px;
    font-size: 12px;
  }

  .filter-bar, .form-grid, .profile-grid, .settings-row {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .filter-bar {
    padding: 14px;
  }

  .trip-card, .order-card, .empty-state {
    padding: 16px;
  }

  .card-actions {
    justify-content: stretch;
  }

  .card-actions button {
    flex: 1 1 auto;
  }

  .price {
    font-size: 18px;
  }
}