* { box-sizing: border-box; }

:root {
  color-scheme: light;
  --page-bg: #f0f2f5;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: #e2e8f0;
  --stat-bg: #f7f9fc;
  --tooltip-bg: #fcfcfb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-bg: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: #383835;
    --stat-bg: #22221f;
    --tooltip-bg: #22221f;
    --series-1: #3987e5;
    --series-2: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: #383835;
  --stat-bg: #22221f;
  --tooltip-bg: #22221f;
  --series-1: #3987e5;
  --series-2: #d95926;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: var(--page-bg);
  margin: 0;
  color: var(--text-primary);
}

header {
  background: #1a252f;
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 1px;
}

header a, header button {
  color: white;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
}

header a:hover, header button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 16px;
}

.card {
  background: var(--surface-1);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.card h2 {
  color: var(--text-primary);
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 320px;
}

.login-card h1 {
  text-align: center;
  font-size: 1.3rem;
  margin-top: 0;
  color: var(--text-primary);
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--text-primary);
}

input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-top: 4px;
  background: var(--surface-1);
  color: var(--text-primary);
}

button, .btn {
  background: #2980b9;
  color: white;
  border: none;
  padding: 10px;
  width: 100%;
  margin-top: 4px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.95rem;
}

button:hover, .btn:hover {
  background: #1f6694;
}

.error {
  color: #c0392b;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.station-list {
  display: grid;
  gap: 14px;
}

.station-card {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.station-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.station-card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.station-card h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.station-card .sub {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge.online {
  background: #d5f4e6;
  color: #1b7a4d;
}

.badge.offline {
  background: #fbe0dd;
  color: #a13b2f;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.telemetry-grid .stat {
  background: var(--stat-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.telemetry-grid .stat .label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.telemetry-grid .stat .value {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 2px;
  color: var(--text-primary);
}

/* ---- Camera ---- */

.camera-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}

.camera-latest {
  flex: 0 0 auto;
}

.latest-photo {
  width: 240px;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.photo-gallery {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.gallery-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ---- History actions ---- */

.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-danger {
  background: #c0392b;
}

.btn-danger:hover {
  background: #922b21;
}

.row-delete-btn {
  width: auto;
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 0.8rem;
  margin: 0;
  cursor: pointer;
}

.row-delete-btn:hover {
  background: #c0392b;
  color: white;
  border-color: #c0392b;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

td {
  color: var(--text-primary);
}

.command-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.command-row .field {
  flex: 0 0 auto;
}

.command-row input[type="number"] {
  width: 100px;
}

.command-row .btn {
  width: auto;
  padding: 10px 18px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  margin-bottom: 0;
  white-space: nowrap;
}

.checkbox-field input {
  width: auto;
  margin-top: 0;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  width: auto;
}

.slider-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.slider-value {
  font-size: 0.85rem;
  color: var(--text-secondary);
  width: 40px;
  text-align: right;
  flex: 0 0 auto;
}

.num-input {
  width: 64px;
  margin-top: 0;
  flex: 0 0 auto;
}

.subsection {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.subsection-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

a.back {
  color: #2980b9;
  text-decoration: none;
  font-size: 0.9rem;
}

/* ---- Charts ---- */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.chart-card {
  position: relative;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.line-chart {
  width: 100%;
  height: 200px;
  display: block;
  overflow: visible;
}

.gridline {
  stroke: var(--gridline);
  stroke-width: 1;
}

.axis-label {
  fill: var(--muted);
  font-size: 10px;
}

.series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.end-marker {
  stroke: var(--surface-1);
  stroke-width: 2;
}

.crosshair {
  stroke: var(--baseline);
  stroke-width: 1;
}

.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 14px;
  height: 2px;
  border-radius: 1px;
  display: inline-block;
}

.chart-tooltip {
  position: absolute;
  top: 8px;
  background: var(--tooltip-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.75rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  min-width: 120px;
  z-index: 2;
}

.tooltip-time {
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-size: 0.7rem;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

.tooltip-key {
  width: 10px;
  height: 2px;
  display: inline-block;
  border-radius: 1px;
}

.tooltip-value {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tooltip-label {
  color: var(--text-secondary);
}
