/* ============================================================
   Pinchpoint Dashboard — Shared Design Tokens + Layout
   ============================================================ */

:root {
  --bg:           #0f0f0f;
  --surface:      #1a1a1a;
  --surface-2:    #252525;
  --surface-3:    #2e2e2e;
  --border:       #333;
  --text:         #e8e8e8;
  --text-muted:   #888;
  --text-dim:     #555;
  --accent:       #E8750A;
  --accent-hover: #c96208;
  --accent-dim:   rgba(232, 117, 10, 0.15);
  --green:        #4caf50;
  --yellow:       #f59e0b;
  --red:          #ef4444;
  --blue:         #3b82f6;

  --nav-collapsed:  56px;
  --nav-expanded:   220px;
  --header-height:  48px;
  --nav-tab-height: 56px;
  --nav-transition: 0.18s ease;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
svg { display: block; }

/* ── Base ── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.app-header {
  height: var(--header-height);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px 0 0;
  gap: 0;
  z-index: 20;
}

.header-logo-area {
  flex-shrink: 0;
  padding: 0 20px 0 16px;
  display: flex;
  align-items: center;
}

.logo-mark {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}
.logo-mark .logo-dot { color: var(--text-muted); font-weight: 300; }

.header-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 8px 0 16px;
  overflow: hidden;
  gap: 0;
}

.header-property {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}
.header-property-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Property switcher — replaces static property name when user has >1 property */
.property-switcher {
  display: inline-flex;
  align-items: center;
}
.property-select {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0 18px 0 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.property-select:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.header-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.season-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.03em;
  margin-left: auto;
  flex-shrink: 0;
}

.header-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 8px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
  white-space: nowrap;
}
.header-logout:hover {
  opacity: 1;
  color: var(--text);
}

/* ── Body (sidebar + content) ── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Nav sidebar ── */
/* Sidebar — always icon-only, never expandable */
.nav-sidebar {
  width: var(--nav-collapsed);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: visible;  /* allow tooltips to escape */
  z-index: 10;
}

/* Toggle button hidden — sidebar is always icon-only */
.nav-toggle { display: none !important; }

/* Nav items list */
.nav-items {
  flex: 1;
  overflow: visible;  /* allow tooltips to escape */
  padding: 8px 0;
  scrollbar-width: none;
}
.nav-items::-webkit-scrollbar { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  color: var(--text-muted);
  border-left: 3px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  cursor: pointer;
  position: relative;
}
.nav-item:hover:not(.nav-disabled) {
  color: var(--text);
  background: var(--surface-2);
}
.nav-item.nav-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.nav-item.nav-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.nav-item svg { flex-shrink: 0; }

/* Labels and badges always hidden */
.nav-label,
.nav-coming-soon { display: none; }

/* Hover tooltip — appears to the right of icon */
.nav-item::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.1s;
}
.nav-item:hover:not(.nav-disabled)::after { opacity: 1; }

/* Nav divider */
.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

/* ── Page content ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
}
.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-track { background: transparent; }
.page-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Page header (inside content area) ── */
.page-heading {
  padding: 20px 24px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Summary bar ── */
.summary-bar {
  display: flex;
  gap: 0;
  padding: 16px 24px 0;
  flex-wrap: wrap;
  gap: 8px;
}
.summary-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
}
.summary-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}
.summary-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.summary-stat.stat-warn .summary-stat-value { color: var(--yellow); }
.summary-stat.stat-alert .summary-stat-value { color: var(--red); }

/* ── Utility ── */
.text-accent  { color: var(--accent); }
.text-muted   { color: var(--text-muted); }
.text-green   { color: var(--green); }
.text-yellow  { color: var(--yellow); }
.text-red     { color: var(--red); }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Loading / error states ── */
.state-loading,
.state-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 8px;
}
.state-error { color: var(--red); }

/* ── Pulse animation for auto-refresh indicator ── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
.refreshing { animation: pulse 1s ease-in-out 3; }

/* ── Mobile: hide sidebar, account for bottom tab bar ───────── */
@media (max-width: 768px) {
  .nav-sidebar { display: none !important; }
  /* Shrink the app-body so content never hides behind the fixed tab bar */
  .app-body {
    padding-bottom: calc(var(--nav-tab-height) + env(safe-area-inset-bottom, 0px));
  }
  /* Season badge crowds the header on narrow widths — season state is
     available in chat and reports, so hiding it here is safe. */
  .season-badge,
  #season-badge { display: none !important; }
}

/* ── Bottom tab bar (mobile only) ───────────────────────────── */
.nav-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-tab-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  /* Must exceed Leaflet's highest internal pane (popup-pane = 700) */
  z-index: 2000;
  flex-direction: row;
  align-items: stretch;
}

@media (max-width: 768px) {
  .nav-tab-bar { display: flex; }
}

.nav-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-decoration: none;
  min-height: 44px;
  padding: 6px 2px 4px;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.nav-tab-item svg { flex-shrink: 0; }
.nav-tab-item:hover,
.nav-tab-item:active { color: var(--text); }
.nav-tab-item.nav-tab-active { color: var(--accent); }

/* ── Zoom overlay (lightbox with click-to-zoom + drag-to-pan) ── */
#zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.96);
  overflow: hidden;
  display: none;
  cursor: zoom-in;
}
#zoom-overlay.open { display: flex; align-items: center; justify-content: center; }
#zoom-overlay.zoomed { cursor: grab; }
#zoom-overlay.zoomed.dragging { cursor: grabbing; }
#zoom-close {
  position: fixed;
  top: 14px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: rgba(30,30,30,0.85);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2001;
  transition: background 0.15s;
  padding: 0;
  font-family: inherit;
}
#zoom-close:hover { background: var(--surface-3); }
#zoom-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  display: block;
  opacity: 0;
  transition: opacity 0.15s;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
#zoom-img.loaded { opacity: 1; }
