:root {
  --bg: #f6f7f8;
  --panel: #fff;
  --border: #dde1e6;
  --border-strong: #c7ccd2;
  --text: #1a1f26;
  --text-dim: #5b6472;
  --text-faint: #8992a0;
  --accent: #1b5fb4;
  --accent-dim: #e8f0fb;
  --danger: #b3261e;
  --danger-dim: #fbe9e8;
  --radius: 8px;
  --sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica,
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button,
input,
select {
  font-family: inherit;
  font-size: inherit;
}
button {
  cursor: pointer;
}
a {
  color: var(--accent);
}

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

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1000;
}
.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.brand small {
  font-weight: 500;
  color: var(--text-faint);
  font-size: 10px;
  margin-left: 2px;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 340px;
}
#locSearch {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
}
#locSearch:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--panel);
}
#searchResults {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  max-height: 220px;
  overflow: auto;
  display: none;
  z-index: 1200;
}
#searchResults div {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#searchResults div:last-child {
  border-bottom: none;
}
#searchResults div:hover {
  background: var(--accent-dim);
}

.hdr-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}
.radius-box {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
}
.radius-box input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
}
.radius-box b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.iconbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-dim);
}
.iconbtn:hover {
  background: var(--bg);
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
#map {
  flex: 1;
  min-width: 0;
  background: #e5e9ec;
}

#sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sb-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-tab {
  flex: 1;
  padding: 9px 4px;
  text-align: center;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
}
.sb-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.sb-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 6px;
}
.monitor-summary {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.monitor-summary b {
  color: var(--text);
}
.monitor-count {
  font-size: 13px;
  margin-top: 4px;
}
.monitor-count b {
  color: var(--accent);
}

.cat-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cat-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--bg);
}
.cat-chip input {
  margin: 0;
  accent-color: var(--accent);
}
.cat-chip .swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

#eventList {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ev-row {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 8px;
}
.ev-row:hover {
  background: var(--bg);
}
.ev-row.selected {
  background: var(--accent-dim);
}
.ev-main {
  flex: 1;
  min-width: 0;
}
.ev-title {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ev-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ev-status {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 10px;
}
.ev-status.open {
  background: var(--danger-dim);
  color: var(--danger);
}
.ev-status.closed {
  background: #e9ecef;
  color: var(--text-dim);
}

.empty-state,
.loading-state,
.error-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
}
.error-state {
  color: var(--danger);
}
.spinner {
  width: 16px;
  height: 16px;
  margin: 0 auto 8px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#detailPanel {
  display: none;
  flex-direction: column;
  height: 100%;
}
#detailPanel.open {
  display: flex;
}
.detail-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-shrink: 0;
}
.detail-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}
.back-btn {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 5px 9px;
  color: var(--text-dim);
}
.detail-body {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
}
.kv {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 4px 8px;
  font-size: 12px;
  margin-bottom: 12px;
}
.kv dt {
  color: var(--text-faint);
}
.kv dd {
  margin: 0;
  color: var(--text);
}
.detail-desc {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.timeline {
  border-left: 2px solid var(--border-strong);
  margin-left: 4px;
  padding-left: 12px;
}
.timeline-item {
  position: relative;
  padding-bottom: 12px;
  font-size: 12px;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline-item time {
  color: var(--text-faint);
  font-size: 11px;
  display: block;
}
.src-link {
  display: inline-block;
  font-size: 12px;
  margin-right: 10px;
  margin-top: 2px;
}

#aiPanel {
  display: none;
  flex-direction: column;
  height: 100%;
}
#aiPanel.open {
  display: flex;
}
#aiMessages {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  font-size: 12.5px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: var(--radius);
  max-width: 92%;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.msg.ai {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}
.msg.ai .fact {
  color: var(--text);
}
.msg.ai .note {
  color: var(--text-faint);
  font-style: italic;
  font-size: 11px;
  margin-top: 4px;
}
.ai-input-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#aiInput {
  flex: 1;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  resize: none;
}
#aiSend {
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
#aiSend svg {
  display: block;
}
#aiSend:disabled {
  opacity: 0.5;
  cursor: default;
}
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  flex-shrink: 0;
}
.ai-suggest-chip {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.ai-suggest-chip:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

#alertStack {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 280px;
}
.alert-toast {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  animation: slidein 0.25s ease;
}
@keyframes slidein {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
.alert-toast b {
  display: block;
  font-size: 12.5px;
  margin-bottom: 2px;
}
.alert-toast .close {
  float: right;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.tp-marker {
  background: none;
  border: none;
}
.tp-popup {
  font-family: var(--sans);
  font-size: 12px;
}
.tp-popup b {
  display: block;
  margin-bottom: 2px;
}

#bottomSheet {
  display: none;
}

@media (max-width: 820px) {
  .search-wrap {
    max-width: none;
  }
  .radius-box {
    display: none;
  }
  #sidebar {
    display: none;
  }

  #bottomSheet {
    display: flex;
    flex-direction: column;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--panel);
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    height: 44px;
    transition: height 0.25s ease;
    overflow: hidden;
  }
  #bottomSheet.expanded {
    height: 62%;
  }
  .sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 4px;
    flex-shrink: 0;
    cursor: pointer;
  }
  .sheet-handle .bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-strong);
  }
  .sheet-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 3px;
    font-weight: 600;
  }
  #bottomSheet .sb-tabs,
  #bottomSheet .sb-body {
    display: none;
  }
  #bottomSheet.expanded .sb-tabs,
  #bottomSheet.expanded .sb-body {
    display: flex;
  }
  #bottomSheet.expanded .sb-body {
    display: block;
  }
  #alertStack {
    width: calc(100% - 20px);
    top: 56px;
  }
}

/* loading dots for ai chat - couldnt think of a better name lol */
.typing-dots{
  display:inline-flex;
  align-items: center;
  gap:4px;
  padding: 2px 0px;
}
.typing-dots span {
  width:6px; height: 6px;
  border-radius: 50%;
  background:currentColor;
  opacity:.4;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2){ animation-delay:.15s }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce{
  0%, 60%, 100%{ transform:translateY(0); opacity:.4; }
  30% { transform: translateY(-4px); opacity:1; }
}
