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

:root {
  --sidebar-w: 280px;
  --accent: #0078d7;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #ddd;
  --text: #222;
  --text-secondary: #666;
  --danger: #c00;
}

html, body { height: 100%; font-family: system-ui, sans-serif; color: var(--text); background: var(--bg); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.modal {
  background: var(--surface);
  border-radius: 8px;
  padding: 2rem;
  width: min(380px, 90vw);
  display: flex; flex-direction: column; gap: .75rem;
}
.modal h2 { font-size: 1.2rem; }
.modal p  { color: var(--text-secondary); font-size: .9rem; }
.modal input {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  width: 100%;
}
.modal button {
  padding: .55rem;
  background: var(--accent);
  color: #fff;
  border: none; border-radius: 4px;
  font-size: 1rem; cursor: pointer;
}
.modal button:hover { filter: brightness(1.1); }
.error { color: var(--danger); font-size: .85rem; }

/* ── Hidden utility class ── */
.auth-form.hidden { 
  display: none !important;
}

/* ── Authentication Forms ── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ── Subscribe Option ── */
.subscribe-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.subscribe-option span {
  color: var(--text-secondary);
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  font-family: inherit;
}

.link-button:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ── Authentication Forms ── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ── App layout ── */
.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, flex 0.3s ease, transform 0.3s ease;
}
#sidebar.sidebar-hidden {
  width: 0;
  min-width: 0;
  flex: 0 0 0;
  transform: translateX(-100%);
  border-right: none;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
}
.sidebar-title { font-weight: 600; font-size: 1rem; }
#btn-toggle-sidebar {
  background: transparent; border: none; color: #fff;
  font-size: 1rem; cursor: pointer; line-height: 1;
}
#btn-toggle-sidebar:hover { filter: brightness(1.1); }
#btn-logout {
  background: var(--danger); border: none; color: #fff;
  padding: 0.55rem 1rem; border-radius: 4px;
  font-size: 0.9rem; cursor: pointer; line-height: 1;
  font-weight: 500;
  transition: background-color 0.2s ease;
}
#btn-logout:hover { background: rgb(130, 1, 1); }
#device-list-wrap {
  padding: .5rem 0;
}

/* ── Sidebar tabs ── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: .5rem .25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

/* ── Stats ── */
.stats-content { padding: .75rem 1rem; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: .3rem 0;
  font-size: .875rem;
}
.stat-row span { color: var(--text-secondary); }
.stat-divider { border-top: 1px solid var(--border); margin: .5rem 0; }

/* ── Display options ── */
.display-options { padding: .75rem 1rem; }
.display-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  margin-bottom: .5rem;
}
.radio-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem 0;
  font-size: .875rem;
  cursor: pointer;
}

/* ── Color Scale ── */
.color-scale {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-scale.hidden {
  display: none;
}



.color-scale-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-scale-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 60vh;
  width: 20px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  padding-right: 5px;
}

.color-scale-gradient {
  width: 8px;
  height: 60vh;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: linear-gradient(to bottom, 
    rgb(0,0,255), 
    rgb(0,255,255), 
    rgb(0,255,0), 
    rgb(255,255,0), 
    rgb(255,0,0)
  );
}

.color-scale-unit {
  position: absolute;
  bottom: -25px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 2px;
}

.hint { padding: .75rem 1rem; color: var(--text-secondary); font-size: .875rem; }

/* Device group */
.device-group { margin-bottom: .25rem; }
.device-toggle {
  width: 100%; text-align: left;
  padding: .55rem 1rem;
  background: none; border: none; cursor: pointer;
  font-size: .8rem; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .04em;
  display: flex; align-items: center; gap: .4rem;
}
.device-toggle:hover { background: var(--bg); }
.device-toggle .arrow { transition: transform .2s; display: inline-block; }
.device-toggle.open .arrow { transform: rotate(90deg); }

.session-list { list-style: none; }
.session-list li button {
  width: 100%; text-align: left;
  padding: .45rem 1rem .45rem 1.75rem;
  background: none; border: none; cursor: pointer;
  font-size: .875rem; color: var(--text);
}
.session-list li button:hover  { background: var(--bg); }
.session-list li button.active { background: #e3f0fb; color: var(--accent); font-weight: 600; }

/* ── Map ── */
#map-wrap { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }
#btn-show-sidebar {
  position: absolute; top: 5.5rem; left: 1rem; z-index: 1001;
  background: rgba(255,255,255,.95); border: 1px solid var(--border);
  border-radius: 4px; padding: .5rem .75rem;
  font-size: .875rem; cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
}
#btn-show-sidebar:hover { background: #fff; }

#track-tooltip {
  background: rgba(200, 200, 200, 0.95);
  border: 1px solid #999;
  border-radius: 4px;
  padding: 0.75rem;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  pointer-events: none;
  max-width: 200px;
  z-index: 1002;
}

.track-pin {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid #999;
  border-left: 3px solid #0078d7;
  border-radius: 4px;
  padding: 0.75rem;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  pointer-events: none;
  max-width: 200px;
  z-index: 1002;
}

.map-info {
  position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem 1rem;
  font-size: .875rem;
  pointer-events: none;
  white-space: nowrap;
  z-index:1003;
}
.map-info.hidden { display: none; }
