/* 应急监测平台 v2 — Modern UI */

:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #14b8a6;
  --primary-glow: rgba(13, 148, 136, 0.35);
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.12);

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.1);

  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --card: rgba(255, 255, 255, 0.92);
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --border: rgba(148, 163, 184, 0.35);
  --border-strong: rgba(148, 163, 184, 0.55);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.08), 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --shadow-primary: 0 8px 24px var(--primary-glow);

  --nav-h: 68px;
  --header-h: 56px;
  --fab-size: 58px;
  --sidebar-w: 400px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 60% at 10% -10%, rgba(13, 148, 136, 0.12), transparent),
    radial-gradient(ellipse 60% 50% at 90% 0%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 50% 40% at 50% 100%, rgba(13, 148, 136, 0.06), transparent);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; display: flex; flex-direction: column; }

#app-header {
  position: relative;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 45%, #0891b2 100%);
  color: #fff;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-h);
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(13, 148, 136, 0.25);
  z-index: 50;
}

#app-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.12) 0%, transparent 50%);
  pointer-events: none;
}

#app-header h1 {
  position: relative;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header-meta {
  position: relative;
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  backdrop-filter: blur(8px);
}

#app-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + 24px);
  scroll-behavior: smooth;
}

#app-main::-webkit-scrollbar { width: 6px; }
#app-main::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

#app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  gap: 4px;
  z-index: 100;
  box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius);
  transition: color 0.2s var(--ease), background 0.2s var(--ease), transform 0.15s var(--ease);
}

.nav-item:hover { color: var(--primary-dark); background: rgba(13, 148, 136, 0.06); }

.nav-item.active {
  color: var(--primary-dark);
  background: rgba(13, 148, 136, 0.1);
}

.nav-item.active .nav-icon {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: var(--shadow-primary);
  transform: translateY(-1px);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 16px;
  line-height: 1;
  transition: all 0.25s var(--ease-spring);
}

.nav-item[data-page="reception"] .nav-icon::before { content: "📞"; font-size: 15px; }
.nav-item[data-page="investigations"] .nav-icon::before { content: "🔎"; font-size: 15px; }
.nav-item[data-page="plans"] .nav-icon::before { content: "📝"; font-size: 15px; }
.nav-item[data-page="reports"] .nav-icon::before { content: "📄"; font-size: 15px; }
.nav-item[data-page="response"] .nav-icon::before { content: "🚨"; font-size: 15px; }
.nav-item[data-page="summary"] .nav-icon::before { content: "📊"; font-size: 15px; }
.nav-item[data-page="dashboard"] .nav-icon::before { content: "🖥️"; font-size: 15px; }
.nav-item[data-page="plume"] .nav-icon::before { content: "🌀"; font-size: 15px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease), border-color 0.25s var(--ease);
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(13, 148, 136, 0.25);
}

.card[style*="cursor:pointer"]:hover { transform: translateY(-1px); }

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: var(--text);
}

.card-title::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: var(--radius-full);
  background: linear-gradient(180deg, var(--primary-light), var(--primary-dark));
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  white-space: nowrap;
  transition: all 0.2s var(--ease);
  position: relative;
  overflow: hidden;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
  box-shadow: 0 10px 28px var(--primary-glow);
  filter: brightness(1.05);
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626, var(--danger));
  color: #fff;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.3);
}

.btn-outline {
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-strong);
  color: var(--primary-dark);
}

.btn-outline:hover {
  border-color: var(--primary);
  background: rgba(13, 148, 136, 0.06);
}

.btn-sm { padding: 7px 14px; font-size: 13px; min-height: 34px; }
.btn-block { width: 100%; }

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

/* datetime-local 控件在手机端偏宽, 压缩以对齐其他控件 */
.form-group input[type="datetime-local"] {
  min-width: 0;
  max-width: 100%;
  min-height: 46px;
  padding: 11px 8px;
  font-size: 14px;
  -webkit-appearance: none;
  appearance: none;
}
.form-row .form-group input[type="datetime-local"] {
  font-size: 13px;
  padding: 11px 6px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

/* AI/自动填入的内容绿色显示, 人工输入为黑; 人工一改自动变黑 */
.form-group input.ai-filled,
.form-group select.ai-filled,
.form-group textarea.ai-filled {
  color: var(--success);
  font-weight: 500;
}

.form-group input[type="file"] {
  padding: 8px;
  font-size: 13px;
  background: var(--bg);
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; min-width: 0; }

.list-item {
  display: flex;
  align-items: center;
  padding: 14px 12px;
  margin: 0 -12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 48px;
  transition: background 0.15s var(--ease);
}

.list-item:hover { background: rgba(13, 148, 136, 0.05); }
.list-item + .list-item { border-top: 1px solid var(--border); }

.list-item .list-info { flex: 1; min-width: 0; }
.list-item .list-title { font-weight: 600; font-size: 15px; color: var(--text); }
.list-item .list-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

.text-muted { color: var(--muted); font-size: 13px; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

#ai-fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 18px);
  right: 18px;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #818cf8 50%, var(--primary) 100%);
  color: #fff;
  border: none;
  font-size: 0;
  box-shadow: 0 8px 28px rgba(99, 102, 241, 0.45), 0 0 0 4px rgba(255,255,255,0.8);
  z-index: 200;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s var(--ease);
  animation: fabPulse 3s ease-in-out infinite;
}

#ai-fab::before {
  content: "✦";
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

#ai-fab:hover {
  transform: scale(1.08);
  animation: none;
  box-shadow: 0 12px 36px rgba(99, 102, 241, 0.5), 0 0 0 4px rgba(255,255,255,0.9);
}

#ai-fab:active { transform: scale(0.95); }

@keyframes fabPulse {
  0%, 100% { box-shadow: 0 8px 28px rgba(99, 102, 241, 0.45), 0 0 0 4px rgba(255,255,255,0.8); }
  50% { box-shadow: 0 8px 32px rgba(99, 102, 241, 0.6), 0 0 0 6px rgba(99, 102, 241, 0.15); }
}

#ai-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.12);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s var(--ease);
  border-top: 1px solid var(--border);
}

#ai-panel.hidden { transform: translateY(100%); }
#ai-panel.half { height: 65vh; }
#ai-panel.full { height: calc(100vh - 20px); top: 20px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-weight: 700;
  font-size: 16px;
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.06), transparent);
}

.ai-header strong { display: flex; align-items: center; gap: 8px; }

.ai-header strong::before {
  content: "✦";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: #fff;
  font-size: 14px;
}

.ai-header-btn {
  border: none;
  background: var(--bg);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ai-header-btn:hover { background: var(--accent-soft); color: var(--accent); }
.ai-header-actions { display: flex; gap: 6px; align-items: center; }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-msg {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  animation: msgIn 0.3s var(--ease);
}

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

.ai-msg.user {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-primary);
}

.ai-msg.assistant {
  background: var(--bg);
  border: 1px solid var(--border);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

.ai-tool-card {
  font-size: 12px !important;
  background: var(--accent-soft) !important;
  border-color: rgba(99, 102, 241, 0.2) !important;
}

#ai-quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px;
}

.ai-quick-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-family: inherit;
}

.ai-quick-btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: rgba(13, 148, 136, 0.08);
}

.ai-input {
  display: flex;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
  background: rgba(248, 250, 252, 0.9);
}

.ai-input input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: 12px 18px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.ai-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ai-input button {
  border-radius: 50%;
  width: 44px;
  height: 44px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

#ai-attach {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border-strong);
  background: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.toast {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  padding: 12px 22px;
  border-radius: var(--radius-full);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  animation: toastIn 0.35s var(--ease-spring);
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.toast-success { background: linear-gradient(135deg, #059669, var(--success)); }
.toast-error { background: linear-gradient(135deg, #dc2626, var(--danger)); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.92); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

details {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

details summary { cursor: pointer; font-weight: 600; color: var(--primary-dark); }

pre {
  white-space: pre-wrap;
  font-size: 13px;
  max-height: 60vh;
  overflow: auto;
  background: var(--bg);
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  line-height: 1.6;
}

@media (min-width: 900px) {
  #app {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header header" "nav main";
    height: 100vh;
  }

  #app-header { grid-area: header; padding: 0 24px; }

  #app-nav {
    grid-area: nav;
    position: static;
    height: auto;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.75);
    box-shadow: none;
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
    font-size: 14px;
  }

  .nav-item .nav-icon { width: 36px; height: 36px; }
  .nav-item.active .nav-icon { transform: none; }

  #app-main { grid-area: main; padding: 24px 28px; padding-bottom: 24px; }
  .card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .card-grid .card { margin-bottom: 0; }

  #ai-fab { bottom: 28px; right: 28px; }

  #ai-panel {
    top: 0; right: 0; bottom: 0; left: auto;
    width: var(--sidebar-w);
    border-radius: 0;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
  }

  #ai-panel:not(.hidden) { transform: translateX(0); }
  #ai-panel.hidden { transform: translateX(100%); }
  #ai-panel.half, #ai-panel.full { height: 100% !important; top: 0; }
}

@media (min-width: 1400px) {
  #app { grid-template-columns: 260px 1fr 260px; grid-template-areas: "header header header" "nav main side"; }
  #app-main { padding: 28px 36px; }
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

/* 右侧信息栏: 仅桌面宽屏显示 (手机/窄屏隐藏, 不影响移动端布局) */
#app-side {
  display: none;
}
.side-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.side-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.side-title::before {
  content: "";
  width: 4px;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary-light), var(--primary-dark));
}
@media (min-width: 1400px) {
  #app-side {
    display: block;
    grid-area: side;
    padding: 24px 16px;
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
