/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3e;
  --text:     #e0e0e8;
  --muted:    #6b7280;
  --accent:   #3b82f6;
  --green:    #22c55e;
  --red:      #ef4444;
  --orange:   #f59e0b;
  --purple:   #a855f7;
  --radius:   8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

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

/* ── Topnav ───────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { font-size: 18px; font-weight: 700; color: var(--accent); }
.nav-brand a { color: var(--accent); }
.nav-links { display: flex; gap: 20px; align-items: center; }

/* ── Page layout ──────────────────────────────────────────────────────────── */
.page-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h2 { font-size: 22px; font-weight: 600; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 380px;
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 32px; color: var(--accent); }
.login-logo p { color: var(--muted); margin-top: 4px; }

/* ── Form elements ────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field select:focus { border-color: var(--accent); }

.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 180px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-success   { background: var(--green);  color: #fff; }
.btn-danger    { background: var(--red);    color: #fff; }
.btn-warning   { background: var(--orange); color: #000; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-full      { width: 100%; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.card-header h3 { margin-bottom: 0; }

/* ── Installation grid ────────────────────────────────────────────────────── */
.inst-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.inst-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  text-decoration: none;
  color: var(--text);
  display: block;
}
.inst-card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }

.inst-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.inst-card h4 { font-size: 16px; font-weight: 600; }
.inst-card .slug { color: var(--muted); font-size: 12px; margin-top: 2px; }
.inst-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.inst-metric { background: var(--bg); border-radius: 4px; padding: 8px; }
.inst-metric .label { font-size: 11px; color: var(--muted); }
.inst-metric .val { font-size: 18px; font-weight: 600; }
.inst-footer { margin-top: 12px; font-size: 11px; color: var(--muted); }

/* ── Stat row (installation detail) ──────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-card .stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .stat-val { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ── Command grid ─────────────────────────────────────────────────────────── */
.cmd-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.cmd-result { margin-top: 10px; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.cmd-result.ok { background: #14532d; color: #86efac; }
.cmd-result.err { background: #7f1d1d; color: #fca5a5; }

/* ── Data table ───────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 6px 10px; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge-green  { background: #14532d; color: var(--green); }
.badge-red    { background: #7f1d1d; color: var(--red); }
.badge-blue   { background: #1e3a5f; color: var(--accent); }
.badge-muted  { background: var(--border); color: var(--muted); }

.poll-badge { background: #14532d; color: var(--green); padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.poll-badge.stale { background: #44330a; color: var(--orange); }

/* ── Alarms ───────────────────────────────────────────────────────────────── */
.alarm-list { display: flex; flex-direction: column; gap: 6px; }
.alarm-item { background: #7f1d1d22; border: 1px solid #ef444430; border-radius: 6px; padding: 8px 12px; color: var(--red); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 520px;
  max-width: 95vw;
}
.modal h3 { margin-bottom: 16px; }

/* ── Access list ──────────────────────────────────────────────────────────── */
.access-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.access-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--bg); border-radius: 4px; }

/* ── Token box ────────────────────────────────────────────────────────────── */
.token-box {
  margin-top: 12px;
  padding: 12px;
  background: #0f2a1c;
  border: 1px solid #22c55e44;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
}

/* ── Settings grid ────────────────────────────────────────────────────────── */
.settings-grid { display: flex; flex-direction: column; gap: 20px; }
.setting-group { border-top: 1px solid var(--border); padding-top: 14px; }
.setting-group h4 { font-size: 13px; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .04em; }

/* ── Pad toggle ───────────────────────────────────────────────────────────── */
.pad-toggle { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.pad-toggle label { font-size: 12px; color: var(--muted); }
.toggle-switch { position: relative; width: 40px; height: 22px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 22px; transition: .2s;
}
.toggle-slider::before {
  position: absolute; content: "";
  width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Live indicator ───────────────────────────────────────────────────────── */
.live-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--muted);
  transition: background .3s;
}
@keyframes live-flash {
  0%   { background: var(--green); box-shadow: 0 0 6px var(--green); }
  100% { background: var(--muted); box-shadow: none; }
}
.live-dot.live-pulse { animation: live-flash 1.2s ease-out forwards; }

/* ── Live indicator ───────────────────────────────────────────────────────── */
.live-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--muted);
  transition: background .3s;
}
@keyframes live-flash {
  0%   { background: var(--green); box-shadow: 0 0 6px var(--green); }
  100% { background: var(--muted); box-shadow: none; }
}
.live-dot.live-pulse { animation: live-flash 1.2s ease-out forwards; }

/* ── Section navigation ───────────────────────────────────────────────────── */
.section-nav {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.section-nav a {
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s, background .15s;
}
.section-nav a:hover { color: var(--text); background: var(--border); text-decoration: none; }

/* Stat cards nested inside a card look better on --bg */
.card .stat-row { margin-bottom: 0; }
.card .stat-card { background: var(--bg); }

/* ── Pad status grid ──────────────────────────────────────────────────────── */
.pad-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
}
.pad-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color .2s;
}
.pad-card.pad-running { border-color: var(--green); }
.pad-card.pad-fault   { border-color: var(--red); }
.pad-card.pad-disabled { opacity: .45; }
.pad-card-label { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.pad-card-status { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.pad-indicator {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.pad-indicator.green  { background: var(--green); }
.pad-indicator.red    { background: var(--red); }
.pad-indicator.orange { background: var(--orange); }
.pad-indicator.gray   { background: var(--muted); }
.pad-step { font-size: 11px; color: var(--muted); margin-top: 5px; }
.pad-faults { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }

/* ── Device log panel ─────────────────────────────────────────────────────── */
.log-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  height: 300px;
  overflow-y: auto;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
}
.log-line { display: block; white-space: pre-wrap; word-break: break-all; }
.log-line.log-info  { color: #9ca3af; }
.log-line.log-warn  { color: var(--orange); }
.log-line.log-fault { color: var(--red); }
.log-empty { color: var(--muted); font-style: italic; font-family: inherit; }

/* ── I/O Diagnostics ──────────────────────────────────────────────────────── */
.diag-sys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.diag-cell {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}
.diag-cell-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.diag-cell-val { font-size: 16px; font-weight: 600; }
.diag-cell-raw { font-size: 11px; color: var(--muted); margin-top: 2px; }

.diag-pad-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.diag-pad-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}
.diag-pad-card.is-detected  { border-color: var(--accent); }
.diag-pad-card.is-running   { border-color: var(--green); }
.diag-pad-card.is-fault     { border-color: var(--red); }
.diag-pad-card.not-detected { opacity: .55; }
.diag-pad-card.pad-disabled { opacity: .4; }
.diag-pad-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 13px;
}
.diag-pad-rows { display: flex; flex-direction: column; gap: 4px; }
.diag-pad-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.diag-pad-row span:last-child { color: var(--text); font-weight: 500; }

/* ── Pad card footer (enable toggle) ─────────────────────────────────────── */
.diag-pad-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.diag-pad-footer-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Hardware address tags ────────────────────────────────────────────────── */
.hw-tag {
  display: inline-block;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 10px;
  color: var(--muted);
  background: var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  cursor: default;
}

/* ── Tooltip icon on control buttons ─────────────────────────────────────── */
.btn-tip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-tip-wrap .tip {
  color: var(--muted);
  font-size: 14px;
  cursor: help;
  user-select: none;
  line-height: 1;
}
.btn-tip-wrap .tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e2030;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 6px;
  width: 270px;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 50;
}
.btn-tip-wrap .tip:hover::after { opacity: 1; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.loading-spinner { color: var(--muted); text-align: center; padding: 40px; }
.header-badges { display: flex; gap: 8px; align-items: center; }
