:root {
  --background: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #111827;
  --muted: #64748b;
  --line: #d9e2ec;
  --primary: #175c62;
  --primary-strong: #0f3f45;
  --accent: #a85512;
  --danger: #b42318;
  --ok: #0f7a4f;
  --warn: #b7791f;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--background);
  color: var(--text);
  font-family: "Noto Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

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

input,
select,
button {
  font: inherit;
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

code {
  border-radius: 5px;
  background: #eef2f6;
  padding: 3px 6px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.app-shell {
  display: grid;
  height: 100vh;
  min-height: 100vh;
  grid-template-columns: 256px minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}

:root[data-sidebar-collapsed="true"] .app-shell {
  grid-template-columns: 84px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  height: 100vh;
  min-height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  padding: 20px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand-copy,
.nav-label,
.operator-name,
.operator-role,
.operator-action {
  transition: opacity 0.14s ease, width 0.14s ease;
}

.brand small,
.muted,
.panel-head p,
.metric small {
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 6px;
  padding: 20px 0;
}

.nav-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-radius: 6px;
  color: #334155;
  font-weight: 650;
  padding: 10px 12px;
}

.nav-item:hover,
.nav-item.active {
  background: #e4f0f0;
  color: var(--primary-strong);
}

.nav-icon {
  width: 24px;
  height: 24px;
  color: #475569;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  color: var(--primary-strong);
}

.sidebar-toggle,
.icon-button {
  display: inline-flex;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #475569;
  cursor: pointer;
}

.sidebar-toggle .nav-icon {
  width: 20px;
  height: 20px;
  transition: transform 0.18s ease;
}

:root[data-sidebar-collapsed="true"] .brand-copy,
:root[data-sidebar-collapsed="true"] .nav-label,
:root[data-sidebar-collapsed="true"] .operator-name,
:root[data-sidebar-collapsed="true"] .operator-role,
:root[data-sidebar-collapsed="true"] .operator-action {
  width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  white-space: nowrap;
}

:root[data-sidebar-collapsed="true"] .sidebar {
  padding-left: 14px;
  padding-right: 14px;
}

:root[data-sidebar-collapsed="true"] .sidebar-head {
  justify-content: center;
}

:root[data-sidebar-collapsed="true"] .brand {
  display: none;
}

:root[data-sidebar-collapsed="true"] .sidebar-toggle .nav-icon {
  transform: rotate(180deg);
}

:root[data-sidebar-collapsed="true"] .nav-item {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 11px 0;
}

:root[data-sidebar-collapsed="true"] .operator {
  place-items: center;
  padding: 10px;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.operator {
  display: grid;
  gap: 8px;
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

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

.workspace {
  height: 100vh;
  min-width: 0;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 20px 24px;
}

.topbar h1,
.panel h2,
.login-panel h1 {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 6px;
}

.breadcrumb a {
  color: var(--primary);
}

.topbar p,
.panel-head p,
.login-panel p {
  margin: 6px 0 0;
}

.content {
  display: grid;
  gap: 20px;
  padding: 20px 24px 32px;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  padding: 0 14px;
}

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

.button.accent {
  border-color: var(--accent);
  background: var(--accent);
}

.button.full {
  width: 100%;
}

.grant-form {
  display: grid;
  width: min(560px, 100%);
  grid-template-columns: minmax(180px, 1fr) 88px auto;
  gap: 10px;
}

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

.metric-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.metric {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  font-size: 26px;
}

.ops-console {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
}

.ops-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button span {
  font-size: 18px;
  line-height: 1;
}

.ops-dashboard-grid {
  display: grid;
  grid-template-columns: 2.2fr repeat(3, minmax(180px, 1fr));
  gap: 16px;
}

.traffic-card,
.ops-status-card,
.server-stat {
  border-radius: 8px;
  background: #f8fafc;
}

.traffic-card {
  display: grid;
  grid-column: span 2;
  grid-row: span 3;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: center;
  gap: 22px;
  min-height: 260px;
  padding: 26px;
}

.health-ring {
  display: grid;
  width: 128px;
  height: 128px;
  place-items: center;
  justify-self: center;
  border: 9px solid #18b981;
  border-radius: 999px;
  color: #059669;
}

.health-ring.health-healthy {
  border-color: #18b981;
  color: #059669;
}

.health-ring.health-good {
  border-color: #3b82f6;
  color: #2563eb;
}

.health-ring.health-warn {
  border-color: #f59e0b;
  color: #b45309;
}

.health-ring.health-danger {
  border-color: #ef4444;
  color: #dc2626;
}

.health-ring strong {
  font-size: 26px;
}

.traffic-main {
  min-width: 0;
}

.traffic-head,
.traffic-values,
.traffic-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.traffic-head span {
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
}

.traffic-head i {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #3b82f6;
  box-shadow: 0 0 0 5px #dbeafe;
  margin-right: 10px;
  vertical-align: -2px;
}

.traffic-tabs {
  display: flex;
  gap: 5px;
}

.traffic-tabs button {
  min-height: 0;
  width: auto;
  border: 0;
  border-radius: 5px;
  background: #e5e7eb;
  color: #475569;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.traffic-tabs button.active {
  background: #3b82f6;
  color: #fff;
}

.traffic-values {
  justify-content: flex-start;
  margin: 28px 0 16px;
}

.traffic-values div {
  min-width: 110px;
}

.traffic-values small,
.traffic-stats {
  color: #94a3b8;
  font-weight: 800;
}

.traffic-values strong {
  font-size: 30px;
  margin-right: 7px;
}

.traffic-stats {
  justify-content: flex-start;
  gap: 42px;
  font-size: 13px;
}

.traffic-stats b {
  color: #0f172a;
}

.sparkline {
  display: block;
  width: 100%;
  height: 64px;
  margin-top: 22px;
}

.sparkline path {
  fill: none;
  stroke: #93c5fd;
  stroke-width: 2.4;
}

.ops-status-card {
  min-height: 126px;
  padding: 18px;
}

.ops-status-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 10px;
}

.ops-status-card header a {
  color: #2563eb;
}

.ops-status-card dl {
  display: grid;
  gap: 7px;
  margin: 0;
}

.ops-status-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.ops-status-card dt,
.ops-status-card p {
  color: #64748b;
}

.ops-status-card dd {
  margin: 0;
  font-weight: 850;
}

.ops-status-card > strong {
  color: #16a34a;
  font-size: 32px;
}

.danger-card > strong {
  color: #dc2626;
}

.card-progress {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  margin: 12px 0;
  overflow: hidden;
}

.card-progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #ef4444;
}

.server-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  border-top: 1px solid #edf1f5;
  margin-top: 18px;
  padding-top: 18px;
}

.server-stat {
  display: grid;
  gap: 7px;
  min-height: 96px;
  padding: 16px;
}

.server-stat span {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.server-stat strong {
  color: #059669;
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-stat small {
  color: #64748b;
  overflow-wrap: anywhere;
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
}

.ops-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.settings-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
}

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

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

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

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

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

.empty {
  color: var(--muted);
  padding: 24px;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #e8eef5;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  min-height: 24px;
  padding: 0 9px;
}

.status-ok {
  background: #e6f5ee;
  color: var(--ok);
}

.status-warn {
  background: #fff3d6;
  color: var(--warn);
}

.status-danger {
  background: #fde8e6;
  color: var(--danger);
}

.detail-panel {
  align-self: start;
}

.detail-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.detail-list div,
.rank-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-list dd {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.compact-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.filter-grid,
.settings-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.redeem-form {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 140px 110px 110px auto;
  gap: 12px;
}

.span-all {
  grid-column: 1 / -1;
}

.generated-codes {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.generated-codes h3 {
  margin: 0 0 12px;
}

.generated-codes div {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.rank-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.rank-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.rank-item span {
  display: grid;
  gap: 4px;
}

.rank-item small {
  color: var(--muted);
  font-family: "Cascadia Mono", Consolas, monospace;
}

.settings-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-form.single-column {
  grid-template-columns: 1fr;
}

.settings-form label {
  display: grid;
  gap: 8px;
  color: #334155;
  font-size: 13px;
  font-weight: 750;
}

.settings-form .check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.check-row input {
  min-height: auto;
  width: 18px;
  height: 18px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.log-filter {
  margin-bottom: 16px;
}

.log-results[aria-busy="true"] {
  opacity: 0.58;
}

.log-table {
  min-width: 1380px;
}

.log-message {
  max-width: 520px;
  white-space: normal;
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.log-path,
.log-id {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.log-id {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-level {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #e8eef5;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
  min-height: 24px;
  padding: 0 9px;
}

.log-info {
  background: #dbeafe;
  color: #1d4ed8;
}

.log-warn {
  background: #fff3d6;
  color: var(--warn);
}

.log-error {
  background: #fde8e6;
  color: var(--danger);
}

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

.login-card {
  width: min(420px, 100%);
}

.login-card .brand {
  border-bottom: 0;
  margin-bottom: 14px;
  padding-bottom: 0;
}

.login-panel {
  display: grid;
  gap: 14px;
}

.login-panel label {
  display: grid;
  gap: 8px;
  font-weight: 750;
}

.alert {
  border-radius: 6px;
  background: #fde8e6;
  color: var(--danger);
  font-weight: 700;
  padding: 10px 12px;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .workspace {
    height: auto;
    overflow: visible;
  }

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

  .operator {
    margin-top: 12px;
  }

  .topbar,
  .two-column,
  .ops-grid,
  .settings-grid,
  .ops-dashboard-grid,
  .server-strip,
  .traffic-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .traffic-card {
    min-height: auto;
  }

  .metric-grid,
  .metric-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .content,
  .topbar,
  .sidebar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .nav,
  .grant-form,
  .metric-grid,
  .metric-grid.compact,
  .compact-list,
  .filter-grid,
  .redeem-form,
  .settings-form,
  .generated-codes div {
    grid-template-columns: 1fr;
  }

  .span-all {
    grid-column: auto;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .traffic-head,
  .traffic-values,
  .traffic-stats {
    align-items: stretch;
    flex-direction: column;
  }
}
