/* The admin portal, in the look of Diveology's and Bauernschnapsen's: a dark sidebar with the mark and an Admin tag, a
   pale work area, white cards with round corners and a soft shadow, round-ended buttons, the device's own font. My
   Empower's colours: forest for the sidebar, field green as the accent (lime in dark mode). Every colour is a token
   here; dark mode follows the device and redefines them, so a new colour goes in both sets. */
:root {
  --side: #163E35;
  --side-text: #F6F4EC;
  --side-muted: rgba(246, 244, 236, 0.66);
  --side-hover: rgba(246, 244, 236, 0.08);
  --side-on: rgba(216, 237, 134, 0.16);
  --side-on-text: #D8ED86;
  --bg: #F0F2EB;
  --surface: #FFFFFF;
  --surface-2: #F6F4EC;
  --text: #172B26;
  --muted: #52665E;
  --faint: #5E7068;
  --line: #DCE3D9;
  --accent: #286B55;
  --accent-strong: #163E35;
  --accent-text: #FFFFFF;
  --accent-soft: #E3EBDD;
  --danger: #A33A1F;
  --focus: #286B55;
  --shadow: 0 1px 2px rgba(23, 43, 38, 0.06), 0 8px 24px rgba(23, 43, 38, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --side: #0F2B25;
    --side-hover: rgba(246, 244, 236, 0.06);
    --bg: #0A1E1A;
    --surface: #12302A;
    --surface-2: #0E2621;
    --text: #F6F4EC;
    --muted: #B3C3BA;
    --faint: #9AAFA4;
    --line: rgba(246, 244, 236, 0.12);
    --accent: #D8ED86;
    --accent-strong: #E6F4AE;
    --accent-text: #163E35;
    --accent-soft: rgba(216, 237, 134, 0.12);
    --danger: #FFB59E;
    --focus: #D8ED86;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.faint {
  color: var(--faint);
}

.small {
  font-size: 13.5px;
}

.tiny {
  font-size: 12.5px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(216, 237, 134, 0.18);
  color: #D8ED86;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Buttons and fields */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.btn.wide {
  width: 100%;
  min-height: 46px;
  margin-top: 16px;
}

.btn.link {
  width: 100%;
  margin-top: 8px;
  background: none;
  color: var(--accent);
}

.btn.danger {
  background: none;
  color: var(--danger);
  box-shadow: inset 0 0 0 1.5px currentColor;
}

.btn.ghost-dark {
  background: var(--side-hover);
  color: var(--side-text);
}

input,
.input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.form-msg {
  margin-top: 12px;
  color: var(--danger);
  font-weight: 600;
}

.form-msg:empty {
  display: none;
}

#secMsg {
  color: var(--muted);
}

/* Sign-in */
.signin {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
  background: radial-gradient(1200px 600px at 70% -10%, #286B55, transparent 60%), #0E2621;
}

.signin-card {
  width: 100%;
  max-width: 420px;
  padding: 28px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.signin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 17px;
}

.signin-brand .tag {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.signin h1 {
  margin-bottom: 8px;
  font-size: 26px;
}

/* The portal: sidebar and work area */
.app {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 12px;
  background: var(--side);
  color: var(--side-text);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 18px;
  font-size: 16px;
  white-space: nowrap;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group {
  margin: 14px 12px 6px;
  color: var(--side-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--side-text);
  font-weight: 500;
  text-decoration: none;
}

.side-nav a:hover {
  background: var(--side-hover);
}

.side-nav a[aria-current="page"] {
  background: var(--side-on);
  color: var(--side-on-text);
}

.side-nav svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(246, 244, 236, 0.12);
}

.me {
  color: var(--side-muted);
  font-weight: 600;
}

.sidebar :focus-visible {
  outline-color: #D8ED86;
}

.work {
  width: 100%;
  max-width: 1440px;
  padding: 28px 36px 48px;
}

.work:focus {
  outline: none;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 30px;
}

.env {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.env::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #2E9B6B;
}

.env.dev {
  color: var(--muted);
}

.env.dev::before {
  background: #C98200;
}

@media (max-width: 900px) {
  .app {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px 10px;
  }

  .side-brand {
    padding: 0 0 10px;
  }

  .side-nav {
    flex-direction: row;
    gap: 6px;
    margin: 0 -16px;
    padding: 0 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav-group {
    display: none;
  }

  .side-nav a {
    flex: none;
    min-height: 38px;
    border-radius: 999px;
  }

  .side-foot {
    position: absolute;
    top: 12px;
    right: 16px;
    padding: 0;
    border: 0;
  }

  .work {
    padding: 20px 16px 40px;
  }

  .page-head h1 {
    font-size: 24px;
  }
}

/* Cards, the segmented control, chips */
.card {
  margin-bottom: 18px;
  padding: 20px 22px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 18px;
}

.card > p.muted {
  max-width: 80ch;
}

.count {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px 18px;
}

.toolbar .chips {
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .toolbar {
    grid-template-columns: 1fr;
  }
}

.seg {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
}

.seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.seg button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Asset tiles */
.assets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.assets.wide {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

@media (max-width: 600px) {
  .assets,
  .assets.wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .preview {
    padding: 10px;
  }

  .asset-meta {
    padding: 10px;
  }
}

.asset {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.preview {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.preview.small img {
  width: 48px;
  height: 48px;
}

.bg-paper {
  background: #F6F4EC;
}

.bg-white {
  background: #FFFFFF;
}

.bg-forest {
  background: #163E35;
}

.bg-none {
  padding: 12px;
  background: var(--surface-2);
}

.bg-none img {
  box-shadow: 0 0 0 1px var(--line);
}

.bg-check {
  background-color: #FFFFFF;
  background-image: linear-gradient(45deg, #E8EBE4 25%, transparent 25%, transparent 75%, #E8EBE4 75%),
    linear-gradient(45deg, #E8EBE4 25%, transparent 25%, transparent 75%, #E8EBE4 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

.bg-check img {
  max-width: 96px;
  max-height: 96px;
}

.code-preview {
  background: var(--surface-2);
  color: var(--muted);
  font: 600 22px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.asset-meta {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px 14px;
}

.asset-meta .row {
  margin-top: auto;
  padding-top: 8px;
}

/* Colours */
.colours {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.colour {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 0 0 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.colour b,
.colour span.tiny {
  padding: 0 12px;
}

.swatch {
  display: block;
  width: 100%;
  height: 84px;
  margin-bottom: 6px;
  box-shadow: inset 0 -1px 0 var(--line);
}

.colour b {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.hexcode {
  color: var(--muted);
  font: 600 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Guidelines */
.guide {
  max-width: 920px;
  padding: 28px 32px 36px;
  font-size: 15.5px;
  line-height: 1.65;
}

.guide h3 {
  margin: 32px 0 10px;
  font-size: 21px;
}

.guide h3:first-child {
  margin-top: 0;
}

.guide p,
.guide ul,
.guide ol {
  max-width: 72ch;
  margin: 0 0 12px;
}

.guide li {
  margin-bottom: 4px;
}

.guide code {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.9em;
}

.guide .sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 5px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
  vertical-align: -1px;
}

.table-wrap {
  margin: 8px 0 16px;
  overflow-x: auto;
}

.guide table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.guide th,
.guide td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.guide th {
  color: var(--muted);
  font-size: 12.5px;
}

@media (max-width: 700px) {
  .guide {
    padding: 20px 18px 24px;
  }
}

/* Previews */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0 18px;
  margin-bottom: 16px;
}

.addr {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.addr input {
  border: 0;
  min-width: 0;
}

.addr span {
  padding: 0 12px 0 2px;
  color: var(--muted);
  white-space: nowrap;
}

.addr:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.addr input:focus-visible {
  outline: none;
}

.row.nowrap {
  flex-wrap: nowrap;
}

.row .input {
  flex: 1;
  min-width: 200px;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}

.pill.on {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pill.off {
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--muted);
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px 18px;
  margin: 14px 0 16px;
}

.facts dt {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.facts dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.preview-card form {
  margin-top: 12px;
}

/* Security */
.devices {
  margin: 14px 0;
  padding: 0;
  list-style: none;
}

.devices li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.devices li div {
  display: flex;
  flex-direction: column;
}

#deviceName {
  flex: 1;
  min-width: 220px;
}

/* The toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  padding: 10px 18px;
  border-radius: 999px;
  background: #163E35;
  color: #F6F4EC;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
