:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #dce1e5;
  --text: #182026;
  --muted: #69757d;
  --brand: #146c5a;
  --brand-dark: #0d5547;
  --blue: #2767c7;
  --danger: #b33b3b;
  --warning: #9b650b;
  --success-bg: #e7f5ef;
  --danger-bg: #faecec;
  --warning-bg: #fff4df;
  font-family: "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,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  padding: 0 16px;
  background: var(--brand);
  color: white;
  cursor: pointer;
}

button:hover {
  background: var(--brand-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

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

button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

button.danger {
  border-color: #e5bcbc;
  background: white;
  color: var(--danger);
}

button.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: var(--line);
  background: white;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

input,
textarea {
  width: 100%;
  border: 1px solid #c9d0d5;
  border-radius: 5px;
  padding: 9px 11px;
  background: white;
  color: var(--text);
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  outline: 2px solid rgb(39 103 199 / 12%);
}

label {
  display: grid;
  gap: 7px;
  color: #3d484f;
  font-size: 14px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf1f3;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
  background: white;
  box-shadow: 0 16px 46px rgb(29 43 50 / 10%);
}

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

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

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: #d4aa2c;
  color: #1f2a2d;
  font-weight: 800;
}

.form-message {
  min-height: 20px;
  color: var(--danger) !important;
  font-size: 13px;
}

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

.app-shell:not([hidden]) {
  display: grid;
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #17231f;
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid rgb(255 255 255 / 9%);
}

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

.brand small {
  margin-top: 3px;
  color: #9aaba4;
}

nav {
  padding: 14px 10px;
}

.nav-item {
  width: 100%;
  border-color: transparent;
  background: #24332e;
  text-align: left;
}

.server-state {
  margin-top: auto;
  padding: 20px;
  color: #a7b8b1;
  font-size: 13px;
}

.server-state i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #42b983;
}

main {
  min-width: 0;
}

header {
  display: flex;
  min-height: 104px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 30px;
  border-bottom: 1px solid var(--line);
  background: white;
}

header h1,
header p,
.table-toolbar h2,
.table-toolbar p {
  margin: 0;
}

header p,
.table-toolbar p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 20px 30px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.metric {
  padding: 18px 20px;
  background: white;
}

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

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 25px;
}

.content {
  margin: 20px 30px 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

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

.table-toolbar input {
  max-width: 280px;
}

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

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

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid #e7eaec;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8f9fa;
  color: #59646b;
  font-size: 12px;
  font-weight: 600;
}

tbody tr:hover {
  background: #fbfcfc;
}

.customer-name strong,
.customer-name small {
  display: block;
}

.customer-name small {
  margin-top: 4px;
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 4px;
  padding: 0 8px;
  background: var(--success-bg);
  color: var(--brand-dark);
  font-size: 12px;
}

.badge.paused {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.expired {
  background: var(--warning-bg);
  color: var(--warning);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.actions-column {
  width: 230px;
  text-align: right;
}

.empty {
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 22px 80px rgb(20 31 37 / 24%);
}

dialog::backdrop {
  background: rgb(13 20 23 / 52%);
}

dialog form {
  display: grid;
  gap: 18px;
}

.dialog-title {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.dialog-title h2,
.dialog-title p {
  margin: 0;
}

.dialog-title p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row small {
  margin-top: 3px;
  color: var(--muted);
}

.toggle-row input {
  width: 20px;
  height: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.key-output {
  margin: 22px 0;
  border: 1px dashed #7aa49a;
  border-radius: 6px;
  padding: 18px;
  background: #f2f8f6;
  color: #153d34;
  font: 700 18px/1.4 Consolas, monospace;
  text-align: center;
  word-break: break-all;
}

.toast-region {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(340px, calc(100vw - 44px));
  border: 1px solid #b6d5ca;
  border-radius: 6px;
  padding: 13px 15px;
  background: white;
  box-shadow: 0 12px 34px rgb(25 37 42 / 16%);
}

.toast.error {
  border-color: #e5bcbc;
}

.toast strong,
.toast span {
  display: block;
}

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

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

  aside {
    position: static;
    height: auto;
  }

  nav,
  .server-state {
    display: none;
  }

  header,
  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
    margin-inline: 16px;
  }

  .content {
    margin-inline: 16px;
  }

  .table-toolbar input {
    max-width: none;
  }
}

@media (max-width: 520px) {
  header {
    padding-inline: 18px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}
