/* UAP Watch Dashboard */

:root {
  --bg-deep:       #0f0e0c;
  --bg-dark:       #141210;
  --bg-panel:      #1a1714;
  --bg-mid:        #201d19;
  --bg-raised:     #262220;
  --text-primary:  #e8e0d4;
  --text-muted:    #9a8e7f;
  --text-dim:      #6b6057;
  --accent:        #c4956a;
  --accent-hover:  #d9ad82;
  --rule:          rgba(154, 142, 127, 0.12);

  --tier-official:    #c4956a;
  --tier-investigated:#8fa86c;
  --tier-civilian:    #6b8fa8;
  --tier-community:   #7a7070;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Outfit', system-ui, sans-serif;

  --radius: 8px;
  --radius-sm: 4px;
}

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

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

body {
  font-family: var(--font-body);
  font-weight: 300;
  color: var(--text-primary);
  background: var(--bg-deep);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- GRAIN --- */
.grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- HEADER --- */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg-dark);
  position: sticky;
  top: 0;
  z-index: 100;
}

.dash-header__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.dash-header__sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

.dash-header__right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.dash-header__updated {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.dash-header__refresh {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.dash-header__refresh:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.dash-header__refresh svg {
  flex-shrink: 0;
}

/* --- MAIN GRID --- */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 380px 420px 1fr;
  grid-template-areas:
    "map   feed"
    "stats feed"
    "timeline news";
  gap: 1px;
  background: var(--rule);
  min-height: calc(100vh - 60px);
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel--map      { grid-area: map; }
.panel--feed     { grid-area: feed; grid-row: 1 / 3; }
.panel--stats    { grid-area: stats; }
.panel--timeline { grid-area: timeline; min-height: 260px; }
.panel--news     { grid-area: news; min-height: 260px; }

/* --- PANEL HEADER --- */
.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

.panel__title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.panel__meta {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.panel__source-note {
  font-size: 0.68rem;
  color: var(--text-dim);
  padding: 0.4rem 0.75rem;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}

/* --- TIER BADGES --- */
.tier {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
}

.tier--official    { background: rgba(196,149,106,0.15); color: var(--tier-official); }
.tier--investigated{ background: rgba(143,168,108,0.12); color: var(--tier-investigated); }
.tier--civilian    { background: rgba(107,143,168,0.12); color: var(--tier-civilian); }
.tier--community   { background: rgba(122,112,112,0.12); color: var(--tier-community); }

/* --- MAP --- */
#map {
  flex: 1;
  min-height: 360px;
}

#map .leaflet-container {
  background: var(--bg-dark);
}

/* Custom Leaflet tiles override */
.leaflet-tile-pane {
  filter: brightness(0.4) saturate(0.6);
}

/* --- SIGHTING FEED --- */
.sighting-feed {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0.5rem 0;
}

.sighting-feed__loading,
.sighting-feed__empty {
  padding: 1.5rem 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}

.sighting-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background 0.15s;
}

.sighting-item:hover {
  background: var(--bg-raised);
}

.sighting-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.sighting-item__location {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 400;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sighting-item__date {
  font-size: 0.72rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sighting-item__bottom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sighting-item__shape {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.sighting-item__duration {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.sighting-item__text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- TIER LEGEND IN FEED HEADER --- */
.tier-legend {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* --- STATS --- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  padding: 0.75rem;
  gap: 0.75rem;
  overflow-y: auto;
  min-height: 0;
}

.stat-chart__label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* --- TIMELINE --- */
.timeline {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0.75rem 1rem;
}

.timeline__loading {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 1rem 0;
}

.timeline__item {
  position: relative;
  padding-left: 1.25rem;
  padding-bottom: 1.25rem;
}

.timeline__item::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 6px;
  width: 1px;
  bottom: 0;
  background: var(--rule);
}

.timeline__item:last-child::before {
  display: none;
}

.timeline__dot {
  position: absolute;
  left: 0;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.timeline__item--released .timeline__dot  { background: var(--accent); }
.timeline__item--expected .timeline__dot  { background: var(--text-muted); border: 1px solid var(--text-muted); background: transparent; }
.timeline__item--historical .timeline__dot{ background: var(--text-dim); }

.timeline__date {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.2rem;
}

.timeline__title {
  font-size: 0.82rem;
  color: var(--text-primary);
  font-weight: 400;
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.timeline__title a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(196,149,106,0.4);
}

.timeline__title a:hover {
  color: var(--accent-hover);
}

.timeline__desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.timeline__source-tag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  margin-top: 0.3rem;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--rule);
}

/* --- NEWS FEED --- */
.news-feed {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.news-feed__loading,
.news-feed__empty {
  padding: 1.5rem 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}

.news-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--rule);
}

.news-item__outlet {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 0.2rem;
}

.news-item__title {
  font-size: 0.82rem;
  color: var(--text-primary);
  line-height: 1.45;
  display: block;
  margin-bottom: 0.25rem;
}

.news-item__title:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.news-item__date {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.news-feed__fallback {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* --- MODAL --- */
.sighting-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.sighting-modal[hidden] {
  display: none;
}

.sighting-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 8, 0.75);
  cursor: pointer;
}

.sighting-modal__card {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.sighting-modal__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.sighting-modal__close:hover { color: var(--text-primary); }

.modal-location {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.modal-meta__item {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.modal-meta__item strong {
  color: var(--text-primary);
  font-weight: 400;
}

.modal-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.65;
  border-top: 1px solid var(--rule);
  padding-top: 0.75rem;
}

/* --- FOOTER --- */
.dash-footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.6;
  background: var(--bg-dark);
}

.dash-footer strong {
  color: var(--text-muted);
  font-weight: 400;
}

/* --- LEAFLET OVERRIDES --- */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  font-family: var(--font-body);
}

.leaflet-popup-tip {
  background: var(--bg-panel);
}

.leaflet-popup-content {
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0.6rem 0.75rem;
}

.map-popup__location {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.map-popup__shape {
  color: var(--text-muted);
  text-transform: capitalize;
}

.map-popup__more {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.75rem;
  display: block;
  margin-top: 0.35rem;
}

/* --- LOADING STATES --- */
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.9; }
}

.is-loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* --- MOBILE --- */
@media (max-width: 900px) {
  .dash-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 300px auto auto auto auto;
    grid-template-areas:
      "map"
      "stats"
      "feed"
      "timeline"
      "news";
  }

  .panel--feed { grid-row: auto; max-height: 400px; }

  .dash-header__sub { display: none; }
  .tier-legend { display: none; }

  #map { min-height: 280px; }

  .stats-grid { grid-template-columns: 1fr; }

  .panel--timeline,
  .panel--news {
    max-height: 360px;
  }
}

@media (max-width: 600px) {
  .dash-header { padding: 0.75rem 1rem; }
  .dash-header__updated { display: none; }
}
