:root {
  --bg: #0f1419;
  --surface: #151c28;
  --card: #1a2332;
  --border: #2a3548;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --link: #a8d4ff;
  --link-hover: #cce8ff;
  --accent: #4d9bff;
  --accent-hover: #6aadff;
  --error: #f87171;
  --nav-bg: #1e2838;
  --nav-active: #2a3a52;
  --header-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 4px 24px rgba(0, 0, 0, 0.25);
  --radius: 10px;
  --radius-sm: 6px;
  --header-brand-width: 800px;
  --header-brand-height: 100px;
  --header-band-bg: #000000;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--link);
  text-decoration: none;
}

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

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* —— Header —— */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0.75rem 1.5rem 1rem;
  background: var(--header-band-bg);
  border-bottom: 1px solid #0a0a0a;
  box-shadow: none;
}

.site-header__wrap {
  width: 100%;
  max-width: none;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--header-band-bg);
}

.site-banner-logo-link {
  display: block;
  line-height: 0;
  width: var(--header-brand-width);
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  background: var(--header-band-bg);
}

.site-banner-logo-link:hover {
  text-decoration: none;
  opacity: 0.96;
}

.site-banner-logo {
  display: block;
  width: var(--header-brand-width);
  max-width: 100%;
  height: auto;
  aspect-ratio: 8 / 1;
  object-fit: contain;
  object-position: center top;
}

.site-header__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.65rem;
  width: 100%;
  max-width: none;
}

.site-header__nav-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-width: 0;
  flex: 1 1 auto;
}

.site-header__page {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: auto;
  padding-left: 0.5rem;
}

@media (max-width: 900px) {
  .site-header__page {
    flex: 1 1 100%;
    margin-left: 0;
    padding-left: 0;
  }
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.site-nav a:hover {
  color: var(--text);
  background: var(--nav-bg);
  text-decoration: none;
}

.site-nav a.active {
  color: var(--text);
  background: var(--nav-active);
  border-color: #3d5270;
}

.site-header__actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.site-header__actions form {
  margin: 0;
}

.btn-link {
  color: var(--link);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.35rem 0.5rem;
}

.btn-link:hover {
  color: var(--link-hover);
}

/* —— Main layout —— */
.page-main {
  padding: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-toolbar h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.page-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.85rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bulk-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.bulk-actions-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.bulk-actions-label select {
  min-width: 9rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

.col-check {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}

.col-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-bar select,
.filter-bar input[type="datetime-local"] {
  min-width: 11rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color-scheme: dark;
}

/* Native calendar glyph — force bright orange on dark inputs */
.filter-bar input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: 1;
  cursor: pointer;
  filter: invert(58%) sepia(88%) saturate(2500%) hue-rotate(1deg) brightness(105%) contrast(104%);
}

.filter-bar select:focus,
.filter-bar input[type="datetime-local"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filter-bar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-bar__hint {
  flex: 1 1 100%;
  margin: 0;
}

.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-layout .card {
  margin: 0;
}

.auth-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 1.25rem;
}

.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.card {
  background: var(--card);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 24rem;
  width: 100%;
}

.card.wide { max-width: 40rem; }

.account-user-list {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
  color: var(--text);
}

.account-user-list li { margin: 0.25rem 0; }

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.card h1 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
}

label { display: block; margin-bottom: 0.75rem; }

input, textarea, select, button {
  font: inherit;
}

input, textarea, select {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  width: auto;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s;
}

button:hover, .btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

button.secondary, .btn.secondary {
  background: var(--nav-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover, .btn.secondary:hover {
  background: var(--nav-active);
}

/* —— Tables —— */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface);
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

tbody tr:hover {
  background: rgba(77, 155, 255, 0.06);
}

tbody tr:last-child td {
  border-bottom: none;
}

table a {
  font-weight: 500;
}

th.col-fleet-actions,
td.col-fleet-actions {
  width: 2.75rem;
  padding-left: 0.25rem;
  padding-right: 0.5rem;
  text-align: right;
  white-space: nowrap;
}

.fleet-display-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  line-height: 0;
}

.fleet-display-icon:hover {
  color: var(--link-hover);
  background: var(--nav-bg);
  text-decoration: none;
}

.fleet-display-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.conn-status {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.5rem;
  border: 1px solid;
  border-radius: var(--radius-sm);
  line-height: 1.25;
  white-space: nowrap;
}

.conn-status--online {
  color: #eab308;
  background: rgba(234, 179, 8, 0.12);
  border-color: rgba(234, 179, 8, 0.5);
}

.conn-status--offline {
  color: #9ca3af;
  background: rgba(55, 65, 81, 0.4);
  border-color: #4b5563;
}

a.conn-status--history {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.55);
  text-decoration: none;
  cursor: pointer;
}

a.conn-status--history:hover {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.28);
  border-color: rgba(59, 130, 246, 0.75);
}

.conn-status--history-disabled {
  color: #71717a;
  background: rgba(63, 63, 70, 0.35);
  border-color: #3f3f46;
  cursor: not-allowed;
  opacity: 0.65;
  user-select: none;
}

/* Smoker mode — colorblind-safe (gray / blue / cyan / violet; no red+green) */
.mode-status {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.5rem;
  border: 1px solid;
  border-radius: var(--radius-sm);
  line-height: 1.25;
  white-space: nowrap;
}

.mode-status--off {
  color: #a1a1aa;
  background: rgba(82, 82, 91, 0.25);
  border-color: #52525b;
}

.mode-status--hold {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.55);
}

.mode-status--smoke_all {
  color: #67e8f9;
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.5);
}

.mode-status--smoke_heat {
  color: #c4b5fd;
  background: rgba(167, 139, 250, 0.15);
  border-color: rgba(167, 139, 250, 0.55);
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.link-row .sep {
  color: var(--muted);
  user-select: none;
}

.error { color: var(--error); }
.hidden { display: none; }

pre {
  background: var(--bg);
  padding: 1rem;
  overflow: auto;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

dl {
  display: grid;
  grid-template-columns: minmax(8rem, 10rem) 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 0.9rem;
}

dd {
  margin: 0;
}

.form-footnote { margin-top: 1.25rem; font-size: 0.85rem; }
.form-success { color: #4ade80; margin: 0 0 1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
code.tiny { font-size: 0.72rem; word-break: break-all; }

code {
  font-size: 0.88em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* —— Debug —— */
.debug-main { max-width: none; }

.debug-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.debug-filter select {
  min-width: 16rem;
  width: auto;
}

.mqtt-status.on { color: #22d3ee; }

#fleet-live-status.on {
  color: #22d3ee;
}
.debug-hint { margin-top: 0; }

.mqtt-log {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  height: min(70vh, 720px);
  overflow: auto;
}

.mqtt-line {
  padding: 0.15rem 0;
  border-bottom: 1px solid #1a2332;
  word-break: break-all;
}

.mqtt-line .ts { color: var(--muted); }
.mqtt-line .topic { color: #93c5fd; }
.mqtt-line .payload { color: var(--text); }

.dir {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  margin-right: 0.25rem;
}

.dir-device { background: #14532d; color: #bbf7d0; }
.dir-app { background: #1e3a5f; color: #bfdbfe; }
.dir-other { background: #374151; color: #e5e7eb; }

/* —— Responsive —— */
@media (max-width: 640px) {
  .site-header {
    padding: 0.75rem 1rem;
  }

  .site-header__toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .site-header__actions {
    justify-content: flex-end;
  }

  .page-main {
    padding: 1rem;
  }

  .auth-layout .card button {
    width: 100%;
  }

  dl {
    grid-template-columns: 1fr;
  }

  dl dt {
    margin-top: 0.5rem;
  }

  dl dt:first-child {
    margin-top: 0;
  }
}
