:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #eef4ff;
  --line: #dfe5ef;
  --text: #162033;
  --muted: #69758a;
  --blue: #2367d1;
  --blue-dark: #164c9d;
  --green: #1f8a5b;
  --red: #c23b3b;
  --amber: #ad6b12;
  --shadow: 0 10px 28px rgba(34, 48, 74, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  min-height: 38px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label textarea,
label select {
  color: var(--text);
  font-size: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.brand {
  font-weight: 800;
  letter-spacing: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 48px;
}

.section-head,
.panel-head,
.device-top,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 18px;
}

.section-head h1,
.panel h2,
.device-card h2,
.login-panel h1 {
  margin: 0;
  letter-spacing: 0;
}

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

.section-head p,
.device-top p,
.description {
  margin: 5px 0 0;
  color: var(--muted);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.device-card,
.panel,
.login-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.device-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.device-card.disabled {
  opacity: 0.68;
}

.device-card h2 {
  font-size: 19px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--amber);
  flex: 0 0 auto;
}

.status-dot.on {
  background: var(--green);
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 0;
}

.meta-grid div {
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 10px;
}

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

dd {
  margin: 0;
  word-break: break-word;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
  margin: 18px 0;
}

.work-grid .panel:last-child {
  grid-column: 1 / -1;
}

.panel {
  padding: 18px;
}

.panel-head {
  margin-bottom: 14px;
}

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

.inline-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) 120px auto;
  gap: 8px;
  margin-bottom: 14px;
}

.inline-form.compact {
  grid-template-columns: minmax(150px, 1fr) auto;
  margin: 0;
}

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

.check-row input {
  width: auto;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  border-color: #b9c9e6;
  background: var(--surface-strong);
  color: var(--blue-dark);
}

.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  border-color: #e6bbbb;
  background: #fff2f2;
  color: var(--red);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.full {
  width: 100%;
}

.edit-block {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.edit-block summary {
  cursor: pointer;
  color: var(--blue-dark);
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.log-panel {
  margin-top: 18px;
}

.account-panel {
  margin-top: 18px;
}

.password-form {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  margin-bottom: 0;
}

.admin-section {
  margin-bottom: 18px;
}

.admin-device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.admin-device-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.admin-device-card.disabled {
  opacity: 0.68;
}

.admin-bottom-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 0.85fr);
  gap: 16px;
  margin: 18px 0;
}

.advanced-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.compact-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.compact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.compact-row strong,
.compact-row span {
  display: block;
}

.compact-row span {
  color: var(--muted);
  font-size: 13px;
}

.user-row {
  align-items: flex-start;
}

.user-summary {
  min-width: 92px;
}

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

.password-reset-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 8px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.badge.success {
  background: #e8f6ef;
  color: var(--green);
}

.badge.online {
  background: #e8f6ef;
  color: var(--green);
}

.badge.error {
  background: #fff0ed;
  color: var(--red);
}

.badge.offline {
  background: #fff0ed;
  color: var(--red);
}

.badge.unknown,
.badge.warn {
  background: #fff7e8;
  color: var(--amber);
}

.flash {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}

.flash.success {
  border-color: #b8dfcc;
  color: var(--green);
}

.flash.error {
  border-color: #edc2c2;
  color: var(--red);
}

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

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--muted);
}

.login-shell {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
}

@media (max-width: 820px) {
  .topbar {
    padding: 0 16px;
  }

  .topnav {
    gap: 8px;
  }

  .user-pill {
    display: none;
  }

  .work-grid,
  .admin-bottom-grid,
  .inline-form,
  .inline-form.compact,
  .password-form,
  .password-reset-form {
    grid-template-columns: 1fr;
  }

  .user-controls {
    justify-content: stretch;
    width: 100%;
  }

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