/* ══════════════════════════════════════════════════════════════
   OSINT Intelligence Dashboard — intelligence.hartmann.id
   Palantir-style dark theme
   ══════════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0a0a0a;
  --bg-widget: #111111;
  --bg-widget-header: #161616;
  --bg-hover: #1a1a1a;
  --border: #222222;
  --border-light: #2a2a2a;

  --text-primary: #d4d4d4;
  --text-secondary: #777777;
  --text-muted: #555555;
  --text-accent: #00ff88;
  --text-danger: #ff4444;
  --text-warning: #ffaa00;
  --text-info: #4488ff;

  --green: #00cc66;
  --yellow: #ffcc00;
  --red: #ff3333;
  --orange: #ff8800;
  --blue: #3388ff;
  --gray: #444444;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --font-size-xs: 0.65rem;
  --font-size-sm: 0.75rem;
  --font-size-base: 0.8125rem;
  --font-size-lg: 0.9375rem;

  --radius: 0;
  --widget-gap: 1px;
}

/* ── Reset ─────────────────────────────────────────────────── */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-mono);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: var(--text-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Header ────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-widget);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-title {
  font-size: var(--font-size-sm);
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 600;
}

.header-meta {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-time {
  color: var(--text-muted);
}

/* ── Map Hero ──────────────────────────────────────────────── */

.map-hero {
  height: 45vh;
  min-height: 300px;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.map-hero #map {
  height: 100%;
  width: 100%;
  background: var(--bg-primary);
}

/* Leaflet overrides for dark theme */
.leaflet-container {
  background: var(--bg-primary) !important;
  font-family: var(--font-mono) !important;
}

.leaflet-control-attribution {
  display: none !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-widget) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  font-family: var(--font-mono) !important;
  font-size: var(--font-size-sm) !important;
}

.leaflet-popup-tip {
  background: var(--bg-widget) !important;
}

/* ── Widget Grid ───────────────────────────────────────────── */

.widget-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--widget-gap);
  background: var(--border);
}

/* ── Widget Frame ──────────────────────────────────────────── */

.widget {
  background: var(--bg-widget);
  display: flex;
  flex-direction: column;
  min-height: 280px;
  max-height: 400px;
  overflow: hidden;
}

.widget--wide {
  grid-column: span 2;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-widget-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.widget-title {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

.widget-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}

.status-dot--live { background: var(--green); }
.status-dot--stale { background: var(--yellow); }
.status-dot--error { background: var(--red); }

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--font-size-sm);
  padding: 2px;
  line-height: 1;
  font-family: var(--font-mono);
}

.refresh-btn:hover {
  color: var(--text-primary);
}

.widget-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.widget-body::-webkit-scrollbar {
  width: 4px;
}

.widget-body::-webkit-scrollbar-thumb {
  background: var(--border-light);
}

/* ── Data Items ────────────────────────────────────────────── */

.data-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--font-size-sm);
}

.data-row:last-child {
  border-bottom: none;
}

.data-row:hover {
  background: var(--bg-hover);
  margin: 0 -10px;
  padding-left: 10px;
  padding-right: 10px;
}

.data-label {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.data-value {
  color: var(--text-primary);
}

.data-value--positive {
  color: var(--green);
}

.data-value--negative {
  color: var(--red);
}

.data-value--warning {
  color: var(--yellow);
}

.data-time {
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Earthquake-specific ───────────────────────────────────── */

.quake-mag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 22px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  border-radius: 2px;
  flex-shrink: 0;
}

.quake-mag--low { background: #1a3320; color: var(--green); }
.quake-mag--medium { background: #33310a; color: var(--yellow); }
.quake-mag--high { background: #331a0a; color: var(--orange); }
.quake-mag--severe { background: #331010; color: var(--red); }

.quake-place {
  color: var(--text-primary);
  font-size: var(--font-size-sm);
}

.quake-depth {
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

/* ── News-specific ─────────────────────────────────────────── */

.news-source {
  font-size: var(--font-size-xs);
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  min-width: 50px;
}

.news-title {
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  line-height: 1.3;
}

.news-title a {
  color: var(--text-primary);
}

.news-title a:hover {
  color: var(--text-accent);
}

/* ── Markets-specific ──────────────────────────────────────── */

.market-row {
  display: grid;
  grid-template-columns: 70px 1fr 80px 60px 50px;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--font-size-sm);
}

.market-symbol {
  color: var(--text-accent);
  font-weight: 600;
  font-size: var(--font-size-xs);
}

.market-name {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-price {
  text-align: right;
  font-weight: 600;
}

.market-change {
  text-align: right;
  font-size: var(--font-size-xs);
}

/* ── Sparkline ─────────────────────────────────────────────── */

.sparkline {
  display: inline-block;
  vertical-align: middle;
}

.sparkline polyline {
  fill: none;
  stroke-width: 1.2;
}

/* ── Social-specific ───────────────────────────────────────── */

.social-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}

.social-tab {
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-mono);
  border-bottom: 2px solid transparent;
}

.social-tab:hover {
  color: var(--text-secondary);
}

.social-tab--active {
  color: var(--text-accent);
  border-bottom-color: var(--text-accent);
}

.social-score {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  min-width: 40px;
  text-align: right;
}

/* ── Flight/Ship-specific ──────────────────────────────────── */

.callsign {
  color: var(--text-accent);
  font-weight: 600;
  font-size: var(--font-size-xs);
  min-width: 60px;
}

.vessel-name {
  color: var(--text-accent);
  font-weight: 600;
  font-size: var(--font-size-xs);
  min-width: 80px;
}

.altitude, .speed {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
}

/* ── Status Bar ────────────────────────────────────────────── */

.status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 12px;
  background: var(--bg-widget);
  border-top: 1px solid var(--border);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  position: sticky;
  bottom: 0;
  z-index: 1000;
  overflow-x: auto;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.status-label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Loading / Skeleton ────────────────────────────────────── */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, var(--border) 25%, var(--border-light) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 2px;
}

.skeleton-line:nth-child(odd) { width: 85%; }
.skeleton-line:nth-child(even) { width: 60%; }

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ── Error State ───────────────────────────────────────────── */

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 120px;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
  gap: 4px;
}

.error-state-icon {
  font-size: 1.2rem;
  opacity: 0.4;
}

.error-state-msg {
  color: var(--text-secondary);
}

/* ── HTMX loading indicator ───────────────────────────────── */

.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* ── Alpine.js cloak ──────────────────────────────────────── */

[x-cloak] {
  display: none !important;
}

/* ── Settings Panel ───────────────────────────────────────── */

.settings-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-lg);
  padding: 2px 6px;
  line-height: 1;
  font-family: var(--font-mono);
  transition: color 0.15s, border-color 0.15s;
}

.settings-btn:hover {
  color: var(--text-accent);
  border-color: var(--text-accent);
}

.settings-panel {
  position: fixed;
  top: 40px;
  right: 0;
  width: 300px;
  max-height: calc(100vh - 40px);
  background: var(--bg-widget);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  z-index: 999;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 4px 16px rgba(0, 0, 0, 0.5);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-widget-header);
  border-bottom: 1px solid var(--border);
}

.settings-title {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

.settings-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
  font-family: var(--font-mono);
}

.settings-close:hover {
  color: var(--text-primary);
}

.settings-body {
  padding: 8px 12px;
  overflow-y: auto;
  flex: 1;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: var(--font-size-sm);
}

.settings-item:last-of-type {
  border-bottom: none;
}

.settings-item:hover {
  background: var(--bg-hover);
  margin: 0 -12px;
  padding-left: 12px;
  padding-right: 12px;
}

.settings-item input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-light);
  background: var(--bg-primary);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.settings-item input[type="checkbox"]:checked {
  background: var(--text-accent);
  border-color: var(--text-accent);
}

.settings-item input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: -1px;
  left: 1px;
  font-size: 11px;
  color: var(--bg-primary);
  font-weight: bold;
}

.settings-item-label {
  color: var(--text-primary);
  flex: 1;
}

.settings-item-id {
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.settings-actions {
  display: flex;
  gap: 8px;
  padding: 10px 0 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.settings-action-btn {
  flex: 1;
  padding: 5px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color 0.15s, border-color 0.15s;
}

.settings-action-btn:hover {
  color: var(--text-accent);
  border-color: var(--text-accent);
}

/* ── Leaflet Layer Control (dark theme) ──────────────────── */

.leaflet-control-layers {
  background: var(--bg-widget) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  color: var(--text-primary) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5) !important;
}

.leaflet-control-layers-toggle {
  background-color: var(--bg-widget) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  width: 30px !important;
  height: 30px !important;
}

.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
}

.leaflet-control-layers-overlays label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  cursor: pointer;
}

.leaflet-control-layers-overlays label:hover {
  color: var(--text-accent);
}

.leaflet-control-layers-separator {
  border-top-color: var(--border) !important;
}

/* Leaflet zoom control dark */
.leaflet-bar a {
  background-color: var(--bg-widget) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: 0 !important;
  width: 28px !important;
  height: 28px !important;
  line-height: 28px !important;
  font-family: var(--font-mono) !important;
}

.leaflet-bar a:hover {
  background-color: var(--bg-hover) !important;
  color: var(--text-accent) !important;
}

/* ── Conflict-specific ────────────────────────────────────── */

.conflict-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.conflict-type--battle { background: #331010; color: var(--red); }
.conflict-type--explosion { background: #331a0a; color: var(--orange); }
.conflict-type--violence { background: #331015; color: #ff4466; }
.conflict-type--protest { background: #33310a; color: var(--yellow); }
.conflict-type--riot { background: #33200a; color: #ff6600; }
.conflict-type--strategic { background: #0a1a33; color: var(--blue); }

.conflict-location {
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  flex: 1;
}

.conflict-fatalities {
  color: var(--red);
  font-size: var(--font-size-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.military-badge {
  display: inline-block;
  padding: 0 4px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--red);
  background: #331010;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 1200px) {
  .widget-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .widget-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .widget--wide {
    grid-column: span 2;
  }
}

@media (max-width: 600px) {
  .widget-grid {
    grid-template-columns: 1fr;
  }
  .widget--wide {
    grid-column: span 1;
  }
  .map-hero {
    height: 35vh;
    min-height: 220px;
  }
  .header-meta {
    display: none;
  }
  .market-row {
    grid-template-columns: 60px 1fr 70px 50px;
  }
  .market-name {
    display: none;
  }
}
