:root {
  color-scheme: light;
  --font-main: Rubik, Aptos, Calibri, "Segoe UI", system-ui, sans-serif;
  --font-display: Saira, Aptos, Calibri, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  --multi-blue: #3553e4;
  --multi-blue-strong: #2843c2;
  --multi-accent: #ffd500;
  --multi-black: #1c1f27;
  --status-online: #20b15a;
  --status-warning: #eab308;
  --severity-critical: #dc2626;
  --severity-info: #2563eb;

  --bg: #f5f6fd;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-muted: #eef1fb;
  --surface-raised: #ffffff;
  --text: #1c1f27;
  --text-strong: #111827;
  --muted: #69707f;
  --muted-strong: #4b5563;
  --border: #dfe4f2;
  --border-strong: #c7d0e5;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --sidebar-bg: var(--multi-blue);
  --sidebar-text: #ffffff;
  --sidebar-muted: rgba(255, 255, 255, 0.8);
  --sidebar-muted-soft: rgba(255, 255, 255, 0.4);
  --sidebar-accent: #2843c2;
  --sidebar-item-hover: rgba(40, 67, 194, 0.5);
  --sidebar-border: #2843c2;
  --shadow: 0 18px 55px rgba(37, 54, 114, 0.16);
  --shadow-soft: 0 10px 28px rgba(37, 54, 114, 0.11);
  --ring: rgba(53, 83, 228, 0.24);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080b12;
  --surface: #11141e;
  --surface-strong: #10131c;
  --surface-muted: #171b27;
  --surface-raised: #121722;
  --text: #eef2ff;
  --text-strong: #ffffff;
  --muted: #9aa4b7;
  --muted-strong: #c3cad8;
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(148, 163, 184, 0.32);
  --input-bg: #0d111b;
  --input-border: rgba(148, 163, 184, 0.28);
  --sidebar-bg: #10131c;
  --sidebar-text: #ffffff;
  --sidebar-muted: rgba(238, 242, 255, 0.72);
  --sidebar-muted-soft: rgba(255, 255, 255, 0.4);
  --sidebar-accent: #3553e4;
  --sidebar-item-hover: rgba(53, 83, 228, 0.3);
  --sidebar-border: rgba(148, 163, 184, 0.18);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 14px 38px rgba(0, 0, 0, 0.28);
  --ring: rgba(53, 83, 228, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  padding: 0;
}

body {
  color: var(--text);
  font: 14px/1.45 var(--font-main);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  clip: rect(0 0 0 0);
  border: 0;
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.app-header {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  padding: 0;
}

.eyebrow,
.section-kicker {
  color: var(--muted);
  display: block;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text-strong);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  margin-top: 3px;
}

.header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.theme-toggle,
button {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  font-weight: 600;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

button {
  background: var(--surface-muted);
  color: var(--text);
}

button:hover {
  background: color-mix(in srgb, var(--surface-muted) 82%, var(--multi-blue));
  border-color: var(--multi-blue);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  box-shadow: 0 0 0 4px var(--ring);
  outline: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

.theme-toggle {
  background: transparent;
  color: var(--muted-strong);
  justify-content: center;
  padding: 8px;
  width: 38px;
}

.theme-icon {
  background: currentColor;
  display: inline-block;
  height: 18px;
  width: 18px;
}

.theme-toggle[data-icon="moon"] .theme-icon {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M20.5 14.8A8.5 8.5 0 0 1 9.2 3.5 9.4 9.4 0 1 0 20.5 14.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M20.5 14.8A8.5 8.5 0 0 1 9.2 3.5 9.4 9.4 0 1 0 20.5 14.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.theme-toggle[data-icon="sun"] .theme-icon {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 7a5 5 0 1 1 0 10 5 5 0 0 1 0-10Zm0-6 1.5 3h-3L12 1Zm0 19 1.5 3h-3l1.5-3ZM4.2 2.8l3.2 1.1-2.1 2.1-1.1-3.2Zm14.5 15.2 2.1 2.1-3.2 1.1 1.1-3.2ZM1 12l3-1.5v3L1 12Zm19 0 3-1.5v3L20 12ZM4.2 21.2 5.3 18l2.1 2.1-3.2 1.1ZM18.7 6l-1.1-3.2 3.2 1.1L18.7 6Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 7a5 5 0 1 1 0 10 5 5 0 0 1 0-10Zm0-6 1.5 3h-3L12 1Zm0 19 1.5 3h-3l1.5-3ZM4.2 2.8l3.2 1.1-2.1 2.1-1.1-3.2Zm14.5 15.2 2.1 2.1-3.2 1.1 1.1-3.2ZM1 12l3-1.5v3L1 12Zm19 0 3-1.5v3L20 12ZM4.2 21.2 5.3 18l2.1 2.1-3.2 1.1ZM18.7 6l-1.1-3.2 3.2 1.1L18.7 6Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

#btn-start,
#btn-start-vibration {
  background: var(--multi-blue);
  border-color: var(--multi-blue);
  color: #ffffff;
}

#btn-start:hover,
#btn-start-vibration:hover {
  background: var(--multi-blue-strong);
  border-color: var(--multi-blue-strong);
}

#btn-stop,
#btn-stop-vibration {
  color: var(--severity-critical);
}

.shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}

.content-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-title {
  min-height: 124px;
  padding: 18px 16px;
}

.sidebar-title .eyebrow {
  color: var(--sidebar-muted);
}

.sidebar-title h1 {
  color: var(--sidebar-text);
  font-size: 20px;
  line-height: 1.15;
  margin-top: 8px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}

.tab-button {
  background: transparent;
  border-color: transparent;
  color: var(--sidebar-muted);
  gap: 12px;
  justify-content: flex-start;
  margin: 0;
  min-height: 40px;
  padding: 10px 12px;
  width: 100%;
}

.tab-button:hover {
  background: var(--sidebar-item-hover);
  border-color: transparent;
  color: var(--sidebar-text);
}

.tab-button.active {
  background: var(--sidebar-accent);
  border-color: var(--sidebar-accent);
  color: var(--sidebar-text);
  box-shadow: none;
}

.tab-icon {
  align-items: center;
  background: transparent;
  border-radius: 0;
  display: inline-flex;
  height: 20px;
  justify-content: center;
  position: relative;
  width: 20px;
}

.camera-icon::before {
  border: 2px solid currentColor;
  border-radius: 3px;
  content: "";
  height: 10px;
  width: 16px;
}

.camera-icon::after {
  border: 2px solid currentColor;
  border-radius: 999px;
  content: "";
  height: 4px;
  left: 7px;
  position: absolute;
  top: 6px;
  width: 4px;
}

.vibration-icon::before {
  background: currentColor;
  content: "";
  height: 16px;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Cpath d='M1 3c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M1 9c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M1 15c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Cpath d='M1 3c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M1 9c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Cpath d='M1 15c2 0 2-2 4-2s2 2 4 2 2-2 4-2 2 2 4 2 2-2 4-2 2 2 4 2' stroke='black' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  width: 20px;
}

main {
  margin: 0;
  max-width: none;
  min-width: 0;
  padding: 0;
}

.tab-panel {
  display: none;
  gap: 20px;
  margin: 0 auto;
  max-width: 1480px;
  padding: 24px;
  width: 100%;
}

.tab-panel.active {
  display: grid;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  padding: 18px 20px;
}

.toolbar-slot {
  align-items: center;
  backdrop-filter: blur(16px);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  display: flex;
  justify-content: flex-end;
  min-height: 52px;
  padding: 7px 10px;
  position: sticky;
  top: 14px;
  width: 100%;
  z-index: 30;
}

.section-heading {
  border-bottom: 1px solid var(--border);
  margin: -2px -2px 16px;
  padding: 0 2px 14px;
}

.section-heading.compact {
  margin-bottom: 12px;
  padding-bottom: 10px;
}

h2 {
  color: var(--text-strong);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 4px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
}

.row label {
  color: var(--muted-strong);
  display: flex;
  flex: 1 1 170px;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  min-width: 0;
}

input[type="text"],
input[type="number"],
input[type="password"],
select {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

/* Neutralize the browser's autofill background so password/username keep the
   dark theme instead of the user-agent's light-yellow fill. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
  caret-color: var(--text);
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 72%, transparent);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 16px,
    calc(100% - 11px) 16px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
  padding-right: 30px;
}

input[type="checkbox"] {
  accent-color: var(--multi-blue);
  height: 16px;
  width: 16px;
}

.checkbox-label {
  align-items: center;
  flex: 0 0 auto !important;
  flex-direction: row !important;
  gap: 8px !important;
  margin-top: 22px;
}

.buttons {
  align-items: center;
  gap: 8px;
}

.advanced {
  background: color-mix(in srgb, var(--surface-muted) 70%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: block;
  padding: 10px 12px;
}

.advanced summary {
  color: var(--muted-strong);
  cursor: pointer;
  font-weight: 700;
  user-select: none;
}

.advanced-grid {
  margin: 12px 0 0;
}

.aggregate {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.metric {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset;
  min-height: 86px;
  overflow: hidden;
  padding: 13px 14px;
  position: relative;
}

.metric::before {
  background: linear-gradient(180deg, var(--multi-blue), #2dd4bf);
  content: "";
  inset: 0 auto 0 0;
  position: absolute;
  width: 3px;
}

.metric .label {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metric .value {
  color: var(--text-strong);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.15;
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

.table-wrap + .buttons {
  margin-top: 18px;
}

table {
  border-collapse: collapse;
  font-size: 12px;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-muted);
  color: var(--muted-strong);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

td {
  color: var(--text);
}

tbody tr {
  background: var(--surface-strong);
}

tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-muted) 38%, var(--surface-strong));
}

tbody tr:hover {
  background: color-mix(in srgb, var(--multi-blue) 10%, var(--surface-strong));
}

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

.dot {
  border-radius: 50%;
  display: inline-block;
  height: 9px;
  width: 9px;
}

.dot.on {
  background: var(--status-online);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--status-online) 18%, transparent);
}

.dot.off {
  background: var(--muted);
}

.logs {
  background: var(--input-bg);
  background-image: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  margin: 0;
  max-height: 300px;
  min-height: 180px;
  overflow: auto;
  padding: 12px 14px;
  white-space: pre-wrap;
}

.error {
  color: var(--severity-critical);
  font-weight: 600;
  margin: 4px 0 0;
  min-height: 1.25em;
}

.state {
  align-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  gap: 7px;
  letter-spacing: 0.06em;
  min-height: 30px;
  padding: 5px 11px;
  text-transform: uppercase;
}

.state::before {
  background: currentColor;
  border-radius: 50%;
  content: "";
  height: 7px;
  width: 7px;
}

.state.idle {
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  color: var(--muted-strong);
}

.state.building {
  background: color-mix(in srgb, var(--severity-info) 12%, transparent);
  color: var(--severity-info);
}

.state.running {
  background: color-mix(in srgb, var(--status-online) 12%, transparent);
  color: var(--status-online);
}

.state.stopping {
  background: color-mix(in srgb, var(--status-warning) 14%, transparent);
  color: var(--status-warning);
}

.state.error {
  background: color-mix(in srgb, var(--severity-critical) 12%, transparent);
  color: var(--severity-critical);
}

#cameras-config,
#vibration-config {
  margin: 0;
  min-width: 660px;
}

#vibration-config {
  min-width: 980px;
}

#cameras-config td:first-child,
#vibration-config td:first-child {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  width: 3rem;
}

#cameras-config input.cam-name,
#cameras-config select.cam-source,
#vibration-config input,
#vibration-config select {
  width: 100%;
}

.upload-hint {
  color: var(--multi-blue);
  font-size: 12px;
  font-weight: 700;
  min-height: 20px;
}

@supports not (color: color-mix(in srgb, white, black)) {
  .app-header,
  .panel {
    background: var(--surface-strong);
  }

  button:hover,
  tbody tr:hover {
    background: var(--surface-muted);
  }
}

@media (max-width: 980px) {
  .app-header {
    justify-content: flex-start;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .toolbar-slot {
    justify-content: flex-start;
    padding: 14px 16px;
    width: 100%;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
  }

  .sidebar-title {
    border-bottom: 0;
    flex: 1 1 220px;
    min-height: auto;
    padding: 4px 12px 4px 0;
  }

  .sidebar-title h1 {
    font-size: 18px;
    margin-top: 4px;
  }

  .sidebar-nav {
    flex: 1 1 auto;
    flex-direction: row;
    padding: 0;
  }

  .tab-button {
    margin-bottom: 0;
    width: auto;
  }

  .tab-panel {
    padding: 16px;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 0;
  }

  h1 {
    font-size: 21px;
  }

  .panel {
    padding: 16px;
  }

  .row {
    gap: 10px;
  }

  .row label {
    flex-basis: 100%;
  }

  .buttons button {
    flex: 1 1 140px;
    justify-content: center;
  }

  .state {
    flex: 1 1 auto;
    justify-content: center;
  }

  .theme-toggle {
    flex: 0 0 38px;
    justify-content: center;
  }
}
