:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #20232a;
  --muted: #63708a;
  --line: #d8dde6;
  --orange: #ff6a13;
  --dark: #20232a;
  --danger: #f04444;
  --ok: #0f8f5f;
  --soft: #f4f4f5;
  --soft-accent: #fff7ed;
  --header-bg: #ffffff;
  --nav-bg: #f3f4f6;
  --nav-button-bg: #ffffff;
  --nav-active-bg: #20232a;
  --nav-active-text: #ffffff;
  --secondary-button-bg: #eceef2;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --panel-radius: 8px;
  --button-radius: 6px;
  --admin-width: 1480px;
  --shadow: 0 10px 28px rgba(39, 39, 42, 0.08);
  --primary-text: #ffffff;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
}

.brand,
.top nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
}

.brand img {
  width: 32px;
  height: 32px;
}

.top nav {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top nav a,
.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--button-radius);
  background: var(--secondary-button-bg);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.button.primary,
button.primary,
button[type="submit"] {
  background: var(--orange);
  color: var(--primary-text);
}

.button.dark,
button.dark {
  background: var(--dark);
  color: #ffffff;
}

.button.danger,
button.danger {
  background: var(--danger);
  color: #ffffff;
}

.home,
.narrow {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 24px 16px;
}

.home {
  display: grid;
  gap: 20px;
}

.home-intro,
.login-card,
.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.home-intro img {
  max-width: 240px;
  height: auto;
}

.app-shell,
.quick-shell {
  width: min(var(--admin-width), 100%);
  margin: 0 auto;
  padding: 18px 20px 32px;
  flex: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 18px;
  scrollbar-width: thin;
}

.tabs button {
  flex: 0 0 auto;
  min-height: 40px;
  background: var(--nav-button-bg);
  border: 1px solid var(--line);
}

.tabs button:hover,
.top nav a:hover,
.button:hover,
button:hover {
  filter: brightness(0.98);
}

.tabs button.active {
  border-color: var(--nav-active-bg);
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
}

.layout {
  display: grid;
  gap: 18px;
  align-items: start;
}

.sidebar,
.content {
  min-width: 0;
}

.project-list,
.list,
.grid,
.form-grid {
  display: grid;
  gap: 10px;
}

.grid,
.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.project-button {
  position: relative;
  display: grid;
  width: 100%;
  justify-content: stretch;
  justify-items: stretch;
  align-items: start;
  min-height: 80px;
  background: #ffffff;
  border: 1px solid var(--line);
  text-align: left;
  box-shadow: none;
  padding: 14px 16px 42px;
}

.project-button-text {
  display: grid;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.project-button strong,
.project-button small {
  display: block;
  overflow-wrap: anywhere;
}

.project-button strong {
  font-size: 15px;
  line-height: 1.25;
}

.project-button small {
  font-size: 13px;
  font-weight: 700;
}

.project-button em {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 10px;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #ddf7ed;
  color: var(--ok);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.project-button.active {
  border-color: var(--orange);
  background: var(--soft-accent);
  box-shadow: inset 4px 0 0 var(--orange);
}

.sidebar-head {
  display: grid;
  gap: 2px;
  margin-bottom: 12px;
}

.eyebrow {
  color: var(--orange);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.full-button {
  width: 100%;
  margin-top: 12px;
}

.dashboard-stack {
  display: grid;
  gap: 16px;
}

.dashboard-hero {
  display: grid;
  gap: 18px;
  border-left: 4px solid var(--orange);
  padding: 20px;
}

.hero-actions,
.quick-action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.metric-card {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.metric-card strong {
  font-size: 28px;
  line-height: 1;
  color: var(--text);
}

.metric-card span {
  color: var(--muted);
  font-weight: 600;
}

.start-panel {
  display: grid;
  gap: 10px;
}

.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.section-head,
.mqtt-profile-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.mqtt-profile-grid {
  display: grid;
  gap: 12px;
  margin: 16px 0 22px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.mqtt-profile-card {
  display: grid;
  gap: 12px;
}

.mqtt-facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.mqtt-facts div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.mqtt-facts dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.mqtt-facts dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.mqtt-error {
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: var(--button-radius);
  background: #fff1f2;
  color: var(--danger);
}

.mqtt-error p,
.mqtt-advice {
  margin: 0;
}

.mqtt-advice {
  color: var(--muted);
  font-weight: 800;
}

.mqtt-event code,
.mqtt-event pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mqtt-monitor {
  display: grid;
  gap: 16px;
}

.mqtt-control-bar {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--soft);
}

.mqtt-filter-buttons {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.mqtt-filter-buttons button {
  flex: 0 0 auto;
  min-height: 38px;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
}

.mqtt-filter-buttons button.active {
  border-color: var(--dark);
  background: var(--dark);
  color: #ffffff;
}

.mqtt-filter-buttons span {
  display: inline-flex;
  min-width: 24px;
  justify-content: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.mqtt-filter-buttons button.active span {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.mqtt-filter-buttons i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--danger);
}

.mqtt-filter-buttons i.online {
  background: var(--ok);
}

.mqtt-events-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.mqtt-event-list {
  display: grid;
  gap: 8px;
  max-height: 720px;
  overflow: auto;
  padding-right: 4px;
}

.mqtt-log-item {
  box-shadow: none;
}

.mqtt-log-item summary {
  grid-template-columns: auto minmax(0, 1fr) auto 28px;
  min-height: 46px;
  padding: 9px 12px;
}

.mqtt-log-item code {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mqtt-log-item small {
  white-space: nowrap;
}

.mqtt-log-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.mqtt-log-body pre {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--button-radius);
  background: #0f172a;
  color: #e5e7eb;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  line-height: 1.15;
}

p {
  margin: 0 0 10px;
}

.muted,
small {
  color: var(--muted);
}

.field-help {
  display: block;
  margin-top: -2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

details {
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 28px;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "+";
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--muted);
  font-weight: 900;
}

details[open] summary {
  background: #fafafa;
  border-bottom: 1px solid var(--line);
}

details[open] summary::after {
  content: "-";
  background: var(--dark);
  color: #ffffff;
}

.details-body {
  padding: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pill.ok {
  background: #dcf7ec;
  color: var(--ok);
}

.pill.bad {
  background: #ffe2e2;
  color: var(--danger);
}

.footer {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin-top: auto;
  padding: 28px 16px;
  text-align: center;
}

.footer img {
  max-width: 160px;
  max-height: 48px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
  max-width: min(420px, calc(100% - 24px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--dark);
  color: #ffffff;
  font-weight: 800;
}

.admin-menu-toggle,
.admin-menu-backdrop {
  display: none;
}

.settings-block {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.settings-block:first-of-type {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.settings-panel {
  display: grid;
  gap: 14px;
}

.settings-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-quick span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.settings-group {
  box-shadow: none;
}

.settings-group summary {
  min-height: 58px;
  grid-template-columns: minmax(0, 1fr) auto 28px;
  background: #ffffff;
}

.settings-group summary span {
  display: block;
  font-size: 18px;
}

.settings-group summary small {
  justify-self: end;
  text-align: right;
}

.color-grid label {
  position: relative;
}

.color-grid label::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--swatch, transparent);
}

.color-grid input {
  padding-right: 42px;
}

.settings-savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  padding: 12px 0 0;
  background: linear-gradient(to top, var(--panel) 80%, rgba(255, 255, 255, 0));
}

.admin-page .footer {
  padding: 16px;
  text-align: left;
}

.admin-page .footer {
  grid-template-columns: auto minmax(0, 1fr);
  justify-items: start;
  align-items: center;
  gap: 12px 16px;
}

.admin-page .footer img {
  max-width: 126px;
}

.admin-page .footer strong,
.admin-page .footer p,
.admin-page .footer small {
  margin: 0;
}

.admin-page .footer p,
.admin-page .footer small {
  font-size: 12px;
}

@media (min-width: 900px) {
  .home {
    grid-template-columns: 1.5fr 1fr;
    align-items: start;
  }

  .layout {
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
  }

  .app-shell,
  .quick-shell {
    padding: 18px 20px 0;
  }

  .sidebar {
    position: sticky;
    top: 138px;
  }

  .dashboard-hero {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .admin-page .tabs {
    position: sticky;
    top: 64px;
    z-index: 8;
    margin: 0 -20px 18px;
    padding: 10px 20px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--line);
  }
}

@media (min-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .admin-menu-toggle {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--line);
    background: #ffffff;
  }

  .admin-menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 99px;
    background: var(--text);
  }

  .admin-page .top {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .admin-page .brand {
    flex: 1;
  }

  .admin-page .top nav {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.8fr) minmax(0, 0.9fr);
    gap: 6px;
    flex-wrap: nowrap;
    justify-content: stretch;
    overflow: hidden;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .admin-page .top nav::-webkit-scrollbar {
    display: none;
  }

  .admin-page .top nav a,
  .admin-page .top nav button {
    width: 100%;
    min-width: 0;
    flex: 1 1 auto;
    min-height: 38px;
    padding: 8px 6px;
    white-space: nowrap;
  }

  .admin-page .tabs {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(86vw, 330px);
    height: 100dvh;
    flex-direction: column;
    gap: 10px;
    padding: 86px 14px 18px;
    background: var(--header-bg);
    border-right: 1px solid var(--line);
    box-shadow: 18px 0 36px rgba(15, 23, 42, 0.16);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .admin-page.admin-menu-open .tabs {
    transform: translateX(0);
  }

  .admin-page .tabs button {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
    border: 0;
    background: rgba(15, 23, 42, 0.38);
    padding: 0;
  }

  .admin-menu-open .admin-menu-backdrop {
    display: block;
  }

  .admin-menu-open {
    overflow: hidden;
  }

  body:not(.admin-page) .top {
    align-items: flex-start;
    flex-direction: column;
  }

  body:not(.admin-page) .top nav {
    width: 100%;
    justify-content: stretch;
  }

  body:not(.admin-page) .top nav a {
    flex: 1 1 auto;
  }

  .layout {
    gap: 12px;
  }

  .app-shell,
  .quick-shell {
    padding: 14px 12px 26px;
  }

  .panel,
  .card,
  .home-intro,
  .login-card {
    padding: 14px;
  }

  .admin-page .footer {
    grid-template-columns: 1fr;
    text-align: center;
    justify-items: center;
  }

  .section-head,
  .mqtt-profile-top {
    align-items: stretch;
    flex-direction: column;
  }

  .mqtt-facts div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .mqtt-log-item summary {
    grid-template-columns: auto minmax(0, 1fr) 28px;
  }

  .mqtt-log-item small {
    display: none;
  }

  .mqtt-events-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-group summary {
    grid-template-columns: minmax(0, 1fr) 28px;
  }

  .settings-group summary small {
    display: none;
  }

  .settings-savebar {
    position: static;
    padding-top: 8px;
  }

  .settings-savebar button,
  .settings-panel > .section-head button {
    width: 100%;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-card {
    min-height: 76px;
    padding: 14px;
  }
}
