html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Tait brand colors, taken from taitcommunications.com */
:root {
  --tait-cyan: #00b5e6;
  --tait-navy: #1a2738;
  --banner-height: 60px;
}

.app-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--banner-height);
  background: var(--tait-navy);
  border-bottom: 3px solid var(--tait-cyan);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  box-sizing: border-box;
  z-index: 1100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.banner-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.banner-logo img {
  height: 30px;
  width: auto;
  display: block;
}

/* Shown only if the remote logo fails to load (see onerror in index.html). */
.logo-fallback {
  display: none;
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
}

.banner-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.3);
}

.banner-title {
  margin: 0;
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* Map sits below the fixed banner. */
#map {
  position: absolute;
  top: var(--banner-height);
  left: 0;
  right: 0;
  bottom: 0;
}

.legend {
  background: rgba(255, 255, 255, 0.92);
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  line-height: 1.5;
  font-size: 13px;
}

.legend i {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  opacity: 0.6;
  border-radius: 50%;
  vertical-align: -2px;
}

.layer-control {
  position: absolute;
  top: calc(var(--banner-height) + 10px);
  right: 10px;
  z-index: 1000;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
  min-width: 185px;
  overflow: hidden;
}

.layer-control-header {
  background: var(--tait-navy);
  border-bottom: 2px solid var(--tait-cyan);
  color: #fff;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.layer-control-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.layer-control-toggle {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
  display: inline-block;
  transition: transform 0.22s ease;
  line-height: 1;
}

.layer-control.collapsed .layer-control-toggle {
  transform: rotate(-90deg);
}

.layer-control-body {
  padding: 10px 12px 12px;
  overflow: hidden;
  max-height: 500px;
  opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.22s ease;
}

.layer-control.collapsed .layer-control-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.layer-section {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.layer-section:last-of-type {
  margin-bottom: 10px;
}

.layer-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #999;
  margin-bottom: 6px;
}

.layer-control label {
  display: block;
  cursor: pointer;
  padding: 2px 0;
  font-size: 14px;
}

.layer-control label:hover {
  color: var(--tait-navy);
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-filter label {
  display: inline;
  font-weight: 600;
}

.date-filter input[type='date'] {
  font: inherit;
  padding: 2px 4px;
}

.date-filter button {
  font: inherit;
  cursor: pointer;
  padding: 2px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #f5f5f5;
}

.date-filter button:hover {
  background: #e9e9e9;
}

.day-status {
  margin-top: 6px;
  font-size: 12px;
  color: #555;
}

.hidden-note {
  margin-top: 3px;
  font-size: 11px;
  color: #a06000;
}

/* ---- Settings button (in layer control) -------------------------------- */

.settings-btn {
  display: block;
  width: 100%;
  padding: 5px 0;
  background: #f0f4f8;
  color: var(--tait-navy);
  border: 1px solid #c8d0da;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}

.settings-btn:hover {
  background: #dce6f0;
}

/* ---- Threshold modal --------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

/* Keep display:none when [hidden] is set */
.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  width: 100%;
  max-width: 500px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
}

.modal-header {
  background: var(--tait-navy);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.12s;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 22px 24px 8px;
  overflow-y: auto;
  flex: 1;
}

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

.threshold-group h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--tait-navy);
}

.threshold-unit {
  font-weight: 400;
  color: #777;
  font-size: 12px;
}

.threshold-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.threshold-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.threshold-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.threshold-field label {
  font-size: 13px;
  font-weight: 500;
  color: #444;
}

.threshold-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.threshold-input-row input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid #d0d5dd;
  border-radius: 5px;
  font: inherit;
  font-size: 14px;
  box-sizing: border-box;
}

.threshold-input-row input:focus {
  outline: none;
  border-color: var(--tait-cyan);
  box-shadow: 0 0 0 3px rgba(0, 181, 230, 0.18);
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.modal-error {
  flex: 1;
  margin: 0;
}

/* ---- Banner user area -------------------------------------------------- */

.banner-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.banner-username {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
}

.role-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
}

.role-admin {
  background: var(--tait-cyan);
  color: var(--tait-navy);
}

.role-user {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.logout-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 4px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.admin-link {
  color: var(--tait-cyan);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid var(--tait-cyan);
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.admin-link:hover {
  background: var(--tait-cyan);
  color: var(--tait-navy);
}

/* ---- Login page -------------------------------------------------------- */

.login-body {
  background: #f0f2f5;
}

.login-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 380px;
  overflow: hidden;
}

.login-card-brand {
  background: var(--tait-navy);
  border-bottom: 3px solid var(--tait-cyan);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
}

.login-card-brand .banner-logo {
  flex-shrink: 0;
}

.login-card-brand .banner-logo img {
  height: 26px;
  width: auto;
  max-width: 100px;
}

.login-card-brand .banner-divider {
  flex-shrink: 0;
}

.login-card-brand-title {
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.login-card-body {
  padding: 28px 32px 32px;
}

.login-heading {
  margin: 0 0 24px;
  font-size: 20px;
  color: var(--tait-navy);
  font-weight: 600;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--tait-cyan);
  box-shadow: 0 0 0 3px rgba(0, 181, 230, 0.18);
}

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--tait-navy);
  color: #fff;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: #243550;
}

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

.login-error {
  background: #fff0f0;
  border: 1px solid #fcc;
  color: #c00;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* ---- Admin page -------------------------------------------------------- */

.admin-body {
  background: #f5f7f9;
}

.admin-content {
  position: fixed;
  top: var(--banner-height);
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 28px;
  box-sizing: border-box;
}

.admin-section {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.09);
  padding: 28px;
  margin-bottom: 24px;
  max-width: 860px;
}

.admin-section h2 {
  margin: 0 0 20px;
  font-size: 18px;
  color: var(--tait-navy);
  font-weight: 600;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 16px;
  align-items: end;
}

.admin-form .form-group {
  margin-bottom: 0;
}

.admin-success {
  background: #f0fff4;
  border: 1px solid #99e6b3;
  color: #1a7a3a;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 16px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.user-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #e5e7eb;
  color: #555;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.user-table td {
  padding: 12px 12px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

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

.user-table tr:hover td {
  background: #fafbfc;
}

.action-cell {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  background: #f5f7fa;
  color: var(--tait-navy);
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-secondary:hover {
  background: #e8ecf2;
}

.btn-danger {
  background: #fff0f0;
  color: #c00;
  border: 1px solid #fcc;
  border-radius: 4px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-danger:hover {
  background: #ffe0e0;
}

.self-badge {
  font-size: 11px;
  color: #888;
  font-weight: normal;
}

/* ---- Anomaly layer ----------------------------------------------------- */

.anomaly-label {
  color: #b84800;
  font-weight: 500;
}

.threshold-group-anomaly {
  background: #fff8f0;
  border: 1px solid #fcd5a8;
  border-radius: 6px;
  padding: 14px;
  margin-top: 6px;
}

.threshold-group-anomaly h3 {
  color: #8b3d00;
}

.threshold-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: #666;
  line-height: 1.45;
}

/* ---- Filter section --------------------------------------------------- */

.filter-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-clear-btn {
  display: none;
  background: none;
  border: 1px solid #c05000;
  color: #c05000;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  cursor: pointer;
  line-height: 1.6;
}
.filter-clear-btn:hover {
  background: #c05000;
  color: #fff;
}

.filter-group {
  margin-top: 6px;
}

.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: #99b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  user-select: none;
}
.filter-group-header:hover {
  background: rgba(0, 181, 230, 0.1);
}

.filter-group-chevron {
  font-size: 10px;
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.filter-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease;
}
.filter-group-body.open {
  max-height: 180px;
  overflow-y: auto;
}

.filter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 2px 4px;
}

.filter-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #dde;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  user-select: none;
}
.filter-chip:hover {
  background: rgba(0, 181, 230, 0.1);
}
.filter-chip input[type="checkbox"] {
  accent-color: var(--tait-cyan);
  cursor: pointer;
}
