.admin-body {
  min-height: 100vh;
  background: #eef2ef;
  overflow-x: hidden;
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(90deg, transparent 49.95%, rgba(23, 107, 99, 0.06) 50%, transparent 50.05%),
    linear-gradient(rgba(23, 107, 99, 0.035) 1px, transparent 1px),
    #eef2ef;
  background-size: 100% 100%, 100% 48px, auto;
}

.login-card {
  width: min(100%, 440px);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-card__copy {
  margin: 46px 0 30px;
}

.login-card__copy h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.18;
  letter-spacing: -0.045em;
}

.login-card__copy p:last-child {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.api-origin {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.api-origin code,
.admin-sidebar__foot code {
  overflow-wrap: anywhere;
  font-family: ui-monospace, "Cascadia Mono", monospace;
}

.admin-app {
  min-height: 100vh;
}

.admin-sidebar {
  position: fixed;
  z-index: 50;
  inset: 0 auto 0 0;
  width: 232px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f8faf8;
}

.admin-sidebar__brand {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.admin-nav {
  display: grid;
  gap: 4px;
  padding: 18px 12px;
}

.admin-nav button {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 0;
  border-radius: 9px;
  padding: 0 14px;
  background: transparent;
  color: #53605b;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.admin-nav button:hover {
  background: #eef3f0;
  color: var(--ink);
}

.admin-nav button[aria-current="page"] {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 680;
}

.admin-nav button[aria-current="page"]::before {
  width: 5px;
  height: 5px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--brand);
  content: "";
}

.admin-sidebar__foot {
  margin-top: auto;
  padding: 18px 22px 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.admin-sidebar__foot span,
.admin-sidebar__foot code {
  display: block;
}

.admin-sidebar__foot code {
  margin-top: 4px;
  color: #40504a;
}

.admin-main {
  min-width: 0;
  margin-left: 232px;
}

.admin-topbar {
  position: sticky;
  z-index: 35;
  top: 0;
  min-height: 78px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(20px, 4vw, 46px);
  border-bottom: 1px solid rgba(219, 226, 222, 0.9);
  background: rgba(238, 242, 239, 0.9);
  backdrop-filter: blur(18px);
}

.admin-topbar > div:nth-child(2) {
  display: grid;
}

.admin-topbar strong {
  font-size: 14px;
}

.admin-topbar span {
  color: var(--muted);
  font-size: 11px;
}

.admin-topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.text-button,
.icon-button {
  border: 0;
  background: transparent;
  color: #4d5a55;
  cursor: pointer;
}

.text-button {
  padding: 8px 10px;
  font-size: 13px;
}

.text-button:hover {
  color: var(--brand);
}

.text-button--danger:hover {
  color: var(--danger);
}

.icon-button {
  min-width: 36px;
  min-height: 36px;
  border-radius: 9px;
}

.icon-button:hover {
  background: #e4eae6;
}

.sidebar-open,
.sidebar-close {
  display: none;
}

.admin-content {
  width: min(100%, 1480px);
  padding: 42px clamp(20px, 4vw, 46px) 80px;
}

.admin-view {
  display: none;
}

.admin-view.is-active {
  display: block;
}

.view-head {
  min-height: 110px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 38px;
  margin-bottom: 28px;
}

.view-head h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.05em;
}

.view-head > p {
  max-width: 470px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.metric-card {
  min-height: 158px;
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  margin: auto 0 4px;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 32px;
  line-height: 1;
  font-weight: 620;
}

.metric-card--alert strong {
  color: var(--danger);
}

.admin-card {
  min-width: 0;
  padding: 24px;
}

.form-card {
  max-width: 900px;
}

.card-head {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.card-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.card-head--tools {
  align-items: center;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.72fr) minmax(480px, 1.28fr);
  gap: 16px;
}

.split-layout--security {
  margin-bottom: 16px;
}

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

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

.field,
.switch-field {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.field > span,
.switch-field > span {
  color: #46534e;
  font-size: 12px;
  font-weight: 650;
}

.field small {
  color: var(--muted);
  font-size: 11px;
}

.field--wide {
  grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea,
.search-field input,
.small-select,
.small-input {
  width: 100%;
  border: 1px solid #cfd9d4;
  border-radius: 9px;
  background: #fbfcfb;
  color: var(--ink);
  outline: 0;
  transition: border 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.field input,
.field select,
.search-field input,
.small-select,
.small-input {
  height: 42px;
  padding: 0 12px;
}

.field textarea {
  min-height: 112px;
  padding: 10px 12px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-field input:focus,
.small-select:focus,
.small-input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(23, 107, 99, 0.1);
}

.field input[readonly] {
  background: #f1f3f1;
  color: var(--muted);
}

.switch-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
}

.switch-field input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--brand);
}

.search-field {
  width: min(100%, 280px);
}

.small-select,
.small-input {
  width: min(100%, 220px);
}

.admin-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd6d1;
  border-radius: 9px;
  padding: 0 15px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.admin-button:hover:not(:disabled) {
  border-color: #aabcb4;
  background: #f8faf9;
}

.admin-button--primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.admin-button--primary:hover:not(:disabled) {
  border-color: var(--brand-strong);
  background: var(--brand-strong);
}

.admin-button--danger {
  border-color: #d5a8a3;
  background: #fff8f7;
  color: var(--danger);
}

.admin-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.form-message {
  min-height: 21px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.form-message[data-state="error"] {
  color: var(--danger);
}

.form-message[data-state="success"] {
  color: var(--brand);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

.table-wrap--compact {
  max-height: 500px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 12px;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid #e5eae7;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 550;
}

td {
  color: #35423d;
}

td:first-child,
th:first-child {
  padding-left: 4px;
}

td:last-child,
th:last-child {
  padding-right: 4px;
}

.row-title {
  display: grid;
}

.row-title strong {
  color: var(--ink);
  font-size: 12px;
}

.row-title small {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
}

.status-pill {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1ef;
  color: #5f6a66;
  font-size: 11px;
}

.status-pill[data-tone="good"] {
  background: #e5f1ed;
  color: var(--brand);
}

.status-pill[data-tone="warn"] {
  background: #f7efe3;
  color: var(--warning);
}

.status-pill[data-tone="bad"] {
  background: #f8eae8;
  color: var(--danger);
}

.table-action {
  border: 0;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-size: 12px;
}

.table-action--danger {
  color: var(--danger);
}

.empty-state {
  margin: 0;
  padding: 24px 6px;
  color: var(--muted);
  font-size: 13px;
}

.compact-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.compact-item {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.4fr) auto;
  align-items: center;
  gap: 18px;
  padding: 15px 4px;
  border-bottom: 1px solid #e5eae7;
  font-size: 12px;
}

.compact-item strong,
.compact-item span,
.compact-item small {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.admin-dialog {
  width: min(calc(100% - 28px), 760px);
  max-height: min(90vh, 900px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 30px 100px rgba(20, 40, 34, 0.22);
}

.admin-dialog::backdrop {
  background: rgba(23, 35, 31, 0.36);
  backdrop-filter: blur(3px);
}

.dialog-shell {
  display: grid;
  max-height: inherit;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 22px;
}

.dialog-body {
  overflow-y: auto;
  padding: 24px;
}

.dialog-devices {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  width: min(calc(100% - 36px), 380px);
  display: grid;
  gap: 8px;
}

.toast {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  color: #34413c;
  font-size: 13px;
}

.toast[data-state="error"] {
  border-left-color: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .split-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .admin-sidebar {
    width: min(82vw, 280px);
    transform: translateX(-105%);
    box-shadow: 20px 0 60px rgba(20, 40, 34, 0.13);
    transition: transform 180ms ease;
  }

  .admin-sidebar.is-open {
    transform: none;
  }

  .admin-main {
    margin-left: 0;
  }

  .sidebar-open,
  .sidebar-close {
    display: inline-grid;
    place-items: center;
  }

  .view-head {
    display: block;
  }

  .view-head > p {
    margin-top: 14px;
  }
}

@media (max-width: 580px) {
  .admin-login {
    padding: 14px;
  }

  .login-card {
    padding: 28px 22px;
  }

  .admin-content {
    padding-top: 28px;
  }

  .metric-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .field--wide {
    grid-column: auto;
  }

  .metric-card {
    min-height: 125px;
  }

  .card-head--tools {
    align-items: stretch;
    flex-direction: column;
  }

  .search-field,
  .small-select,
  .small-input {
    width: 100%;
  }

  .compact-item {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .admin-dialog {
    width: 100%;
    max-height: 92vh;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
  }
}

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