:root {
  --fg: #141c26;
  --muted: #526071;
  --line: #d8e0ea;
  --line-strong: #b8c4d4;
  --bg: #f3f6fa;
  --card: #ffffff;
  --nav-bg: #111927;
  --nav-fg: #d5deeb;
  --nav-muted: #8b9bb4;
  --nav-active-bg: #1f3356;
  --nav-active-border: #68a0ff;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --ok: #137333;
  --ok-bg: #e6f4ea;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn: #8f5700;
  --warn-bg: #fef7e0;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.table-wrapper:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.app-sidebar {
  background: var(--nav-bg);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-inline-end: 1px solid #223047;
}

.brand-block {
  padding: 0 10px 14px;
  border-bottom: 1px solid #223047;
}

.brand-title {
  display: block;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
}

.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--nav-muted);
  margin-top: 2px;
}

.nav-sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.nav-group-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--nav-muted);
  padding: 0 10px;
  margin: 0 0 4px;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-list a {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 10px 7px 12px;
  border-radius: 7px;
  border-inline-start: 3px solid transparent;
  color: var(--nav-fg);
  font-size: 13.5px;
  text-decoration: none;
}

.nav-list a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-list a[aria-current="page"] {
  background: var(--nav-active-bg);
  border-inline-start-color: var(--nav-active-border);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid #223047;
}

.user-badge {
  font-size: 12px;
  color: var(--nav-muted);
  margin: 0 0 8px 6px;
}

.logout-btn {
  width: 100%;
  min-height: 38px;
  background: transparent;
  border: 1px solid #3c4d69;
  color: var(--nav-fg);
  border-radius: 7px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.app-main {
  padding: 24px 28px 48px;
  max-width: 1380px;
  width: 100%;
}

.login-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

/* Typography & Sections */
h1 {
  font-size: 21px;
  line-height: 1.3;
  margin: 0 0 12px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
  margin: 26px 0 10px;
  font-weight: 600;
}

h3 {
  font-size: 14px;
  margin: 18px 0 8px;
  font-weight: 600;
}

p {
  margin: 0 0 12px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
}

.pre-card {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
}

/* Status & Alerts */
.ok {
  color: var(--ok);
  font-weight: 600;
}

.bad {
  color: var(--bad);
  font-weight: 600;
}

.warn {
  color: var(--warn);
  font-weight: 600;
}

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

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

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.pill.ok {
  background: var(--ok-bg);
  border-color: #b7dfc2;
}

.pill.bad {
  background: var(--bad-bg);
  border-color: #f4c2be;
}

.pill.warn {
  background: var(--warn-bg);
  border-color: #f3d89b;
}

.flash {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  padding: 11px 15px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.flash.error,
.error {
  background: var(--bad-bg);
  border-color: #f5c2bd;
  color: #7a1c14;
}

/* KPI Strip */
.kpi-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-chip {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Responsive Tables */
.table-wrapper {
  overflow-x: auto;
  max-width: 100%;
  border-radius: 8px;
  container-type: inline-size;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: nowrap;
}

thead th,
tr > th {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line-strong);
}

tbody tr:hover {
  background: #f8fbff;
}

td.wrap {
  white-space: normal;
  word-break: break-word;
  min-width: 200px;
  max-width: 460px;
}

/* Grids */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.grid div span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
}

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

/* Forms */
search {
  display: block;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
}

legend {
  padding: 0 6px;
  font-weight: 600;
  font-size: 13px;
  color: var(--fg);
}

label {
  display: block;
  margin: 10px 0 4px;
  font-weight: 500;
  color: var(--fg);
  font-size: 13px;
}

label.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 14px 6px 0;
  font-weight: 400;
  color: var(--fg);
  cursor: pointer;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 4px 12px;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px 2px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  max-width: 540px;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font: inherit;
  font-size: max(1rem, 1em);
  color: var(--fg);
  background: #fff;
}

input:user-invalid,
select:user-invalid,
textarea:user-invalid {
  border-color: var(--bad);
  background: #fffafa;
}

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

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filter-field {
  flex: 1 1 200px;
  min-width: 180px;
}

.filter-field input,
.filter-field select {
  max-width: none;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  max-width: 760px;
}

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

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.inline-form {
  display: inline-block;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-top: 12px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn.secondary {
  background: #eef2f7;
  border-color: var(--line-strong);
  color: var(--fg);
}

.btn.secondary:hover {
  background: #e2e8f0;
}

.btn:disabled,
.btn.secondary:disabled,
.btn:disabled:hover,
.btn.secondary:disabled:hover {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f1f5f9;
  color: var(--muted);
}

.btn.small {
  min-height: 32px;
  margin: 0;
  padding: 4px 10px;
  font-size: 12.5px;
}

.filter-bar .btn,
.action-row .btn {
  margin-top: 0;
}

code {
  background: #eef2f6;
  padding: 2px 6px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* Responsive Mobile Layout */
@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    padding: 14px 16px;
    gap: 12px;
  }

  .nav-sections {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px 18px;
  }

  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .nav-list a {
    min-height: 44px;
    padding: 8px 12px;
  }

  .app-main {
    padding: 16px 14px 36px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="file"],
  select,
  .btn {
    min-height: 44px;
  }
}

/* Store Wi-Fi Panel & Container-Responsive Tables */
.wifi-panel-grid {
  margin-top: 14px;
  margin-bottom: 14px;
}

.wifi-panel-grid h3 {
  margin-top: 0;
  font-size: 15px;
}

.radio-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0;
}

.radio-item input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.radio-item label {
  margin: 0;
  font-weight: 400;
  cursor: pointer;
}

.wifi-scan-table {
  --label-2: "信号与信道";
  --label-3: "加密方式";
  --label-4: "操作";
}

.wifi-profiles-table {
  --label-2: "连接状态";
  --label-3: "路由优先级";
  --label-4: "操作";
}

@container (width < 600px) {
  .wifi-scan-table,
  .wifi-scan-table thead,
  .wifi-scan-table tbody,
  .wifi-scan-table tr,
  .wifi-scan-table th,
  .wifi-scan-table td,
  .wifi-profiles-table,
  .wifi-profiles-table thead,
  .wifi-profiles-table tbody,
  .wifi-profiles-table tr,
  .wifi-profiles-table th,
  .wifi-profiles-table td {
    display: block;
    white-space: normal;
  }

  .wifi-scan-table thead,
  .wifi-profiles-table thead {
    display: none;
  }

  .wifi-scan-table tr,
  .wifi-profiles-table tr {
    margin-block-end: 12px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .wifi-scan-table tbody th,
  .wifi-profiles-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
  }

  .wifi-scan-table td,
  .wifi-profiles-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border: 0;
    padding: 4px 2px;
  }

  .wifi-scan-table td:nth-child(2)::before,
  .wifi-profiles-table td:nth-child(2)::before {
    content: var(--label-2) ": ";
    font-weight: 600;
    color: var(--muted);
  }

  .wifi-scan-table td:nth-child(3)::before,
  .wifi-profiles-table td:nth-child(3)::before {
    content: var(--label-3) ": ";
    font-weight: 600;
    color: var(--muted);
  }

  .wifi-scan-table td:nth-child(4)::before,
  .wifi-profiles-table td:nth-child(4)::before {
    content: var(--label-4) ": ";
    font-weight: 600;
    color: var(--muted);
  }
}

.radio-inline-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.radio-inline-group .radio-item {
  margin: 2px 0;
}

.compact-fieldset {
  margin: 0 0 8px;
  padding: 6px 10px;
}

.task-reconcile-form {
  min-width: 260px;
  white-space: normal;
}

.cmd-hints {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.cmd-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}

.cmd-copy label {
  font-size: 12px;
  color: var(--muted);
}

.cmd-copy input[readonly] {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.sidebar-account-link {
  display: block;
  width: 100%;
  text-align: center;
  min-height: 36px;
  line-height: 22px;
  margin-bottom: 8px;
  border: 1px solid #3c4d69;
  color: var(--nav-fg);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  text-decoration: none;
}

.sidebar-account-link:hover,
.sidebar-account-link[aria-current="page"] {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

input[type="date"] {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--fg);
  min-height: 36px;
}
