/* ========== 全局重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --danger: #d93025;
  --warning: #f9ab00;
  --success: #188038;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}

/* ========== 顶部标题栏 ========== */
.app-header {
  background: linear-gradient(135deg, var(--primary), #4285f4);
  color: #fff;
  padding: 14px 16px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}
.app-header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1px;
}

/* ========== 页面容器 ========== */
.page {
  display: none;
  position: fixed;
  top: 52px; left: 0; right: 0; bottom: 60px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.page.active { display: block; }

/* ========== 搜索栏 ========== */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar button {
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ========== 筛选栏 ========== */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 62px;
  z-index: 10;
}
.filter-bar select {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.filter-bar select:focus { border-color: var(--primary); }
.result-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
}

/* ========== 门位置卡片列表 ========== */
.gate-list {
  padding: 10px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gate-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border-left: 4px solid var(--primary);
}
.gate-card:active {
  transform: scale(.98);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.gate-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.gate-no {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}
.gate-tags {
  display: flex;
  gap: 5px;
}
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.tag-line { background: #e8f0fe; color: var(--primary); }
.tag-dir { background: #fef7e0; color: #b06000; }
.tag-section { background: #e6f4ea; color: var(--success); }
.tag-dist { background: #fce8e6; color: var(--danger); font-weight: 600; }

/* ========== 智能里程搜索分区 ========== */
.search-section { margin-bottom: 16px; }
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  padding: 8px 4px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 8px;
}
.section-count { font-size: 12px; font-weight: 400; color: var(--text-secondary); }
.section-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  background: var(--card);
  border-radius: var(--radius);
}
.section-warn {
  padding: 14px;
  text-align: center;
  color: #b06000;
  font-size: 13px;
  background: #fef7e0;
  border-radius: var(--radius);
  line-height: 1.6;
}
.empty-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.empty-hint b { color: var(--primary); }
.gate-info-row {
  display: flex;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  line-height: 1.5;
}
.gate-info-row .label {
  flex-shrink: 0;
  color: #80868b;
  min-width: 42px;
}
.gate-info-row .value {
  word-break: break-all;
}
.gate-card-footer {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.gate-card-footer button {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-nav-small {
  background: var(--primary);
  color: #fff;
}
.btn-detail-small {
  background: #f1f3f4;
  color: var(--text);
}

/* ========== 地图页 ========== */
.map-filter {
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.map-filter select {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  outline: none;
}
.map-container {
  width: 100%;
  height: calc(100% - 90px);
  min-height: 400px;
}
.map-tip {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 6px;
  background: var(--card);
  border-top: 1px solid var(--border);
}

/* ========== 应急卡页 ========== */
.emergency-search {
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.emergency-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  outline: none;
}
.emergency-search input:focus { border-color: var(--danger); }
.emergency-list {
  padding: 10px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.emergency-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border-left: 4px solid var(--danger);
  transition: transform .15s;
}
.emergency-card:active { transform: scale(.98); }
.emergency-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.emergency-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--danger);
}
.emergency-level {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
  color: #fff;
}
.level-high { background: var(--danger); }
.level-mid { background: var(--warning); }
.level-low { background: var(--success); }
.emergency-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ========== 弹窗 ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .2s;
}
.modal-content {
  background: var(--card);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp .25s;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}
.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: #f1f3f4;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.detail-row {
  display: flex;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.6;
}
.detail-row .label {
  flex-shrink: 0;
  width: 75px;
  color: var(--text-secondary);
  font-weight: 500;
}
.detail-row .value {
  color: var(--text);
  word-break: break-all;
  flex: 1;
}
.modal-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-actions button {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-nav {
  background: var(--primary);
  color: #fff;
}
.btn-copy {
  background: #f1f3f4;
  color: var(--text);
}
.btn-map {
  background: #e8f5e9;
  color: var(--success);
}

/* ========== 访问密码验证层 ========== */
.access-gate {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1a237e, #283593);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.access-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.access-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.access-card h2 {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 8px;
}
.access-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}
.access-input-row {
  display: flex;
  gap: 10px;
}
.access-input-row input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}
.access-input-row input:focus {
  border-color: var(--primary);
}
.btn-access {
  padding: 12px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-access:hover { background: var(--primary-dark); }
.access-msg {
  margin-top: 14px;
  font-size: 13px;
  min-height: 18px;
}
.access-msg.error { color: var(--danger); }
.access-msg.success { color: var(--success); }
.access-msg.info { color: var(--primary); }

/* ========== 应急步骤样式 ========== */
.step-list {
  counter-reset: step;
}
.step-item {
  position: relative;
  padding: 12px 12px 12px 44px;
  margin-bottom: 10px;
  background: #f8f9fa;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.7;
  counter-increment: step;
}
.step-item::before {
  content: counter(step);
  position: absolute;
  left: 12px; top: 12px;
  width: 24px; height: 24px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.em-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--danger);
  margin: 16px 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--danger);
}
.em-alert-box {
  background: #fce8e6;
  border: 1px solid #f5c6c2;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--danger);
  line-height: 1.6;
}
.em-phone {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  padding: 3px 12px;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
  margin: 2px 4px 2px 0;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(32,33,36,.9);
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 300;
  animation: fadeIn .2s;
  white-space: nowrap;
}

/* ========== 底部导航栏 ========== */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -1px 4px rgba(0,0,0,.06);
}
.tab-item {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color .2s;
}
.tab-item.active { color: var(--primary); }
.tab-icon { font-size: 22px; }
.tab-label { font-size: 11px; font-weight: 500; }

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ========== 动画 ========== */
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(100%); } to { transform: translateY(0); }
}

/* ========== 桌面端适配 ========== */
@media (min-width: 768px) {
  .page { max-width: 768px; margin: 0 auto; left: 50%; transform: translateX(-50%); }
  .modal-content { border-radius: 16px; margin: 0 20px; }
  .modal-overlay { align-items: center; }
  .modal-content { animation: fadeIn .25s; }
  .tab-bar { max-width: 768px; left: 50%; transform: translateX(-50%); }
  .app-header { max-width: 768px; left: 50%; transform: translateX(-50%); }
}