:root {
  --primary: #3370ff;
  --primary-dark: #245bdb;
  --primary-light: #e8f0ff;
  --primary-soft: #f3f7ff;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #646a73;
  --subtle: #8f959e;
  --line: #dee0e3;
  --line-soft: #eff0f1;
  --danger: #f54a45;
  --danger-soft: #fff0f0;
  --success: #00b578;
  --success-soft: #e9f8f3;
  --warning: #ff8800;
  --shadow-sm: 0 6px 18px rgba(31, 35, 41, .04);
  --shadow-md: 0 12px 32px rgba(31, 35, 41, .08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 14% -10%, rgba(51, 112, 255, .12), transparent 30%),
    radial-gradient(circle at 88% 2%, rgba(20, 184, 166, .09), transparent 28%),
    var(--bg);
  color: var(--text);
}

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

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  padding: 10px 18px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(31, 35, 41, .9);
  box-shadow: var(--shadow-md);
  transition: .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 24px;
  background:
    radial-gradient(circle at 18% 12%, rgba(51, 112, 255, .14), transparent 28%),
    linear-gradient(180deg, #eef4ff 0%, #f7f9fc 100%);
}

.login-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 36px;
  align-items: center;
}

.login-brand {
  display: flex;
  gap: 18px;
  align-items: center;
}

.brand-mark {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  color: #ffffff;
  background: linear-gradient(135deg, #3370ff, #6aa1ff);
  font-weight: 900;
  letter-spacing: .04em;
  box-shadow: 0 18px 36px rgba(51, 112, 255, .26);
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(51, 112, 255, .2);
}

.login-brand p,
.topbar p {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.login-brand h1 {
  margin: 0 0 10px;
  color: #111827;
  font-size: 46px;
  line-height: 1.08;
  font-weight: 900;
}

.login-brand span,
.card-head span,
.api-status,
.user-pill,
.metric-card span,
.tips-card p {
  color: var(--muted);
}

.login-card,
.panel-card,
.metric-card {
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(222, 224, 227, .9);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}

.login-card {
  padding: 28px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.card-head strong {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  background: #ffffff;
  font-size: 14px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #c9cdd4;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(51, 112, 255, .14);
}

textarea {
  resize: vertical;
  min-height: 112px;
  line-height: 1.65;
}

.primary-btn,
.outline-btn,
.danger-btn,
.logout-btn,
.nav-link {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.primary-btn,
.outline-btn,
.danger-btn {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 8px;
}

.primary-btn {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(51, 112, 255, .18);
}

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

.outline-btn {
  color: var(--primary);
  background: #ffffff;
  border: 1px solid rgba(51, 112, 255, .26);
}

.outline-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.danger-btn {
  color: var(--danger);
  background: #ffffff;
  border: 1px solid rgba(245, 74, 69, .24);
}

.danger-btn:hover {
  background: var(--danger-soft);
}

.api-status {
  margin: 14px 0 0;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  color: var(--text);
  background: rgba(255, 255, 255, .94);
  border-right: 1px solid var(--line-soft);
  box-shadow: 6px 0 24px rgba(31, 35, 41, .03);
  backdrop-filter: blur(14px);
}

.side-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 22px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.side-brand strong,
.side-brand span {
  display: block;
}

.side-brand strong {
  font-size: 16px;
  font-weight: 900;
}

.side-brand span {
  margin-top: 4px;
  color: var(--subtle);
  font-size: 12px;
}

.sidebar nav {
  padding-top: 10px;
}

.nav-link,
.logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  min-height: 40px;
  margin-bottom: 6px;
  padding: 0 12px;
  border-radius: 10px;
  text-align: left;
  color: var(--muted);
  background: transparent;
}

.nav-link:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
}

.logout-btn {
  position: absolute;
  left: 14px;
  bottom: 18px;
  width: calc(100% - 28px);
  color: var(--danger);
}

.logout-btn:hover {
  background: var(--danger-soft);
}

.main-view {
  min-width: 0;
  padding: 22px 26px 34px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin: -22px -26px 22px;
  padding: 18px 26px;
  background: rgba(245, 247, 251, .88);
  border-bottom: 1px solid rgba(222, 224, 227, .72);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  font-weight: 900;
}

.top-actions,
.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.user-pill {
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #ffffff;
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.metric-card::after {
  content: "";
  position: absolute;
  right: -28px;
  top: -28px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: rgba(51, 112, 255, .08);
}

.metric-card strong {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 10px;
  color: var(--text);
  font-size: 32px;
  line-height: 1.1;
  font-weight: 900;
}

.metric-card .small-text {
  font-size: 17px;
  word-break: break-all;
}

.panel-card {
  padding: 20px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
}

.log-filters {
  margin-bottom: 14px;
}

.log-filters input,
.log-filters select {
  width: auto;
  min-width: 190px;
  margin-bottom: 0;
}

.table-muted {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #ffffff;
}

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

th {
  color: var(--muted);
  background: #f7f8fa;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
}

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

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover td {
  background: #f8fbff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.enabled {
  color: var(--success);
  background: var(--success-soft);
}

.status-pill.disabled {
  color: var(--danger);
  background: var(--danger-soft);
}

.inline-btn {
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--primary);
  background: var(--primary-light);
  cursor: pointer;
  font-weight: 800;
}

.inline-btn:hover {
  background: #dbe8ff;
}

.qr-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  align-items: stretch;
}

.qr-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.qr-preview canvas {
  width: 260px;
  height: 260px;
  border-radius: 14px;
  border: 1px solid var(--line-soft);
  background: #ffffff;
}

.qr-preview span {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.tenant-list {
  display: grid;
  gap: 10px;
}

.tenant-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #ffffff;
}

.tenant-item:hover {
  border-color: rgba(51, 112, 255, .3);
  background: #f8fbff;
}

.tenant-item strong,
.tenant-item span {
  display: block;
}

.tenant-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tips-card {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.tips-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
}

.tips-card p {
  margin: 6px 0 0;
  line-height: 1.7;
}

@media (max-width: 980px) {
  .login-panel,
  .app-shell,
  .metric-grid,
  .form-grid,
  .qr-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .logout-btn {
    position: static;
    width: 100%;
  }

  .topbar {
    position: static;
    margin: -22px -26px 22px;
  }
}

@media (max-width: 640px) {
  .login-panel {
    gap: 22px;
  }

  .login-brand {
    align-items: flex-start;
  }

  .login-brand h1 {
    font-size: 32px;
  }

  .main-view {
    padding: 18px;
  }

  .topbar {
    margin: -18px -18px 18px;
    padding: 16px 18px;
    align-items: flex-start;
    flex-direction: column;
  }
}
