/* ==========================================================================
   SiteOps Construction Dashboard — Stylesheet
   Industrial Precision, High Contrast, Mobile-First
   ========================================================================== */

:root {
  --bg-canvas: #090d16;
  --bg-surface: #0f172a;
  --bg-surface-elevated: #151f38;
  --bg-surface-active: #1e293b;
  --bg-input: #0a0e1a;
  
  --border-subtle: #1e293b;
  --border-default: #2a3754;
  --border-focus: #f59e0b;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #090d16;
  
  /* Status & Priority Accents */
  --amber-500: #f59e0b;
  --amber-400: #fbbf24;
  --amber-bg: rgba(245, 158, 11, 0.12);
  --amber-border: rgba(245, 158, 11, 0.35);

  --red-500: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --red-border: rgba(239, 68, 68, 0.35);

  --blue-500: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);
  --blue-border: rgba(59, 130, 246, 0.35);

  --emerald-500: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.12);
  --emerald-border: rgba(16, 185, 129, 0.35);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--amber-500);
  outline-offset: 2px;
}

/* Base App Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top Navigation */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background-color: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  padding: 0.75rem 1.25rem;
}

.nav-container {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

.brand-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.badge-env {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  background: var(--amber-bg);
  color: var(--amber-400);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-indicator-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.status-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--amber-500);
  box-shadow: 0 0 8px var(--amber-500);
  transition: var(--transition-fast);
}

.status-pulse-dot.online {
  background-color: var(--emerald-500);
  box-shadow: 0 0 8px var(--emerald-500);
}

.status-pulse-dot.offline {
  background-color: var(--red-500);
  box-shadow: 0 0 8px var(--red-500);
}

/* Button System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  color: #000000;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #fbbf24 0%, #b45309 100%);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.45);
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-active);
  border-color: #3b4e72;
}

/* Main Content */
.main-content {
  flex: 1;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* KPI Stats Section */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.kpi-card:hover {
  border-color: #3b4e72;
  transform: translateY(-1px);
}

.kpi-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-chip {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.chip-neutral {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
}

.chip-amber {
  background: var(--amber-bg);
  color: var(--amber-400);
}

.chip-blue {
  background: var(--blue-bg);
  color: #60a5fa;
}

.chip-emerald {
  background: var(--emerald-bg);
  color: #34d399;
}

.chip-red {
  background: var(--red-bg);
  color: #f87171;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #ffffff;
  line-height: 1.1;
}

.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Dashboard Grid (Feed + Form Drawer) */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  align-items: start;
}

/* Feed Column */
.feed-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Filter Panel */
.filter-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2rem 0.5rem 2.2rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast);
}

.search-box input:focus {
  border-color: var(--amber-500);
}

.btn-clear-search {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.25rem;
}

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

.filter-groups {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  background: var(--bg-canvas);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

.filter-pills .pill {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-pills .pill:hover {
  color: var(--text-primary);
}

.filter-pills .pill.active {
  background: var(--bg-surface-active);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.filter-select-wrap select {
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

/* Feed Container & States */
.feed-container {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.feed-state-box {
  background: var(--bg-surface);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  padding: 3rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.state-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-neutral {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-secondary);
}

.icon-red {
  background: var(--red-bg);
  color: var(--red-500);
}

.state-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
}

.state-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 420px;
}

/* Skeleton Loading */
.feed-state-loading {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.skeleton-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, #1e293b 25%, #2a3754 50%, #1e293b 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.w-30 { width: 30%; }
.w-40 { width: 40%; }
.w-50 { width: 50%; }
.w-60 { width: 60%; }
.w-70 { width: 70%; }
.w-75 { width: 75%; }
.w-80 { width: 80%; }

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

/* Observations List */
.observations-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.observation-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.observation-card:hover {
  border-color: #3b4e72;
  background: var(--bg-surface-elevated);
}

.obs-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.obs-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.obs-id-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.obs-id {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--amber-400);
}

.obs-timestamp {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.obs-title {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
}

.obs-badges {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge-open {
  background: var(--amber-bg);
  color: var(--amber-400);
  border: 1px solid var(--amber-border);
}

.badge-in-progress {
  background: var(--blue-bg);
  color: #60a5fa;
  border: 1px solid var(--blue-border);
}

.badge-resolved {
  background: var(--emerald-bg);
  color: #34d399;
  border: 1px solid var(--emerald-border);
}

.badge-priority-high {
  background: var(--red-bg);
  color: #f87171;
  border: 1px solid var(--red-border);
}

.badge-priority-medium {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border: 1px solid #334155;
}

.badge-priority-low {
  background: rgba(148, 163, 184, 0.08);
  color: #94a3b8;
  border: 1px solid #1e293b;
}

.obs-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-line;
}

.obs-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.obs-location {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  color: #e2e8f0;
}

.obs-location svg {
  color: var(--amber-500);
  flex-shrink: 0;
}

.obs-reporter {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
}

.obs-reporter strong {
  color: #cbd5e1;
}

/* Observation Form Drawer / Sidebar */
.form-column {
  position: sticky;
  top: 5rem;
}

.form-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}

.form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.form-kicker {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--amber-400);
  display: block;
  margin-bottom: 0.15rem;
}

.form-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.btn-close-drawer {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}

/* Form Controls */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

.required {
  color: var(--red-500);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  color: var(--text-primary);
  font-size: 1rem; /* 16px to prevent iOS auto-zoom */
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--amber-500);
  background-color: var(--bg-canvas);
  outline: none;
}

.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
  border-color: var(--red-500);
}

.field-feedback {
  font-size: 0.72rem;
  color: var(--red-500);
  min-height: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-alert {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin-bottom: 1rem;
}

.form-alert.alert-error {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: #fca5a5;
}

.form-alert.alert-success {
  background: var(--emerald-bg);
  border: 1px solid var(--emerald-border);
  color: #6ee7b7;
}

.form-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

.btn-submit {
  flex: 1;
}

.form-footnote {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.form-footnote code {
  font-family: var(--font-mono);
  background: var(--bg-canvas);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--amber-400);
}

/* Spinner */
.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 99;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  color: #ffffff;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 280px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.toast-success {
  border-left: 4px solid var(--emerald-500);
}

.toast.toast-error {
  border-left: 4px solid var(--red-500);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  padding: 1rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-container {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.footer-sep {
  color: var(--border-default);
}

.footer-tag {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.footer-endpoint-pill {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-canvas);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  color: var(--amber-400);
}

/* Utility Helpers */
.hidden {
  display: none !important;
}

/* Media Queries & Responsive Design */
@media (min-width: 992px) {
  .md-hidden {
    display: none !important;
  }
}

@media (max-width: 991px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .form-column {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 440px;
    background: rgba(9, 13, 22, 0.8);
    backdrop-filter: blur(8px);
    z-index: 50;
    padding: 1rem;
    overflow-y: auto;
    display: none;
  }

  .form-column.drawer-open {
    display: block;
    animation: drawerSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes drawerSlide {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }

  .nav-container {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .top-nav {
    padding: 0.6rem 0.85rem;
  }

  .brand-title {
    font-size: 1rem;
  }

  .brand-subtitle {
    display: none;
  }

  .nav-controls .btn-text {
    display: none;
  }

  .btn {
    padding: 0.5rem 0.75rem;
  }

  .kpi-section {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-section .kpi-card:last-child {
    grid-column: span 2;
  }

  .filter-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-groups {
    justify-content: space-between;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
