:root {
  color-scheme: light;
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dce4e6;
  --line-strong: #c6d2d5;
  --text: #172126;
  --muted: #66757b;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #e7f4f1;
  --danger: #b42318;
  --danger-soft: #fef0ee;
  --warning: #9a6700;
  --warning-soft: #fff6db;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(23, 33, 38, .09);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(390px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow); }
.login-panel h1 { margin: 8px 0 6px; font-size: 25px; }
.login-panel label { display: block; margin: 17px 0 6px; color: #4d5c62; font-size: 13px; }
.download-app-link { display: block; margin-top: 15px; color: var(--accent); text-align: center; font-size: 13px; font-weight: 700; text-decoration: none; }

.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.muted { color: var(--muted); }
h1, h2, h3, p { margin-top: 0; }

input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  padding: 0 11px;
  outline: none;
  color: var(--text);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
input:disabled { background: #eef2f3; color: #7b888d; }

.primary, .secondary {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 650;
  border: 1px solid transparent;
}
.primary { color: #fff; background: var(--accent); }
.primary:hover { background: var(--accent-dark); }
.secondary { color: #344348; background: #fff; border-color: var(--line-strong); }
.secondary:hover { background: var(--surface-soft); }
.wide { width: 100%; margin-top: 22px; }
.danger { color: var(--danger) !important; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 68px;
  padding: 0 max(20px, calc((100vw - 1240px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 7px; background: var(--accent); color: #fff; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-label { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #425158; font-size: 13px; padding: 0 4px; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #425158;
  padding: 0;
}
.icon-button:hover { background: var(--surface-soft); border-color: var(--line-strong); }
.icon-button svg, .icon-text-button svg { width: 17px; height: 17px; stroke-width: 1.9; }
.icon-text-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; white-space: nowrap; }
.text-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #344348;
  padding: 0 12px;
  font-weight: 650;
}
.text-button svg { width: 17px; height: 17px; flex: 0 0 auto; stroke-width: 1.9; }

main { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 70px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.section-heading h1 { margin: 6px 0 0; font-size: 27px; letter-spacing: -.01em; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.feature-card {
  min-height: 172px;
  text-align: left;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  color: var(--text);
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.feature-card:hover:not(:disabled) { border-color: #99bdb8; transform: translateY(-2px); box-shadow: 0 12px 30px rgba(23,33,38,.08); }
.feature-card:disabled { cursor: not-allowed; opacity: .72; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.feature-icon { width: 44px; height: 44px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 7px; }
.feature-icon svg { width: 23px; height: 23px; }
.feature-card h2 { margin: 17px 0 7px; font-size: 17px; }
.feature-card p { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; padding-top: 17px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #6a777c; font-size: 12px; }
.card-foot svg { width: 16px; height: 16px; display: block; }
.address { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #98a4a8; }
.status.online .status-dot { background: #16824a; box-shadow: 0 0 0 4px rgba(22,130,74,.1); }
.status.offline .status-dot { background: #b42318; }
.empty-state { padding: 48px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

.tabbar { display: inline-flex; gap: 4px; background: #e7ecee; border-radius: 7px; padding: 4px; margin-bottom: 16px; }
.tab { border: 0; background: transparent; border-radius: 5px; min-height: 34px; padding: 0 16px; color: #536167; font-weight: 650; }
.tab.active { color: var(--text); background: #fff; box-shadow: 0 1px 4px rgba(23,33,38,.08); }
.admin-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-toolbar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-toolbar h2 { margin: 0 0 4px; font-size: 17px; }
.panel-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid #e8edef; font-size: 13px; vertical-align: middle; }
th { color: #66757b; font-size: 12px; font-weight: 700; background: #fafcfc; }
tbody tr:last-child td { border-bottom: 0; }
td strong { display: block; font-size: 13px; margin-bottom: 3px; }
td small { color: var(--muted); }
.align-right { text-align: right; }
.row-actions { display: inline-flex; gap: 7px; }
.row-actions button { min-height: 32px; padding: 0 10px; font-size: 12px; }
.badge { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 0 9px; font-size: 11px; font-weight: 750; }
.badge.yes { background: var(--accent-soft); color: var(--accent-dark); }
.badge.no { background: #eef2f3; color: #66757b; }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.error { background: var(--danger-soft); color: var(--danger); }

dialog {
  width: min(690px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 31, 35, .42); backdrop-filter: blur(2px); }
dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.dialog-heading h2 { margin: 5px 0 0; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-grid label:not(.check) { display: grid; gap: 6px; color: #4d5c62; font-size: 12px; font-weight: 650; }
.span-2 { grid-column: span 2; }
.check-row { display: flex; flex-wrap: wrap; align-items: center; gap: 17px; min-height: 42px; }
.check { display: inline-flex; align-items: center; gap: 7px; color: #425158; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.dialog-actions { display: flex; align-items: center; gap: 9px; margin-top: 23px; padding-top: 18px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.form-error { min-height: 18px; margin-top: 12px; color: var(--danger); font-size: 12px; }
.auth-list { display: grid; gap: 9px; max-height: 52vh; overflow: auto; }
.auth-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-radius: 7px; padding: 12px 13px; }
.auth-main { display: flex; align-items: center; gap: 10px; }
.auth-main strong { display: block; font-size: 13px; }
.auth-main small { color: var(--muted); font-size: 11px; }
.auth-expiry { width: 210px; height: 36px; }
.batch-form { padding: 22px; border-top: 1px solid var(--line); }
.batch-form h3 { margin: 0 0 16px; font-size: 17px; }
.batch-form h4 { margin: 0 0 8px; color: #4d5c62; font-size: 12px; }
.batch-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.batch-columns:has(> :nth-child(2):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.toast { position: fixed; left: 50%; right: auto; bottom: 24px; z-index: 100; max-width: min(440px, calc(100vw - 40px)); padding: 11px 18px; border: 1px solid rgba(15,118,110,.2); border-radius: 999px; background: rgba(255,255,255,.88); color: #344348; box-shadow: 0 10px 30px rgba(23,33,38,.13); backdrop-filter: blur(10px); font-size: 13px; text-align: center; transform: translateX(-50%); }
.toast.error { border-color: rgba(180,35,24,.2); background: rgba(254,240,238,.92); color: #8f1d14; }

@media (max-width: 940px) {
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .topbar { height: auto; min-height: 64px; padding: 12px 16px; align-items: center; }
  .brand small, .user-label { display: none; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  main { width: calc(100% - 28px); padding-top: 28px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading h1 { font-size: 23px; }
  .feature-grid { grid-template-columns: 1fr; }
  .feature-card { min-height: 158px; }
  .batch-columns { grid-template-columns: 1fr; }
  .tabbar { display: flex; width: 100%; }
  .tab { flex: 1; padding: 0 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .auth-row { align-items: flex-start; flex-direction: column; }
  .auth-expiry { width: 100%; }
  .panel-toolbar { align-items: flex-start; flex-direction: column; }
  .panel-toolbar > button { width: 100%; }
  dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
  dialog form { padding: 18px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .spacer { display: none; }
  .dialog-actions button { flex: 1; min-width: 96px; }
  .auth-list { max-height: none; }
  th, td { padding: 12px; }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 14px; }
  .brand { gap: 8px; }
  .brand-mark { width: 34px; height: 34px; }
  .top-actions { gap: 5px; }
  .text-button { padding: 0 9px; }
  .section-heading h1 { font-size: 22px; }
  .feature-card { padding: 18px; }
  .empty-state { padding: 34px 18px; }
  .toast {
    left: 50%;
    right: auto;
    bottom: calc(24px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 40px);
  }
}
