* { box-sizing: border-box; }

body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  background: #0a0a0a;
  color: #ddd;
}

#container { width: 100vw; height: 100vh; }

/* ── Loading overlay ── */
#loading {
  position: absolute; inset: 0;
  background: rgba(8,8,16,0.97);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 50; gap: 14px;
}
#loading.hidden { display: none; }
#loading-title { font-size: 15px; color: #aaa; }
#loading-sub   { font-size: 12px; color: #444; }
#loading-bar-wrap { width: 200px; height: 3px; background: #1e1e2e; border-radius: 2px; }
#loading-bar      { height: 100%; background: #4da6ff; border-radius: 2px; width: 0%; transition: width 0.3s; }

/* ── Chat panel ── */
#chat-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 360px;
  background: rgba(10,10,18,0.97);
  border-left: 1px solid #1e1e2e;
  display: flex; flex-direction: column;
  z-index: 10;
}

/* Header */
#chat-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid #1e1e2e;
  flex-shrink: 0;
}
#chat-header h2 {
  margin: 0 0 3px; font-size: 14px; font-weight: 700; color: #fff;
}
#chat-header .subtitle {
  font-size: 11px; color: #555; line-height: 1.4;
}

/* Lang toggle */
.lang-row {
  display: flex; gap: 4px; margin-top: 10px;
}
.lang-btn {
  padding: 3px 10px; font-size: 11px; font-weight: 600;
  border: 1px solid #2a2a3a; border-radius: 4px;
  background: #14141e; color: #555; cursor: pointer; transition: all 0.15s;
}
.lang-btn.active { background: #1a3a52; border-color: #2a6496; color: #fff; }

/* Messages */
#messages {
  flex: 1; overflow-y: auto; padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: #2a2a3a; border-radius: 2px; }

/* Welcome card */
.welcome-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid #1e1e2e;
  border-radius: 8px; padding: 12px 14px;
  font-size: 12px; color: #666; line-height: 1.7;
}
.welcome-card b { color: #aaa; }
.example-question {
  display: block; margin-top: 5px;
  font-size: 11px; color: #4da6ff;
  cursor: pointer; padding: 3px 0;
  text-decoration: none; transition: color 0.15s;
}
.example-question:hover { color: #7ec8ff; }

/* User message */
.msg-user {
  align-self: flex-end;
  max-width: 88%;
  background: rgba(26,58,82,0.85);
  border: 1px solid #1e4a6e;
  border-radius: 10px 10px 2px 10px;
  padding: 9px 12px;
  font-size: 12px; color: #c8e4ff; line-height: 1.5;
}

/* Assistant message */
.msg-assistant {
  align-self: flex-start;
  max-width: 100%;
  width: 100%;
}
.msg-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid #1e1e2e;
  border-radius: 8px; overflow: hidden;
}
.msg-title {
  padding: 10px 14px 8px;
  font-size: 12px; font-weight: 700; color: #fff;
  border-bottom: 1px solid #1e1e2e;
}
.msg-results {
  padding: 8px 14px 10px;
  font-size: 11px; color: #888; line-height: 1.9;
}
.result-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}
.result-row:last-child { border-bottom: none; }
.result-name { color: #bbb; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-value { color: #4da6ff; font-weight: 600; font-size: 11px; flex-shrink: 0; margin-left: 8px; }
.result-more { font-size: 10px; color: #444; padding-top: 4px; }
.msg-count { padding: 0 14px 6px; font-size: 10px; color: #333; }

/* SQL toggle */
.sql-toggle {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 14px;
  border-top: 1px solid #1e1e2e;
  font-size: 10px; color: #444;
  cursor: pointer; user-select: none; transition: color 0.15s;
}
.sql-toggle:hover { color: #666; }
.sql-toggle .arrow { font-size: 8px; transition: transform 0.2s; }
.sql-toggle.open .arrow { transform: rotate(90deg); }
.sql-body { display: none; padding: 0 14px 12px; }
.sql-body.open { display: block; }
pre.sql-pre {
  margin: 0;
  background: #0d0d18; border: 1px solid #1e1e2e;
  border-radius: 5px; padding: 10px;
  font-size: 10px; color: #a8c7f0;
  line-height: 1.6; overflow-x: auto;
  white-space: pre-wrap; word-break: break-all;
}

/* Thinking indicator */
.msg-thinking {
  align-self: flex-start;
  font-size: 11px; color: #444; padding: 6px 2px;
}
.dots span { animation: blink 1.4s infinite; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* Error */
.msg-error {
  align-self: flex-start; width: 100%;
  background: rgba(200,30,30,0.08);
  border: 1px solid rgba(200,30,30,0.2);
  border-radius: 8px; padding: 10px 14px;
  font-size: 11px; color: #ff8a8a; line-height: 1.5;
}

/* Autocomplete */
#autocomplete {
  position: absolute; bottom: 52px; left: 0; right: 0;
  background: rgba(14,14,22,0.99);
  border-top: 1px solid #1e1e2e;
  z-index: 20; display: none;
}
#autocomplete.open { display: block; }
.ac-item {
  padding: 9px 16px; font-size: 12px; color: #aaa;
  cursor: pointer; transition: background 0.1s;
  border-bottom: 1px solid #13131f;
  display: flex; justify-content: space-between; align-items: center;
}
.ac-item:hover, .ac-item.focused { background: rgba(77,166,255,0.08); color: #fff; }
.ac-type { font-size: 10px; color: #333; }

/* Input bar */
#input-bar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #1e1e2e;
  background: rgba(14,14,22,0.99);
  position: relative;
}
#question-input {
  flex: 1; background: #0d0d18;
  border: 1px solid #2a2a3a; border-radius: 6px;
  padding: 8px 12px; font-size: 12px; color: #ddd;
  outline: none; transition: border-color 0.15s;
  font-family: inherit;
}
#question-input::placeholder { color: #333; }
#question-input:focus { border-color: #2a6496; }
#submit-btn {
  background: #1a3a52; border: 1px solid #2a6496;
  color: #4da6ff; border-radius: 6px;
  width: 34px; height: 34px; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
#submit-btn:hover { background: #2a4a62; }
#submit-btn:disabled { opacity: 0.4; cursor: default; }

/* Layer suggestion card */
.msg-layers {
  align-self: flex-start; width: 100%;
  background: rgba(20,30,20,0.6);
  border: 1px solid #1e3a22;
  border-radius: 8px; overflow: hidden;
}
.layers-header {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex; align-items: center; gap: 6px;
  font-size: 11px;
}
.layers-header-title { color: #8fc; font-weight: 600; flex: 1; }
.layers-source { font-size: 10px; color: #3a5a3a; }
.layer-row {
  padding: 8px 14px; border-bottom: 1px solid rgba(255,255,255,0.03);
  display: flex; align-items: flex-start; gap: 10px;
}
.layer-row:last-child { border-bottom: none; }
.layer-row-info { flex: 1; min-width: 0; }
.layer-row-title { font-size: 11px; color: #ccc; line-height: 1.4; }
.layer-row-abstract { font-size: 10px; color: #444; margin-top: 2px; line-height: 1.4; }
.layer-add-btn {
  flex-shrink: 0;
  background: rgba(20,50,30,0.6); border: 1px solid #2a5a32;
  color: #6da; border-radius: 4px;
  padding: 3px 10px; font-size: 10px; cursor: pointer;
  white-space: nowrap; transition: all 0.15s; font-family: inherit;
}
.layer-add-btn:hover { background: rgba(20,70,40,0.8); }
.layer-add-btn.active { background: rgba(20,70,40,0.9); border-color: #4a9a5a; color: #8fe8a0; }

/* Active WMS overlay panel */
#wms-panel {
  position: absolute; bottom: 20px; left: 20px;
  z-index: 10; display: flex; flex-direction: column; gap: 5px;
  max-width: 260px; pointer-events: none;
}
.wms-chip {
  background: rgba(10,10,18,0.92); border: 1px solid #2a6244;
  border-radius: 16px; padding: 4px 8px 4px 12px;
  font-size: 11px; color: #6da;
  display: flex; align-items: center; gap: 6px;
  pointer-events: all;
}
.wms-chip-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wms-chip-remove {
  background: none; border: none; color: #3a5a3a;
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px;
  transition: color 0.15s;
}
.wms-chip-remove:hover { color: #ff8a8a; }

/* Share / download actions */
.result-actions {
  display: flex; gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid #1e1e2e;
}
.action-btn {
  background: #14141e; border: 1px solid #2a2a3a;
  color: #666; border-radius: 4px;
  padding: 4px 10px; font-size: 10px;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.action-btn:hover { background: #1e1e2e; color: #aaa; border-color: #3a3a4a; }
.action-btn.copied { color: #4da6ff; border-color: #2a6496; }

/* Trend chart */
.trend-title {
  display: flex; justify-content: space-between; align-items: center;
}
.trend-subtitle { font-size: 10px; font-weight: 400; color: #444; }
.trend-chart-wrap { padding: 4px 14px 12px; height: 130px; position: relative; }

/* Mobile */
@media (max-width: 700px) {
  #chat-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    height: 55vh;
    border-left: none; border-top: 1px solid #1e1e2e;
  }
}
