:root {
  --bg:           #0E1622;
  --sidebar-bg:   #0A111B;
  --panel:        #16212F;
  --panel-raised: #1D2B3D;
  --line:         #28384D;
  --text:         #DDE7F0;
  --text-dim:     #8A9CB0;
  --muted:        #5A6E84;
  --navy:         #2B5BD7;
  --navy-hi:      #3D6FE8;
  --accent:       #5AA2FF;
  --accent-glow:  rgba(90,162,255,0.16);
  --confirmed:    #2BD4C0;
  --online:       #3FD17E;
  --warn:         #F5A623;
  --danger:       #FF5C6C;
  --offline:      #34465A;
  --sidebar-w:    228px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }

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

h1, h2 {
  font-family: "Archivo", system-ui, sans-serif;
  font-weight: 800; margin: 0; letter-spacing: -0.02em;
}
h3 { font-family: "IBM Plex Sans", system-ui, sans-serif; font-weight: 600; margin: 0; }

code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  background: var(--panel-raised);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

/* ---- Signal trace — the live-telemetry signature ---- */
/* A scrolling oscilloscope wave keyed purely on status classes.
   Offline = flat dashed baseline; online/warn/danger = a coloured
   heartbeat that sweeps right→left like a monitor. */
@keyframes sig-scroll-28 { to { background-position: -28px center; } }
@keyframes sig-scroll-40 { to { background-position: -40px center; } }
@keyframes dot-breathe   { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.signal-trace {
  display: inline-block;
  width: 58px; height: 18px; vertical-align: middle; flex: none;
  background-repeat: no-repeat;
  background-image: repeating-linear-gradient(90deg, var(--offline) 0 4px, transparent 4px 9px);
  background-size: 100% 2px;
  background-position: 0 center;
  opacity: 0.7;
}
.rstatus-online .signal-trace,
.rstatus-warn   .signal-trace,
.rstatus-danger .signal-trace {
  background-repeat: repeat-x;
  background-size: 28px 18px;
  opacity: 1;
}
.rstatus-online .signal-trace {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='28'%20height='18'%3E%3Cpath%20d='M0%209%20H7%20l1.5%20-5%20l2%2010%20l1.5%20-5%20H28'%20fill='none'%20stroke='%235AA2FF'%20stroke-width='1.4'/%3E%3C/svg%3E");
}
.rstatus-warn .signal-trace {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='28'%20height='18'%3E%3Cpath%20d='M0%209%20H7%20l1.5%20-5%20l2%2010%20l1.5%20-5%20H28'%20fill='none'%20stroke='%23F5A623'%20stroke-width='1.4'/%3E%3C/svg%3E");
}
.rstatus-danger .signal-trace {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='28'%20height='18'%3E%3Cpath%20d='M0%209%20H7%20l1.5%20-5%20l2%2010%20l1.5%20-5%20H28'%20fill='none'%20stroke='%23FF5C6C'%20stroke-width='1.4'/%3E%3C/svg%3E");
}
@media (prefers-reduced-motion: no-preference) {
  .rstatus-online .signal-trace,
  .rstatus-warn   .signal-trace,
  .rstatus-danger .signal-trace { animation: sig-scroll-28 1.3s linear infinite; }
}

/* Wide ambient sweep — used on the login identity panel */
.signal-line {
  width: 100%; height: 24px;
  background-repeat: repeat-x;
  background-position: 0 center;
  background-size: 40px 24px;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='40'%20height='24'%3E%3Cpath%20d='M0%2012%20H11%20l2%20-7%20l3%2014%20l2%20-7%20H40'%20fill='none'%20stroke='%235AA2FF'%20stroke-width='1.5'/%3E%3C/svg%3E");
  opacity: 0.85;
}
@media (prefers-reduced-motion: no-preference) {
  .signal-line { animation: sig-scroll-40 1.7s linear infinite; }
}

/* ---- Layout shell ---- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 0 18px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}

/* Brand */
.sidebar .brand { padding: 0 16px 18px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.sidebar .brand-logo { width: 132px; height: auto; display: block; }
.sidebar .brand .sub {
  display: block; font-size: 10px; font-weight: 500; color: var(--muted);
  margin-top: 8px; letter-spacing: 0.18em; text-transform: uppercase;
  font-family: "IBM Plex Mono", monospace;
}

/* Nav */
.sidebar nav { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }
.sidebar nav a {
  color: var(--text-dim); text-decoration: none; font-size: 13px; font-weight: 500;
  padding: 8px 12px; border-radius: 5px; display: block;
  border-left: 2px solid transparent;
  transition: color 0.1s, background 0.1s;
}
.sidebar nav a:hover { color: var(--text); background: rgba(255,255,255,0.04); text-decoration: none; }
.sidebar nav a.active {
  color: var(--text); background: var(--panel-raised);
  border-left: 2px solid var(--navy); padding-left: 10px;
}

/* Sidebar section headings */
.sidebar-section {
  display: block;
  font-size: 10px; font-weight: 500; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  padding: 0 16px; margin: 20px 0 6px;
}

/* Fleet status stats */
.sidebar-stat {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 16px; font-size: 12px; color: var(--text-dim);
}
.sidebar-stat .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.sidebar-stat.online-stat { color: var(--online); }
.sidebar-stat.online-stat .dot { background: var(--online); }
.sidebar-stat.offline-stat { color: var(--muted); }
.sidebar-stat.offline-stat .dot { background: var(--offline); }

/* Company nav */
.company-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }
.company-nav a {
  display: block; padding: 4px 16px; font-size: 12px;
  color: var(--text-dim); text-decoration: none; border-radius: 4px;
  transition: color 0.1s, background 0.1s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.company-nav a:hover { color: var(--text); background: rgba(255,255,255,0.04); text-decoration: none; }

/* Logout */
.sidebar .logout {
  color: var(--muted); font-size: 12px; font-weight: 500;
  padding: 8px 12px; margin: 0 8px; border-radius: 5px;
  background: none; border: none; cursor: pointer;
  display: block; text-align: left; width: calc(100% - 16px);
  transition: color 0.1s, background 0.1s;
  margin-top: auto;
}
.sidebar .logout:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.main .pagehead { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.main .pagehead h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; flex: 1; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .sidebar .brand { padding: 0 14px 0 0; border-right: 1px solid var(--line); border-bottom: none; margin-bottom: 0; }
  .sidebar nav { flex-direction: row; }
  .sidebar-section, .sidebar-stat, .company-nav { display: none; }
  .sidebar .logout { margin-left: auto; margin-top: 0; }
  .main { padding: 20px 16px 50px; }
}

/* ---- Shared components ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.panel-pad { padding: 22px 24px; }
.panel h3.label {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 14px; font-weight: 500; font-family: "IBM Plex Mono", monospace;
}

input, select, textarea {
  width: 100%; padding: 9px 12px;
  background: var(--panel-raised); border: 1px solid var(--line);
  border-radius: 6px; color: var(--text);
  font-family: "IBM Plex Sans", system-ui, sans-serif; font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

button, .btn {
  font-family: "IBM Plex Sans", system-ui, sans-serif; font-weight: 500; font-size: 13px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-raised); color: var(--text); cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
button:hover, .btn:hover { background: rgba(255,255,255,0.05); border-color: var(--muted); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button.primary, .btn.primary {
  background: var(--navy); border-color: var(--navy);
  color: #fff; font-weight: 600;
}
button.primary:hover, .btn.primary:hover { background: var(--navy-hi); border-color: var(--navy-hi); }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
button.danger:hover { background: var(--danger); color: #fff; }

/* Status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; color: var(--muted); font-family: "IBM Plex Mono", monospace; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--offline); flex: none; }
.pill.online { color: var(--online); }
.pill.online .dot { background: var(--online); box-shadow: 0 0 6px 1px rgba(63,209,126,0.5); }
.pill.offline { color: var(--muted); }
.pill.offline .dot { background: var(--offline); }
.pill.warn { color: var(--warn); }
.pill.warn .dot { background: var(--warn); box-shadow: 0 0 5px 1px rgba(245,166,35,0.5); }
.pill.danger { color: var(--danger); }
.pill.danger .dot { background: var(--danger); box-shadow: 0 0 5px 1px rgba(255,92,108,0.5); }
.pill.inactive { color: var(--accent); }
.pill.inactive .dot { background: var(--accent); opacity: 0.45; }

@media (prefers-reduced-motion: no-preference) {
  .pill.online .dot { animation: dot-breathe 2.2s ease-in-out infinite; }
}

/* Top loading bar */
#page-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent); z-index: 9999; pointer-events: none;
  transform: scaleX(0); transform-origin: left center;
  box-shadow: 0 0 8px 0 var(--accent);
}
#page-bar.running { transform: scaleX(0.85); transition: transform 2.5s cubic-bezier(0.08, 0.4, 0.3, 1); }
#page-bar.done { transform: scaleX(1); opacity: 0; transition: transform 0.12s ease, opacity 0.4s ease 0.08s; }

/* Spinner */
@keyframes _spin { to { transform: rotate(360deg); } }
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: _spin 0.7s linear infinite;
  flex-shrink: 0;
}
.loading-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 40px 20px; color: var(--muted); font-size: 13px;
}

/* Table */
table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); font-weight: 500;
  font-family: "IBM Plex Mono", monospace;
  padding: 10px 14px; background: var(--panel-raised); border-bottom: 1px solid var(--line);
}
table.list th:first-child { border-radius: 6px 0 0 0; }
table.list th:last-child  { border-radius: 0 6px 0 0; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13px; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr:hover { background: var(--panel-raised); }
table.list .device-name { font-weight: 600; }
table.list .device-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
