/* ==========================================================================
   EXAIRSENSE CMS - Modern Flat Design System
   Green Smart Campus Air Quality Monitoring Platform
   ========================================================================== */

:root {
  /* Slate neutral palette */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  
  /* Text tokens */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  /* Primary & accent palette (flat, clean, vivid) */
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-border: #a7f3d0;
  
  /* Semantic status colors */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;
  
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;
  
  --info: #0ea5e9;
  --info-bg: #f0f9ff;
  --info-border: #bae6fd;
  --info-text: #0369a1;

  --purple: #8b5cf6;
  --purple-bg: #f5f3ff;
  --purple-border: #ddd6fe;
  --purple-text: #6d28d9;
  
  /* Modern Flat Elevation (minimal crisp shadows) */
  --shadow-flat: 0 1px 3px 0 rgba(15, 23, 42, 0.04), 0 1px 2px -1px rgba(15, 23, 42, 0.03);
  --shadow-hover: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;
  
  --transition: all 0.15s ease-in-out;
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   App Layout Shell
   ========================================================================== */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px 1fr;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--primary);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

.brand small {
  color: var(--text-muted);
  display: block;
  font-size: 11px;
  font-weight: 600;
  margin-top: 2px;
  letter-spacing: -0.01em;
}

.nav-group {
  margin-bottom: 20px;
}

.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-subtle);
  margin: 12px 10px 6px;
}

.nav-link {
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 3px 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
}

.nav-link:hover {
  background: var(--surface-alt);
  color: var(--text-main);
}

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary-hover);
  border-color: var(--primary-border);
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.sidebar-footer b {
  color: var(--text-main);
}

/* Main Area */
.main {
  padding: 28px 32px;
  min-width: 0;
  max-width: 1600px;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.title h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.title p {
  color: var(--text-muted);
  font-size: 13.5px;
}

.user-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ==========================================================================
   Badges, Pills, and Buttons
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.badge.collector {
  background: var(--primary-light);
  color: var(--primary-hover);
  border-color: var(--primary-border);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 2s infinite;
}

.pulse-dot.paused {
  background: var(--warning);
  animation: none;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 9px 16px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
  box-shadow: var(--shadow-flat);
}

.btn:hover {
  background: var(--primary-hover);
}

.btn.secondary {
  background: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-flat);
}

.btn.secondary:hover {
  background: var(--surface-alt);
  border-color: var(--text-muted);
}

.btn.warning {
  background: var(--warning);
  color: #ffffff;
}
.btn.warning:hover {
  background: #d97706;
}

.btn.danger {
  background: var(--danger);
  color: #ffffff;
}
.btn.danger:hover {
  background: #dc2626;
}

.btn.small {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

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

/* ==========================================================================
   Grids & Cards (Modern Flat Design)
   ========================================================================== */

.grid {
  display: grid;
  gap: 16px;
}

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

.grid.cards-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.95fr);
}

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

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 12px;
}

.section-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-flat);
  position: relative;
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-strong);
}

.card h3 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* High-Level Overview Stat Cards */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-flat);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.stat-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.stat-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 16px;
  background: var(--surface-alt);
}

.stat-icon.green { background: var(--success-bg); color: var(--success-text); }
.stat-icon.blue { background: var(--info-bg); color: var(--info-text); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning-text); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple-text); }

.stat-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
}

/* ==========================================================================
   Comprehensive Parameter Cards (Rata-rata Semua Parameter Udara)
   ========================================================================== */

.param-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 1300px) {
  .param-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 768px) {
  .param-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 500px) {
  .param-grid {
    grid-template-columns: 1fr;
  }
}

.param-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-flat);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.param-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
}

.param-card.accent-green::before { background: var(--success); }
.param-card.accent-blue::before { background: var(--info); }
.param-card.accent-amber::before { background: var(--warning); }
.param-card.accent-red::before { background: var(--danger); }
.param-card.accent-purple::before { background: var(--purple); }

.param-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.param-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.param-name {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.param-icon {
  font-size: 16px;
}

.param-main {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 4px 0 8px;
}

.param-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  line-height: 1;
}

.param-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.param-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  border-top: 1px solid var(--surface-alt);
  padding-top: 8px;
  margin-top: 4px;
}

.param-guide {
  color: var(--text-subtle);
  font-weight: 500;
}

/* ==========================================================================
   Status Pills & Indicators
   ========================================================================== */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  background: var(--text-subtle);
}
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.bad { background: var(--danger); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.status-pill.good {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.status-pill.watch {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

.status-pill.poor {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.status-pill.unknown {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ==========================================================================
   Modern Flat Tables
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: var(--transition);
}

tbody tr:hover {
  background: var(--surface-alt);
}

.dev-cell {
  display: flex;
  flex-direction: column;
}

.dev-code {
  font-weight: 700;
  color: var(--text-main);
}

.dev-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.cell-metric {
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

.cell-metric small {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 2px;
}

/* ==========================================================================
   Map & Charts
   ========================================================================== */

#map, #adminMap, #deviceMap {
  height: 420px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

#deviceMap {
  height: 260px;
}

.chart-box {
  height: 330px;
  position: relative;
  padding: 8px 0;
}

/* Leaflet Map Flat Styling */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-modal) !important;
  border: 1px solid var(--border);
  font-family: inherit !important;
}

.leaflet-popup-content {
  margin: 14px 16px !important;
  line-height: 1.5 !important;
  font-size: 13px !important;
}

/* ==========================================================================
   Forms & Inputs (Flat Minimalist)
   ========================================================================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  display: block;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  background: var(--surface);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Modals, Alerts, Notices
   ========================================================================== */

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 18px;
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
  font-size: 13.5px;
  font-weight: 500;
  display: none;
}

.notice.error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.notice.ok {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 9999;
}

.modal {
  width: min(440px, 100%);
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 26px;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border);
}

.modal h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 6px;
}

.helper {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.empty {
  color: var(--text-muted);
  padding: 36px 20px;
  text-align: center;
  font-size: 13.5px;
}

/* Metric boxes used in details */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.metric {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.metric .k {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metric .v {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.metric .unit {
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  margin-left: 2px;
}

/* Campus Breakdown Badge Pill */
.category-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main {
    padding: 20px 16px;
  }
  .grid.cards-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .grid.cards-4 {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .user-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}
