:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #d9e2ef;
  --line-soft: #e7edf5;
  --text: #172033;
  --muted: #64748b;
  --primary: #1f5fe7;
  --primary-strong: #194fc4;
  --sidebar: #13213a;
  --sidebar-muted: #b8c7dd;
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  transition:
    background 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

button:hover {
  background: var(--primary-strong);
  box-shadow: 0 8px 18px rgba(31, 95, 231, 0.18);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  color: #1f2937;
  background: #e8eef6;
}

button.secondary:hover {
  background: #dce6f2;
  box-shadow: none;
}

button.ghost {
  width: 100%;
  color: #dbeafe;
  background: rgba(255, 255, 255, 0.12);
}

input,
select {
  min-height: 38px;
  border: 1px solid #d4dce8;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(20, 35, 60, 0.14);
}

.brand {
  display: grid;
  gap: 6px;
  margin-bottom: 24px;
}

.brand strong {
  font-size: 26px;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 14px;
}

.brand.small {
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand.small strong {
  color: #fff;
  font-size: 20px;
}

.brand.small span {
  color: var(--sidebar-muted);
  font-size: 13px;
}

.login-form,
.login-form label {
  display: grid;
  gap: 8px;
}

.login-form {
  gap: 16px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 18px;
  background: var(--sidebar);
}

#nav {
  display: grid;
  grid-auto-rows: min-content;
  align-content: start;
  gap: 6px;
  flex: 0 0 auto;
}

#nav button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  color: #d7e2f1;
  background: transparent;
  border-radius: 6px;
  text-align: left;
}

#nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

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

.content {
  min-width: 0;
  padding: 28px 32px 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar p:empty {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-actions button {
  width: auto;
  min-width: 72px;
  white-space: nowrap;
}

.topbar-actions button.ghost {
  color: #1f2937;
  background: #fff;
  border: 1px solid var(--line);
}

.topbar-actions button.ghost:hover {
  background: #f8fafc;
  box-shadow: none;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 26px;
  line-height: 1.25;
}

h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

.topbar p,
.section-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.page {
  width: 100%;
}

.apps-grid,
.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.app-card,
.table-row,
.note-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
}

.app-card {
  display: flex;
  flex-direction: column;
  min-height: 148px;
  gap: 18px;
  box-shadow: 0 10px 28px rgba(22, 34, 51, 0.05);
}

.app-card h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
}

.app-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.app-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 10px;
  color: #1d4ed8;
  background: #dbeafe;
  font-size: 12px;
  white-space: nowrap;
}

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

.section-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-head-row button {
  flex-shrink: 0;
}

.inline-form,
.grid-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.inline-form {
  grid-template-columns: minmax(180px, 1fr) auto auto auto;
  align-items: center;
}

.grid-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.grid-form button {
  grid-column: span 3;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #334155;
}

.check input {
  min-height: auto;
}

.table-list {
  display: grid;
  gap: 10px;
  width: 100%;
}

.admin-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
}

.admin-table th,
.admin-table td {
  height: 62px;
  border-bottom: 1px solid var(--line-soft);
  padding: 11px 14px;
  color: #263245;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  height: 48px;
  color: #6b778c;
  background: #fbfcfe;
  font-weight: 600;
}

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

.admin-table tbody tr:hover td {
  background: #f8fbff;
}

.device-table th:nth-child(1),
.device-table td:nth-child(1) {
  width: 12%;
}

.device-table th:nth-child(2),
.device-table td:nth-child(2) {
  width: 11%;
}

.device-table th:nth-child(3),
.device-table td:nth-child(3) {
  width: 8%;
}

.device-table th:nth-child(4),
.device-table td:nth-child(4) {
  width: 10%;
}

.device-table th:nth-child(5),
.device-table td:nth-child(5) {
  width: 9%;
}

.device-table th:nth-child(6),
.device-table td:nth-child(6) {
  width: 11%;
}

.device-table th:nth-child(7),
.device-table td:nth-child(7) {
  width: 15%;
}

.device-table th:nth-child(8),
.device-table td:nth-child(8) {
  width: 14%;
}

.device-table th:nth-child(9),
.device-table td:nth-child(9) {
  width: 16%;
}

.customer-table,
.user-table {
  min-width: 900px;
}

.customer-table th:nth-child(1),
.customer-table td:nth-child(1) {
  width: 24%;
}

.customer-table th:nth-child(2),
.customer-table td:nth-child(2) {
  width: 12%;
}

.customer-table th:nth-child(3),
.customer-table td:nth-child(3) {
  width: 24%;
}

.customer-table th:nth-child(4),
.customer-table td:nth-child(4) {
  width: 20%;
}

.customer-table th:nth-child(5),
.customer-table td:nth-child(5) {
  width: 20%;
}

.user-table th:nth-child(1),
.user-table td:nth-child(1) {
  width: 14%;
}

.user-table th:nth-child(2),
.user-table td:nth-child(2) {
  width: 13%;
}

.user-table th:nth-child(3),
.user-table td:nth-child(3) {
  width: 13%;
}

.user-table th:nth-child(4),
.user-table td:nth-child(4) {
  width: 9%;
}

.user-table th:nth-child(5),
.user-table td:nth-child(5) {
  width: 12%;
}

.user-table th:nth-child(6),
.user-table td:nth-child(6) {
  width: 22%;
}

.user-table th:nth-child(7),
.user-table td:nth-child(7) {
  width: 17%;
}

.name-cell {
  font-weight: 600;
}

.empty-cell {
  height: 96px;
  color: var(--muted);
  text-align: center !important;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.status-online {
  border-color: #b7ebc6;
  color: #15803d;
  background: #eefdf3;
}

.status-offline {
  border-color: #ffd3d3;
  color: #e5484d;
  background: #fff2f2;
}

.status-unknown {
  border-color: #d9dee8;
  color: #64748b;
  background: #f4f6f9;
}

.table-select {
  width: 138px;
  min-height: 32px;
  border-radius: 4px;
  font-size: 13px;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

button.mini {
  min-height: 30px;
  border: 1px solid #d5dfec;
  border-radius: 4px;
  padding: 0 11px;
  color: #304158;
  background: #fff;
  font-size: 13px;
  white-space: nowrap;
}

button.mini:hover {
  background: #f3f7fc;
  box-shadow: none;
}

.table-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 76px;
}

.table-row strong {
  display: block;
  margin-bottom: 5px;
}

.device-row .meta {
  display: block;
}

.device-meta {
  display: grid;
  gap: 4px;
}

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

.device-actions select {
  min-width: 132px;
}

button.danger {
  border-color: #fecaca;
  color: #991b1b;
  background: #fee2e2;
}

button.danger:hover {
  background: #fecaca;
  box-shadow: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 15, 31, 0.48);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 28px 90px rgba(18, 29, 49, 0.25);
}

.device-detail-panel {
  width: min(840px, calc(100vw - 32px));
}

.class-card-permission-panel {
  width: min(640px, 100vw);
}

.class-card-permission-drawer {
  display: block;
  overflow: hidden;
}

.class-card-permission-drawer .class-card-permission-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(640px, 100vw);
  max-height: none;
  overflow-y: auto;
  border-width: 0 0 0 1px;
  border-radius: 0;
  box-shadow: -18px 0 48px rgba(18, 29, 49, 0.18);
}

.device-detail-content {
  padding: 0 22px 22px;
}

.device-info-table,
.detail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.device-info-table th,
.device-info-table td,
.detail-table th,
.detail-table td {
  min-width: 0;
  border: 1px solid var(--line-soft);
  padding: 10px 12px;
  color: #263245;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-info-table th {
  width: 180px;
  color: #5d6878;
  background: #f6f8fb;
  font-weight: 600;
}

.detail-section {
  margin-top: 22px;
}

.detail-section h4 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

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

.detail-table {
  min-width: 620px;
}

.detail-table th {
  color: #6b778c;
  background: #fbfcfe;
  font-weight: 600;
}

.detail-table td {
  white-space: nowrap;
}

.detail-empty {
  min-height: 70px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 14px;
}

.modal-head h3 {
  margin: 0 0 6px;
  font-size: 22px;
}

.modal-icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  padding: 0;
  color: #1f2937;
  background: #fff;
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.modal-icon-button:hover {
  background: #f6f8fb;
  box-shadow: none;
}

.modal-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 0 22px 22px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.required-label {
  position: relative;
  padding-left: 10px;
}

.required-label::after {
  content: "*";
  position: absolute;
  top: 0;
  left: 0;
  color: #dc2626;
}

#userDialogForm .field.required-label {
  padding-left: 0;
}

#userDialogForm .field.required-label::after {
  content: none;
}

#userDialogForm .field-label {
  display: block;
  min-height: 20px;
}

#userDialogForm .field.required-label .field-label {
  position: relative;
  padding-left: 10px;
}

#userDialogForm .field.required-label .field-label::before {
  content: "*";
  position: absolute;
  top: 0;
  left: 0;
  color: #dc2626;
}

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

input.invalid-control,
select.invalid-control,
textarea.invalid-control {
  border-color: #dc2626 !important;
  background: #fff7f7;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
}

.modal-form .check {
  display: flex;
  align-items: center;
  min-height: 38px;
}

.product-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 28px;
  min-height: 38px;
}

.product-options .check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  white-space: nowrap;
}

.product-options .check input {
  width: auto;
  flex: 0 0 auto;
}

.field-span-2 {
  grid-column: span 2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.class-card-scope-field {
  display: grid;
  gap: 8px;
}

.class-card-section-label {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.class-card-scope-panel,
.class-card-permission-options {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  background: #fbfcfe;
}

.class-card-scope-section {
  display: grid;
  gap: 8px;
}

.class-card-scope-section small {
  color: #718096;
  font-size: 12px;
  font-weight: 600;
}

.class-card-check-grid,
.class-card-permission-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.class-card-check-grid {
  display: grid;
  gap: 8px;
}

.class-card-check {
  display: flex;
  min-width: 0;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  border: 1px solid #e1e8f2;
  border-radius: 8px;
  padding: 0 12px;
  color: #60708a;
  background: #fff;
  cursor: pointer;
}

.class-card-check input {
  width: 16px;
  height: 16px;
  min-height: auto;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  accent-color: #2f57a7;
}

.class-card-check span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}

.class-card-check:has(input:checked) {
  border-color: #b9c8e8;
  color: #2f57a7;
  background: #f4f7ff;
}

.class-card-permission-check {
  min-height: 40px;
  font-weight: 700;
}

.class-card-empty {
  color: var(--muted);
  font-size: 13px;
}

.class-card-permission-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0 -22px -22px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.class-card-permission-actions button {
  min-width: 120px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.row-actions button {
  min-width: 86px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: #172033;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.25);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 12px;
  }

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

  .content {
    padding: 20px 16px 32px;
  }

  .topbar {
    align-items: flex-start;
  }

  .apps-grid,
  .note-grid {
    grid-template-columns: 1fr;
  }

  .section-head-row {
    flex-direction: column;
  }

  .section-head-row button {
    width: 100%;
  }

  .inline-form,
  .grid-form,
  .table-row {
    grid-template-columns: 1fr;
  }

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

  .modal-panel {
    width: calc(100vw - 18px);
    max-height: calc(100vh - 18px);
  }

  .class-card-permission-drawer .class-card-permission-panel {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border: 0;
  }

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

  .field-span-2 {
    grid-column: auto;
  }

  .class-card-check-grid,
  .class-card-permission-options {
    grid-template-columns: 1fr;
  }

  .class-card-permission-actions {
    margin: 0 -22px -22px;
  }

  .grid-form button {
    grid-column: auto;
  }
}
