:root {
  color-scheme: light;
  --ink: #1b1f23;
  --muted: #65717d;
  --line: #d9e1e7;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --accent: #126c66;
  --accent-dark: #0b4b46;
  --warn: #b42318;
  --gold: #b38b2e;
  --shadow: 0 24px 80px rgba(27, 31, 35, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(18, 108, 102, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(18, 108, 102, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(960px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-items: center;
  padding: 32px 0;
}

.panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: clamp(24px, 5vw, 48px);
}

.hidden {
  display: none !important;
}

.masthead {
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(32px, 6vw, 56px);
  line-height: 1.05;
  font-weight: 800;
}

h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

h3 {
  margin-bottom: 12px;
  font-size: 17px;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 0;
}

.login-form label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 13px 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 108, 102, 0.16);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 12px 18px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

button.secondary {
  color: var(--accent-dark);
  background: rgba(18, 108, 102, 0.1);
}

button.ghost {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.error {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--warn);
  font-weight: 700;
}

.dashboard-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 24px;
  margin-bottom: 24px;
}

.dashboard-header h1 {
  font-size: clamp(28px, 4vw, 42px);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-line {
  min-height: 24px;
  margin-bottom: 20px;
  color: var(--muted);
  font-weight: 700;
}

.metric {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  margin-bottom: 24px;
}

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

.metric strong {
  font-size: clamp(40px, 10vw, 72px);
  line-height: 0.9;
  color: var(--accent-dark);
}

.latest {
  padding-top: 4px;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

dl div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  min-width: 0;
  background: #fff;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

dd {
  margin: 0;
  min-height: 24px;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.global-error {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  padding: 14px 16px;
  border-radius: 6px;
  color: #fff;
  background: var(--warn);
  box-shadow: 0 16px 48px rgba(180, 35, 24, 0.28);
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: clamp(12px, 3vw, 32px);
  background: rgba(11, 24, 29, 0.58);
}

.api-modal {
  width: min(1120px, 100%);
  max-height: min(860px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(217, 225, 231, 0.92);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 32px 100px rgba(11, 24, 29, 0.32);
}

.api-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(20px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.api-modal-header h2 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

.close-button {
  flex: 0 0 auto;
}

.api-modal-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  align-items: center;
}

.api-modal-body {
  overflow: auto;
  padding: clamp(20px, 3vw, 32px);
}

.help-block {
  padding: 0 0 24px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--line);
}

.help-block:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.help-block p,
.help-block li {
  color: var(--ink);
  line-height: 1.7;
}

.help-block ul {
  margin: 0;
  padding-left: 22px;
}

.help-block code {
  border: 1px solid rgba(18, 108, 102, 0.18);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--accent-dark);
  background: rgba(18, 108, 102, 0.08);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 0.94em;
}

.help-block pre {
  margin: 12px 0 14px;
  overflow: auto;
  border: 1px solid #cfd9df;
  border-radius: 8px;
  padding: 16px;
  background: #101817;
}

.help-block pre code {
  display: block;
  min-width: max-content;
  border: 0;
  padding: 0;
  color: #edf7f2;
  background: transparent;
  font-size: 14px;
  line-height: 1.65;
}

.endpoint-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.endpoint-line strong {
  border-radius: 4px;
  padding: 5px 8px;
  color: #fff;
  background: var(--accent);
  font-size: 12px;
  letter-spacing: 0;
}

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

.error-codes dt {
  color: var(--accent-dark);
}

@media (max-width: 640px) {
  .password-row,
  .dashboard-header,
  .metric,
  dl {
    grid-template-columns: 1fr;
  }

  .dashboard-header {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button,
  .password-row button {
    width: 100%;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 0;
  }

  .api-modal {
    max-height: 100vh;
    border-radius: 0;
  }

  .api-modal-header {
    display: grid;
  }

  .close-button {
    width: 100%;
  }

  .api-modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .error-codes {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    min-height: auto;
    background: #fff;
  }

  body > :not(#apiHelpModal) {
    display: none !important;
  }

  #apiHelpModal,
  #apiHelpModal.hidden {
    position: static !important;
    display: block !important;
    padding: 0 !important;
    background: #fff !important;
  }

  .api-modal {
    width: 100% !important;
    max-height: none !important;
    display: block !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .api-modal-header {
    padding: 0 0 12mm !important;
    border-bottom: 1px solid #ccd6dc !important;
    background: #fff !important;
  }

  .api-modal-actions {
    display: none !important;
  }

  .api-modal-body {
    overflow: visible !important;
    padding: 10mm 0 0 !important;
  }

  .help-block {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .help-block pre {
    white-space: pre-wrap;
    overflow: visible;
    border-color: #ccd6dc;
    background: #101817 !important;
  }

  .help-block pre code {
    min-width: 0;
    color: #edf7f2 !important;
  }

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