/* =====================================================
   kbWatch — Dark Intelligence Dashboard
   ===================================================== */

:root {
  --bg:       #0a0c10;
  --bg2:      #0f1218;
  --bg3:      #161b24;
  --border:   #1e2736;
  --accent:   #00d4ff;
  --accent2:  #0a7cff;
  --text:     #c8d6e8;
  --text-dim: #5a6a80;
  --text-hi:  #ffffff;
  --sidebar-w: 270px;
  --topbar-h:  48px;
  --statsbar-h: 36px;
  --panel-w:   340px;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── LOCK SCREEN ─────────────────────────────────── */
#lockscreen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.lock-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  user-select: none;
}
.lock-logo {
  font-size: 2rem; font-weight: 800; letter-spacing: -1px; color: var(--text-hi);
}
.lock-logo span { color: var(--accent); }
.lock-sub {
  font-size: 0.62rem; letter-spacing: 3px; color: var(--text-dim);
  text-transform: uppercase;
}
.lock-dots {
  display: flex; gap: 16px; margin: 4px 0;
}
.lock-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.lock-dots span.filled {
  background: var(--accent); border-color: var(--accent);
}
.lock-error {
  font-size: 0.72rem; color: #ff4d4d; letter-spacing: 1px;
  opacity: 0; transition: opacity 0.2s; height: 1em;
}
.lock-error.visible { opacity: 1; }
.lock-grid {
  display: grid; grid-template-columns: repeat(3, 72px);
  gap: 10px;
}
.kp {
  height: 72px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text-hi); font-size: 1.4rem; font-weight: 600;
  cursor: pointer; transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.kp:hover  { background: var(--border); border-color: var(--accent); }
.kp:active { transform: scale(0.92); }
.kp-clear  { font-size: 1.1rem; color: var(--text-dim); }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-10px); }
  40%      { transform: translateX(10px); }
  60%      { transform: translateX(-8px); }
  80%      { transform: translateX(8px); }
}
.shake { animation: shake 0.5s ease; }

/* ── TOP BAR ─────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
}
.logo { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.5px; color: var(--text-hi); }
.logo-accent { color: var(--accent); }
.tagline { font-size: 0.68rem; color: var(--text-dim); margin-left: 10px; text-transform: uppercase; letter-spacing: 1px; }
.clock { font-family: monospace; font-size: 0.9rem; color: var(--accent); letter-spacing: 2px; }
.status-pill {
  display: flex; align-items: center; gap: 7px;
  background: #0d1a0d; border: 1px solid #1a3a1a;
  padding: 4px 12px; border-radius: 20px; font-size: 0.75rem; color: #4cff88;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4cff88;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}
.btn-icon {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  margin-left: 10px; transition: background 0.2s;
}
.btn-icon:hover { background: var(--bg3); }
.topbar-right { display: flex; align-items: center; }

/* ── LAYOUT ──────────────────────────────────────── */
.layout {
  display: flex;
  position: fixed;
  top: var(--topbar-h);
  bottom: var(--statsbar-h);
  left: 0; right: 0;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.3s, min-width 0.3s;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; }
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section { border-bottom: 1px solid var(--border); padding: 12px 14px; }
.section-title {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.badge {
  background: var(--accent2); color: #fff;
  font-size: 0.62rem; padding: 1px 6px; border-radius: 20px; font-weight: 700;
}

/* Search */
.search-wrap { position: relative; }
.search-wrap input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 7px 32px 7px 10px; border-radius: 6px;
  font-size: 0.8rem; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-icon { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 0.8rem; color: var(--text-dim); }

/* Legend */
.legend { display: flex; flex-direction: column; gap: 7px; }
.legend-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.78rem; cursor: pointer; user-select: none;
}
.legend-item input { accent-color: var(--accent); cursor: pointer; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Severity */
.severity-row { display: flex; gap: 14px; font-size: 0.78rem; }
.severity-row label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.severity-row input { accent-color: var(--accent); }

/* Feed list */
.feed-section { flex: 1; }
.feed-list { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.feed-list::-webkit-scrollbar { width: 3px; }
.feed-list::-webkit-scrollbar-thumb { background: var(--border); }
.feed-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; cursor: pointer;
  transition: border-color 0.2s; display: flex; gap: 8px; align-items: flex-start;
}
.feed-item:hover { border-color: var(--accent); }
.feed-item-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }
.feed-item-text { flex: 1; }
.feed-item-title { font-size: 0.73rem; color: var(--text-hi); line-height: 1.3; }
.feed-item-meta { font-size: 0.62rem; color: var(--text-dim); margin-top: 3px; }

/* Sources */
.sources-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.sources-list li { font-size: 0.7rem; color: var(--text-dim); display: flex; align-items: center; gap: 7px; }
.src-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ── MAP ─────────────────────────────────────────── */
.map-container { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; background: #080c14; }

/* Leaflet overrides */
.leaflet-container { background: #080c14; }
.leaflet-control-zoom a {
  background: var(--bg3) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg) !important; }
.leaflet-popup-content-wrapper {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.leaflet-popup-tip { background: var(--bg2); }
.leaflet-popup-content { margin: 10px 14px; }

/* Event dot markers */
.event-marker {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  cursor: pointer;
  transition: transform 0.15s;
  animation: markerPop 0.3s ease-out;
}
.event-marker:hover { transform: scale(1.4); z-index: 9999 !important; }
@keyframes markerPop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.event-marker.severity-high {
  box-shadow: 0 0 10px 3px currentColor;
  animation: markerPop 0.3s ease-out, glowPulse 2s ease-in-out infinite;
}
@keyframes glowPulse {
  0%,100% { box-shadow: 0 0 6px 2px currentColor; }
  50%      { box-shadow: 0 0 16px 6px currentColor; }
}

/* ── DETAIL PANEL ────────────────────────────────── */
.detail-panel {
  position: absolute;
  top: 16px; right: 16px;
  width: var(--panel-w);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  z-index: 900;
  display: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
  animation: slideIn 0.2s ease-out;
}
.detail-panel.open { display: block; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.detail-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--text-dim);
  font-size: 1rem; cursor: pointer;
}
.detail-close:hover { color: var(--text-hi); }
.detail-type-badge {
  display: inline-block;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px; margin-bottom: 10px;
  background: var(--bg3); border: 1px solid var(--border);
}
.detail-title { font-size: 1rem; font-weight: 700; color: var(--text-hi); line-height: 1.35; margin-bottom: 8px; }
.detail-time { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 6px; font-family: monospace; }
.detail-severity { font-size: 0.72rem; margin-bottom: 10px; font-weight: 600; }
.detail-body { font-size: 0.78rem; line-height: 1.55; color: var(--text); border-top: 1px solid var(--border); padding-top: 10px; margin-bottom: 10px; }
.detail-coords { font-size: 0.67rem; color: var(--text-dim); font-family: monospace; }

/* ── LOADING OVERLAY ─────────────────────────────── */
.map-loading {
  position: absolute; inset: 0;
  background: rgba(10,12,16,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; z-index: 800; font-size: 0.85rem; color: var(--text-dim);
  transition: opacity 0.4s;
}
.map-loading.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── STATS BAR ───────────────────────────────────── */
.statsbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--statsbar-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px; gap: 24px;
  z-index: 1000;
}
.stat { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; }
.stat:first-child { color: #ff4d4d; }
.refresh-stat { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.btn-refresh {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--accent); padding: 2px 10px; border-radius: 4px;
  font-size: 0.72rem; cursor: pointer; transition: background 0.2s;
}
.btn-refresh:hover { background: var(--border); }

/* ── POPUP CONTENT ───────────────────────────────── */
.popup-title { font-weight: 700; font-size: 0.85rem; color: var(--text-hi); margin-bottom: 4px; }
.popup-type  { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 6px; }
.popup-desc  { font-size: 0.75rem; color: var(--text); line-height: 1.4; }
.popup-more  { display: inline-block; margin-top: 8px; font-size: 0.7rem; color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 950; width: 100% !important; }
  .detail-panel { width: calc(100vw - 32px); }
  .tagline, .topbar-center { display: none; }
}
