/* ==========================================================================
   InTraffic Camera Dashboard — app.css
   Light professional theme for staff-facing traffic analytics
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  /* Brand */
  --color-navy:       #1e3a5f;
  --color-navy-dark:  #152b47;

  /* Backgrounds */
  --color-bg:         #f8f9fa;
  --color-bg-white:   #ffffff;

  /* Borders */
  --color-border:     #e5e7eb;
  --color-border-md:  #d1d5db;

  /* Text */
  --color-text:       #111827;
  --color-text-secondary: #6b7280;
  --color-text-muted: #9ca3af;

  /* Semantic colors */
  --color-blue:       #2563eb;
  --color-blue-light: #eff6ff;
  --color-blue-dark:  #1d4ed8;
  --color-green:      #16a34a;
  --color-green-light:#f0fdf4;
  --color-amber:      #d97706;
  --color-amber-light:#fffbeb;
  --color-red:        #dc2626;
  --color-red-light:  #fef2f2;
  --color-orange:     #ea580c;
  --color-orange-light:#fff7ed;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-lg:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);

  /* Radius */
  --radius-sm:  4px;
  --radius:     8px;
  --radius-lg:  12px;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'SF Mono', Consolas, monospace;
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

ul {
  list-style: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
}

/* --------------------------------------------------------------------------
   App Shell Layout
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  min-height: 100vh;
}

#main-app {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo span {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.01em;
}

.nav-links {
  flex: 1;
  padding: 12px 0;
}

.nav-links li {
  margin: 2px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.7);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

.nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
  text-decoration: none;
}

.nav-link.active {
  background: rgba(255,255,255,0.15);
  color: #ffffff;
}

.nav-link svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-link.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer #user-name {
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Content Area
   -------------------------------------------------------------------------- */
#content-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   Top Bar
   -------------------------------------------------------------------------- */
#top-bar {
  height: var(--topbar-height);
  background: var(--color-bg-white);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 16px;
}

.top-bar-left {
  flex: 1;
  min-width: 0;
}

.top-bar-left h1 {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Page Content
   -------------------------------------------------------------------------- */
#page-content {
  flex: 1;
  padding: 24px;
  min-width: 0;
}

.page-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   KPI / Metric Cards
   -------------------------------------------------------------------------- */
.kpi-card {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Grid Utilities
   -------------------------------------------------------------------------- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.kpi-row {
  /* inherits from grid-4 */
}

/* Dashboard-specific grids */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dashboard-grid-2 {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
}

.page-dashboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* --------------------------------------------------------------------------
   Data Tables
   -------------------------------------------------------------------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead tr {
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:nth-child(even) {
  background: #fafafa;
}

.data-table tbody tr:hover {
  background: var(--color-blue-light);
}

.data-table tbody tr.row-alert {
  background: #fff5f5;
}

.data-table tbody tr.row-alert:hover {
  background: #fee2e2;
}

.data-table small {
  font-size: 11px;
  color: var(--color-text-secondary);
}

/* --------------------------------------------------------------------------
   Status Pills
   -------------------------------------------------------------------------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-pill::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill-online {
  background: var(--color-green-light);
  color: #15803d;
}
.pill-online::before {
  background: var(--color-green);
}

.pill-degraded {
  background: var(--color-amber-light);
  color: #92400e;
}
.pill-degraded::before {
  background: var(--color-amber);
}

.pill-offline {
  background: #f3f4f6;
  color: #374151;
}
.pill-offline::before {
  background: #9ca3af;
}

/* --------------------------------------------------------------------------
   Severity Badges
   -------------------------------------------------------------------------- */
.severity-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-critical {
  background: var(--color-red-light);
  color: var(--color-red);
  border: 1px solid #fca5a5;
}

.badge-high {
  background: var(--color-orange-light);
  color: var(--color-orange);
  border: 1px solid #fed7aa;
}

.badge-medium {
  background: var(--color-amber-light);
  color: var(--color-amber);
  border: 1px solid #fde68a;
}

.badge-low {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

/* --------------------------------------------------------------------------
   General Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-success {
  background: var(--color-green-light);
  color: #15803d;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-blue);
  color: #ffffff;
  border-color: var(--color-blue);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-blue-dark);
  border-color: var(--color-blue-dark);
  text-decoration: none;
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border-md);
}
.btn-outline:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: #9ca3af;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: rgba(255,255,255,0.7);
  border: none;
  padding: 6px 0;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s;
}
.btn-ghost:hover {
  color: #ffffff;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* --------------------------------------------------------------------------
   Form Elements
   -------------------------------------------------------------------------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
select {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border-md);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--color-text);
  background: var(--color-bg-white);
  transition: border-color 0.12s, box-shadow 0.12s;
  appearance: none;
  -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="search"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
  cursor: pointer;
}

.input-sm {
  padding: 5px 8px;
  font-size: 13px;
  width: auto;
}

/* --------------------------------------------------------------------------
   Filter Row / Toolbar
   -------------------------------------------------------------------------- */
.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  margin-bottom: 0;
  white-space: nowrap;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.filter-card {
  padding: 16px 20px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   Login Screen
   -------------------------------------------------------------------------- */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-logo span {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-navy);
}

.login-card h2 {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--color-text);
}

.login-card form label {
  margin-top: 14px;
}

.login-card form input {
  width: 100%;
  margin-bottom: 2px;
}

.login-card .btn-block {
  margin-top: 20px;
  padding: 10px;
  font-size: 14.5px;
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 8px;
}

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

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  max-width: 380px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: var(--color-red);
}

.toast-success {
  background: var(--color-green);
}

.toast-warning {
  background: var(--color-amber);
}

/* --------------------------------------------------------------------------
   Empty State
   -------------------------------------------------------------------------- */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13.5px;
}

.empty-state::before {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  background: var(--color-border);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 20px;
}

/* --------------------------------------------------------------------------
   Skeleton Loaders
   -------------------------------------------------------------------------- */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.skeleton {
  background: #e5e7eb;
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-table {
  height: 200px;
  background: #f3f4f6;
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  margin: 16px;
}

/* --------------------------------------------------------------------------
   Chart Containers
   -------------------------------------------------------------------------- */
.chart-wrap {
  padding: 16px 20px;
  min-height: 280px;
  position: relative;
}

.chart-wrap canvas {
  max-height: 320px;
}

/* --------------------------------------------------------------------------
   Map Card
   -------------------------------------------------------------------------- */
.map-card {
  overflow: hidden;
}

.map-card #dashboard-map {
  border-radius: 0 0 8px 8px;
}

/* MapLibre overrides for clean look */
.maplibregl-popup-content {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.maplibregl-popup-close-button {
  font-size: 16px;
  padding: 2px 6px;
}

/* --------------------------------------------------------------------------
   Text Utilities
   -------------------------------------------------------------------------- */
.text-muted {
  color: var(--color-text-secondary);
}

.text-danger {
  color: var(--color-red) !important;
}

.text-success {
  color: var(--color-green);
}

/* --------------------------------------------------------------------------
   Export Form
   -------------------------------------------------------------------------- */
.export-form {
  padding: 20px;
}

/* --------------------------------------------------------------------------
   Responsive — Mobile (< 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  :root {
    --sidebar-width: 0px;
  }

  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s;
    width: 240px;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #content-area {
    margin-left: 0;
  }

  #top-bar {
    padding: 0 16px;
    flex-wrap: wrap;
    height: auto;
    padding-top: 10px;
    padding-bottom: 10px;
    gap: 8px;
  }

  .top-bar-right {
    flex-wrap: wrap;
    gap: 6px;
  }

  #page-content {
    padding: 16px;
  }

  .dashboard-grid,
  .dashboard-grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .filter-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .login-card {
    padding: 28px 24px;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 10px;
  }
}

/* --------------------------------------------------------------------------
   Responsive — Small Desktop (768px–1024px)
   -------------------------------------------------------------------------- */
@media (min-width: 768px) and (max-width: 1024px) {
  .dashboard-grid,
  .dashboard-grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-4 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --------------------------------------------------------------------------
   Responsive — Large (> 1400px)
   -------------------------------------------------------------------------- */
@media (min-width: 1400px) {
  .grid-4 {
    grid-template-columns: repeat(6, 1fr);
  }
}
