:root {
  --bg: #0f1419;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2a3341;
  --border-2: #3a4452;
  --text: #e6edf3;
  --muted: #8b96a7;
  --accent: #008b8b;
  --accent-2: #00b3b3;
  --accent-3: #00d9d9;
  --danger: #e06c6c;
  --good: #4ec9b0;
  --warn: #e8a04c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms;
  font-family: inherit;
}
button:hover { background: var(--accent-2); }
button.link {
  background: transparent;
  color: var(--accent-2);
  padding: 0;
  font-size: 13px;
}
button.link:hover { background: transparent; text-decoration: underline; }
.inline { display: inline; }

.error {
  background: rgba(224, 108, 108, 0.12);
  color: var(--danger);
  border: 1px solid rgba(224, 108, 108, 0.35);
  padding: 10px 14px;
  border-radius: 6px;
  margin: 12px 0;
}

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; color: var(--accent-2); }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--accent-2); }

/* ---- Topbar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; color: var(--accent-2); }
.topbar .brand a { color: inherit; }
.topbar nav { display: flex; gap: 16px; align-items: center; }

/* ---- Container ---- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.container h1 { margin: 0 0 6px; }

/* ---- Dashboard ---- */
.inst-grid {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.inst-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  color: var(--text);
  transition: border-color 120ms, transform 120ms;
}
.inst-card:hover {
  border-color: var(--accent-2);
  transform: translateY(-1px);
  text-decoration: none;
}
.inst-card h2 { margin: 0 0 6px; font-size: 17px; color: var(--accent-2); }
.inst-card p  { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.inst-card .open { font-size: 13px; color: var(--muted); }

/* ---- Instrument detail ---- */
.back { font-size: 13px; }

.timestamp-bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  margin: 18px 0 22px;
}
.timestamp-bar .label { color: var(--muted); margin-right: 6px; font-size: 13px; }
.timestamp-bar #age { margin-left: 10px; font-size: 13px; }
.timestamp-bar .actions { display: flex; align-items: center; gap: 16px; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px;
  cursor: pointer; user-select: none;
}
.check input { accent-color: var(--accent-2); }

.fresh { color: var(--good); }
.stale { color: var(--danger); }

/* ---- Tile grid ---- */
.tiles-root { display: flex; flex-direction: column; gap: 22px; }

.tile-heading {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: left;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 120ms, transform 120ms, background 120ms;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 92px;
  width: 100%;
}
.tile.clickable:hover {
  border-color: var(--accent-2);
  background: var(--panel-2);
  transform: translateY(-1px);
}
.tile.non-clickable {
  cursor: default;
  opacity: 0.85;
}
.tile.non-clickable:hover { border-color: var(--border); background: var(--panel); transform: none; }

.tile-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tile-value {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  word-break: break-word;
}
.tile-value .unit {
  font-size: 13px;
  color: var(--muted);
  margin-left: 4px;
  font-weight: 400;
}
.tile-open {
  margin-top: auto;
  font-size: 11.5px;
  color: var(--accent-2);
  opacity: 0.75;
}
.tile-open.text-only { color: var(--muted); }

/* ---- Plot modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
body.modal-open { overflow: hidden; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  width: 100%;
  max-width: 1000px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: modal-in 160ms ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--accent-2);
  font-weight: 600;
}
.modal-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-2);
  background: var(--panel-2);
}

.modal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.range-tabs {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.range-tabs button {
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  font-size: 12.5px;
  border-radius: 6px;
}
.range-tabs button:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.range-tabs button.active { background: var(--accent); color: white; }

.modal-plot {
  padding: 12px 20px 20px;
  width: 100%;
  min-height: 420px;
  flex: 1;
}
.modal-plot > div { width: 100%; }

#source { margin-top: 20px; }
