:root {
  --bg:     #0f0d14;
  --bg2:    #17141f;
  --bg3:    #1f1a2a;
  --line:   rgba(255,255,255,0.08);
  --accent: #a855f7;
  --accent-dim: rgba(168,85,247,0.1);
  --text:   #e4e0ed;
  --muted:  #6b6480;
  --red:    #e05252;
  --amber:  #e0a030;
  --blue:   #3b82d4;
  --green:  #1fbb7f;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--bg);
}
.logo {
  font-size: 13px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--accent);
  text-transform: uppercase;
}
.logo span { color: var(--muted); font-weight: 400; }
#hdr-meta {
  font-size: 11px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  text-align: right;
  line-height: 1.6;
}

/* RESET BUTTON */
#btn-reset {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
  display: none;
}
#btn-reset:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }

/* DROP ZONE */
#dropzone {
  margin: 28px 20px;
  border: 1.5px dashed rgba(168,85,247,.25);
  border-radius: 8px;
  padding: 60px 20px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, background .15s;
}
#dropzone:hover, #dropzone.drag {
  border-color: var(--accent);
  background: var(--accent-dim);
}
#dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.dz-glyph  { font-size: 36px; margin-bottom: 12px; opacity: .4; }
.dz-title  { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.dz-hint   { font-size: 11px; font-family: 'Space Mono', monospace; color: var(--muted); }
#dz-error  {
  display: none;
  font-size: 11px;
  font-family: 'Space Mono', monospace;
  color: var(--red);
  margin-top: 10px;
}

/* MAIN */
#main { display: none; padding: 16px 20px 40px; }

.slabel {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin: 22px 0 10px;
}
.slabel:first-child { margin-top: 0; }

/* STATS GRID */
.sgrid {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.g6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

.sc { background: var(--bg2); padding: 14px 13px; }
.sc .l {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  letter-spacing: .08em;
  margin-bottom: 6px;
}
.sc .v {
  font-size: 19px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  line-height: 1;
}
.sc .u   { font-size: 10px; color: var(--muted); margin-left: 2px; }
.sc.hi .v { color: var(--accent); }

/* MAP */
#map-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
#map {
  height: 320px;
  width: 100%;
}
.leaflet-container { background: var(--bg2); }

/* MAP RESIZE HANDLE */
#map-resize {
  height: 10px;
  background: var(--bg3);
  border-top: 1px solid var(--line);
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
#map-resize::after {
  content: '';
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: var(--muted);
  opacity: .4;
}
#map-resize:hover::after { opacity: .8; }

/* CHARTS */
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 14px 10px;
}
.ci    { position: relative; width: 100%; height: 200px; }
.ci-sm { position: relative; width: 100%; height: 155px; }
.clabel {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  letter-spacing: .08em;
  margin-bottom: 8px;
}
.leg-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.ld {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
}
.ld-c { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* SEGMENTS TABLE */
.seg-wrap {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
th {
  font-size: 9px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  font-size: 11px;
  font-family: 'Space Mono', monospace;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
.tag {
  display: inline-block;
  font-size: 9px;
  padding: 3px 7px;
  border-radius: 3px;
}
.tag.up { background: rgba(168,85,247,.12); color: var(--accent); }
.tag.dn { background: rgba(59,130,212,.12);  color: var(--blue); }

/* ANALYSIS CARD */
#analysis-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.ah {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
  flex-wrap: wrap;
}
.ah-title { font-size: 13px; font-weight: 600; }

#btn-analyze {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 13px;
  border-radius: 3px;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
#btn-analyze:hover    { opacity: .85; }
#btn-analyze:disabled { opacity: .35; cursor: not-allowed; }

#analysis-body { padding: 16px; min-height: 60px; }

.ph {
  font-size: 11px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
}

/* CHAT */
#chat-area { border-top: 1px solid var(--line); }

#chat-messages {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.msg {
  font-size: 13px;
  line-height: 1.75;
  padding: 10px 12px;
  border-radius: 6px;
  white-space: pre-wrap;
}
.msg.user {
  background: rgba(168,85,247,.08);
  color: var(--text);
  align-self: flex-end;
  max-width: 85%;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
}
.msg.assistant {
  background: var(--bg3);
  color: var(--text);
  align-self: flex-start;
  max-width: 95%;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}
#chat-input {
  flex: 1;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  background: var(--bg3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 4px;
  outline: none;
}
#chat-input:focus { border-color: rgba(168,85,247,.4); }
#chat-input::placeholder { color: var(--muted); }
#chat-send {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity .15s;
}
#chat-send:hover    { opacity: .85; }
#chat-send:disabled { opacity: .35; cursor: not-allowed; }

/* THINKING INDICATOR */
.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: 'Space Mono', monospace;
  color: var(--muted);
  padding: 8px 0;
}
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,100%{opacity:.2} 50%{opacity:1} }

/* RESPONSIVE */
@media (max-width: 600px) {
  .g6      { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .two-col { grid-template-columns: 1fr; }
  #map     { height: 220px; }
  .ci      { height: 160px; }
}
