:root {
  --canvas: #eef2f0;
  --panel: #fbfcfb;
  --panel-strong: #ffffff;
  --ink: #17211f;
  --muted: #66736f;
  --line: #c8d3cf;
  --line-strong: #9eada8;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --notice: #a85f00;
  --danger: #b42318;
  --info: #2563eb;
  --focus: #1d4ed8;
  --radius: 6px;
  --font-ui: "Bahnschrift", "Microsoft YaHei UI", "Segoe UI", sans-serif;
  --font-data: "Cascadia Code", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p,
dl {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 650;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
  font-weight: 650;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--canvas);
}

.login-panel {
  width: min(100%, 520px);
  border-left: 6px solid var(--accent);
  padding: 36px 40px;
  background: var(--panel-strong);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.login-mark,
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--accent);
  font-family: var(--font-data);
  font-size: 13px;
  font-weight: 700;
}

.login-panel h1 {
  margin-top: 22px;
  font-size: 30px;
}

.login-panel > p {
  margin-top: 8px;
  color: var(--muted);
}

.stack {
  margin-top: 28px;
}

.stack label,
.form-grid label,
.inline-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--ink);
  background: var(--panel-strong);
}

input::placeholder {
  color: #87928f;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.primary,
.quiet,
.danger,
.text-button {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 8px 13px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.quiet {
  color: var(--ink);
  background: var(--panel-strong);
  border-color: var(--line-strong);
}

.quiet:hover {
  border-color: var(--ink);
}

.danger {
  color: var(--danger);
  background: transparent;
  border-color: #e0aaa6;
}

.danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.text-button {
  min-height: 32px;
  padding: 4px 7px;
  color: var(--accent-dark);
  background: transparent;
}

.text-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.form-error {
  min-height: 22px;
  margin-top: 10px;
  color: var(--danger);
}

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

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #e5ebe8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

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

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 18px 12px;
}

.nav-list button {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 600;
}

.nav-list button:hover {
  color: var(--ink);
  background: #dbe3df;
}

.nav-list button.active {
  color: #ffffff;
  background: var(--accent);
}

.rail-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 16px 18px 20px;
  border-top: 1px solid var(--line);
}

.service-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--notice);
}

.service-status.healthy .status-dot {
  background: var(--accent);
}

.service-status.unhealthy .status-dot {
  background: var(--danger);
}

.workspace {
  min-width: 0;
  padding: 26px 28px 48px;
}

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

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.view-panel {
  display: grid;
  gap: 18px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.metric {
  min-height: 112px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

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

.metric-value {
  display: block;
  margin-top: 12px;
  font-family: var(--font-data);
  font-size: 28px;
  line-height: 1;
  font-weight: 700;
}

.metric-note {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.users-layout,
.billing-layout {
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
}

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

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  padding: 18px;
}

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

.panel-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.count-label {
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

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

tbody tr:hover {
  background: #f3f6f4;
}

.mono {
  font-family: var(--font-data);
}

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

.nowrap {
  white-space: nowrap;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.table-actions button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.empty-state {
  padding: 26px 8px;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 650;
}

.badge.green {
  color: #075e54;
  border-color: #8fc3b9;
  background: #e5f3ef;
}

.badge.yellow {
  color: #7c4600;
  border-color: #e2bf84;
  background: #fff5df;
}

.badge.red {
  color: #8e1c14;
  border-color: #e5a9a4;
  background: #fdeceb;
}

.badge.neutral {
  color: var(--muted);
  background: #f1f4f2;
}

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

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  font-family: var(--font-data);
}

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

.adjustment-form {
  grid-template-columns: auto minmax(160px, 1fr) auto 110px auto;
  margin-top: 16px;
}

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

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

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.key-reveal {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #8fc3b9;
  border-left: 5px solid var(--accent);
  background: #edf7f4;
}

.key-reveal p {
  margin-bottom: 8px;
  color: var(--muted);
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.key-row code {
  overflow-wrap: anywhere;
  padding: 9px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-family: var(--font-data);
  font-size: 12px;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 40px));
}

.toast {
  padding: 12px 14px;
  border-left: 4px solid var(--info);
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
}

.toast.success {
  border-left-color: #5ed0bd;
}

.toast.error {
  border-left-color: #ff8d84;
}

@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 160ms ease-out;
  }

  @keyframes toast-in {
    from {
      transform: translateY(8px);
      opacity: 0;
    }
  }
}

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

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .split-layout,
  .usage-layout,
  .users-layout,
  .billing-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    height: auto;
    width: 100%;
  }

  .nav-list {
    width: 100%;
    grid-template-columns: repeat(5, minmax(96px, 1fr));
    overflow-x: auto;
    padding-top: 10px;
  }

  .nav-list button {
    text-align: center;
    padding-inline: 8px;
    white-space: nowrap;
  }

  .rail-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .workspace {
    padding: 20px 14px 36px;
    min-width: 0;
    width: 100%;
  }

  .metric-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

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

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

  .input-action {
    grid-template-columns: 1fr;
  }

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