/* =====================================================================
   Water Quality Monitoring Dashboard — Stylesheet
   Neumorphic / soft-glassmorphic SaaS design system
   ===================================================================== */

:root {
  /* Surfaces */
  --bg: #EEF2F7;
  --surface: #EEF2F7;
  --surface-raised: #F3F6FA;

  /* Text */
  --text-primary: #1E293B;
  --text-secondary: #52607A;
  --text-muted: #8996AC;

  /* Neumorphic shadows */
  --shadow-dark: rgba(163, 177, 198, 0.55);
  --shadow-light: rgba(255, 255, 255, 0.9);

  /* Borders / lines */
  --hairline: rgba(30, 41, 59, 0.08);
  --gridline: rgba(100, 116, 139, 0.10);

  /* Accents */
  --blue: #3B82F6;
  --purple: #7C3AED;
  --light-blue: #60A5FA;
  --teal: #14B8A6;
  --cyan: #06B6D4;

  /* Status */
  --danger: #DC2626;
  --danger-bg: #FEF2F2;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition: 250ms ease;

  --font: 'Lexend', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

/* Elements toggled via the `hidden` attribute must stay hidden even though
   several rules below set their own `display` (same selector specificity,
   so the later rule would otherwise win the cascade). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(160deg, #EEF2F7 0%, #E7ECF4 45%, #ECEFF6 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Elegant scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.7); background-clip: padding-box; }

/* =====================================================================
   Base neumorphic card
   ===================================================================== */
.neu-raised {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  transition: box-shadow var(--transition), transform var(--transition);
}
.neu-inset {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light);
}

.app {
  max-width: 2048px;
  margin: 0 auto;
  padding: 0 28px 48px;
  animation: pageFadeIn 600ms ease both;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   Header
   ===================================================================== */
.dashboard-header {
  padding: 14px 4px 10px;
}
.header-inner { max-width: 1440px; margin: 0 auto; }
.header-title-row {
  display: flex;
  align-items: center;
  gap: 18px;
}
.header-title-row > div {
  min-width: 0; /* let the flex item shrink so its h1/subtitle can wrap instead of overflowing */
}
.header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: #fff;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 6px 6px 14px var(--shadow-dark), -6px -6px 14px var(--shadow-light);
}
.header-icon svg { width: 28px; height: 28px; }
.header-icon img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }

.dashboard-header h1 {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  overflow-wrap: break-word;
}
.header-subtitle {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.subtitle-chip {
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  color: var(--text-secondary);
}
.live-clock {
  font-variant-numeric: tabular-nums;
  background: rgba(20, 184, 166, 0.10);
  color: #0F766E;
  font-weight: 600;
}
.subtitle-sep { color: var(--text-muted); }

/* =====================================================================
   Summary cards
   ===================================================================== */
.summary-grid {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  transition: box-shadow var(--transition), transform var(--transition);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  opacity: 0;
  animation: cardIn 500ms ease forwards;
}
.summary-grid .summary-card:nth-child(1) { animation-delay: 40ms; }
.summary-grid .summary-card:nth-child(2) { animation-delay: 90ms; }
.summary-grid .summary-card:nth-child(3) { animation-delay: 140ms; }
.summary-grid .summary-card:nth-child(4) { animation-delay: 190ms; }
.summary-grid .summary-card:nth-child(5) { animation-delay: 240ms; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.summary-card:hover {
  transform: translateY(-3px);
  box-shadow: 11px 11px 22px var(--shadow-dark), -11px -11px 22px var(--shadow-light);
}
.summary-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(124,58,237,0.15));
  color: var(--blue);
  margin-bottom: 12px;
}
.summary-icon svg { width: 19px; height: 19px; }
.summary-label {
  margin: 0 0 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.summary-value {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-variant-numeric: proportional-nums;
}

/* =====================================================================
   Filter toolbar
   ===================================================================== */
.filter-toolbar {
  position: sticky;
  top: 12px;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin-bottom: 14px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  transition: box-shadow var(--transition);
}
.filter-toolbar.is-disabled { opacity: 0.6; pointer-events: none; }

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-left: 2px;
}
.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.select-wrap select,
.select-wrap input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light);
  padding: 8px 36px 8px 12px;
  min-width: 200px;
  cursor: pointer;
  transition: box-shadow var(--transition);
}
.select-wrap select:focus,
.select-wrap input[type="date"]:focus {
  outline: none;
  box-shadow: inset 3px 3px 8px var(--shadow-dark), inset -3px -3px 8px var(--shadow-light), 0 0 0 3px rgba(59,130,246,0.25);
}
.select-caret {
  position: absolute;
  right: 14px;
  pointer-events: none;
  color: var(--text-muted);
  display: flex;
}
.select-caret svg { width: 16px; height: 16px; }

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 6px 6px 14px rgba(59,130,246,0.25), -2px -2px 8px rgba(255,255,255,0.5);
  transition: transform var(--transition), box-shadow var(--transition);
}
.refresh-btn:hover { transform: translateY(-2px); box-shadow: 8px 8px 18px rgba(59,130,246,0.32); }
.refresh-btn:active { transform: translateY(0); }
.refresh-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.refresh-icon svg { width: 16px; height: 16px; display: block; }
.refresh-btn.is-loading .refresh-icon svg { animation: spin 900ms linear infinite; }

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

/* =====================================================================
   Content grid: 40% table / 60% charts
   ===================================================================== */
.content-grid {
  display: grid;
  grid-template-columns: minmax(500px, 1.15fr) minmax(650px, 1.85fr);
  gap: 10px;
  align-items: start;
  animation: cardIn 450ms ease both;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  padding: 12px;
  transition: box-shadow var(--transition);
  min-width: 0; /* grid items default to min-width:auto — without this the table's
                   unshrinkable content would blow out the track instead of scrolling */
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}
.panel-header svg { width: 18px; height: 18px; color: var(--blue); }
.panel-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.report-left-column { min-width: 0; }
.report-date {
  min-height: 160px;
  display: grid;
  place-items: start center;
  padding-top: 28px;
  color: rgba(30, 41, 59, 0.42);
  font-size: clamp(42px, 4.1vw, 72px);
  font-weight: 700;
  letter-spacing: -0.04em;
  text-align: center;
}

/* =====================================================================
   Data table
   ===================================================================== */
.table-scroll {
  overflow: hidden;
  max-height: none;
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #E9EEF6;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 9px 5px;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
  border-bottom: 1px solid var(--hairline);
}
.data-table thead th:first-child {
  text-align: center;
  width: 13%;
  left: 0;
  z-index: 3;
}
.data-table thead th[data-station="Compostela"] {
  font-size: 9.5px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.data-table tbody td {
  padding: 7px 5px;
  text-align: right;
  color: var(--text-primary);
  white-space: nowrap;
  border-bottom: 1px solid rgba(30,41,59,0.045);
}
.data-table tbody td:first-child {
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  left: 0;
  background: inherit;
  z-index: 1;
}

.data-table tbody tr { background: #F7F9FC; transition: background var(--transition); }
.data-table tbody tr:nth-child(even) { background: #EEF2F8; }
.data-table tbody tr:hover { background: #DEEBFF; }
.data-table tbody tr:hover td:first-child { background: #DEEBFF; }

.data-table tbody td.no-reading { color: var(--text-muted); font-weight: 400; }

.data-table tbody tr {
  opacity: 0;
  animation: rowIn 350ms ease forwards;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* =====================================================================
   Charts
   ===================================================================== */
.charts-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.chart-card {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--hairline);
  padding: 4px 8px 3px;
  transition: background var(--transition);
  opacity: 0;
  animation: cardIn 450ms ease forwards;
}
.chart-card:hover {
  transform: none;
  box-shadow: none;
  background: rgba(255,255,255,0.22);
}
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.chart-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.chart-card-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: rgba(100,116,139,0.08);
  padding: 2px 8px;
  border-radius: 6px;
}
.chart-canvas-wrap { height: 90px; position: relative; }
.chart-empty {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12.5px;
  gap: 8px;
  flex-direction: column;
}
.chart-empty svg { width: 26px; height: 26px; opacity: 0.5; }

/* =====================================================================
   Loading skeleton
   ===================================================================== */
.skeleton-wrap { display: none; }
.skeleton-wrap.active { display: block; animation: cardIn 300ms ease both; }

.skeleton-content {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 24px;
}
.skeleton-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  padding: 20px;
}
.skel-line, .skel-chart {
  border-radius: 10px;
  background: linear-gradient(90deg, #E4E9F1 25%, #EFF3F8 37%, #E4E9F1 63%);
  background-size: 400% 100%;
  animation: shimmer 1.6s ease infinite;
}
.skel-line { height: 34px; margin-bottom: 12px; }
.skel-title { width: 40%; height: 20px; }
.skeleton-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px,1fr)); gap: 18px; }
.skel-chart { height: 260px; }

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

/* =====================================================================
   Error / Empty states
   ===================================================================== */
.state-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 18px var(--shadow-dark), -8px -8px 18px var(--shadow-light);
  padding: 64px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: cardIn 400ms ease both;
}
.state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  margin-bottom: 12px;
}
.state-icon svg { width: 34px; height: 34px; }
.error-icon { background: #FEF2F2; color: var(--danger); }
.empty-icon { background: rgba(59,130,246,0.08); color: var(--blue); }

.state-panel h2 { margin: 0; font-size: 19px; font-weight: 700; color: var(--text-primary); }
.state-panel p { margin: 0 0 12px; font-size: 14px; color: var(--text-secondary); max-width: 360px; }

.retry-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 6px 6px 14px rgba(59,130,246,0.25);
  transition: transform var(--transition);
}
.retry-btn:hover { transform: translateY(-2px); }
.retry-btn svg { width: 16px; height: 16px; }

/* =====================================================================
   Footer
   ===================================================================== */
.dashboard-footer {
  display: none;
}

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

/* Tablet */
@media (max-width: 1100px) {
  .content-grid, .skeleton-content { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .chart-canvas-wrap, .chart-empty { height: 200px; }
  .skel-chart { height: 220px; }
  .table-scroll { max-height: 420px; }
  .report-date { min-height: 140px; }
}

/* Mobile */
@media (max-width: 640px) {
  .app { padding: 0 14px 32px; }
  .dashboard-header { padding: 20px 4px 14px; }
  .dashboard-header h1 { font-size: 20px; }
  .header-icon { width: 46px; height: 46px; border-radius: 14px; }
  .header-icon svg { width: 22px; height: 22px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .summary-card { padding: 14px 16px; }
  .summary-value { font-size: 22px; }
  .filter-toolbar { position: static; flex-direction: column; align-items: stretch; gap: 14px; }
  .select-wrap select, .select-wrap input[type="date"] { width: 100%; min-width: 0; }
  .refresh-btn { justify-content: center; }
  .charts-container { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
}
