:root {
  color: #172033;
  background: #f4f6f8;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  font-synthesis: none;
  letter-spacing: 0;
  --border: #d9dee7;
  --border-strong: #b8c0cf;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --text: #172033;
  --muted: #667085;
  --primary: #1769e0;
  --primary-hover: #0e56bd;
  --danger: #c73535;
  --danger-hover: #a92727;
  --success: #18794e;
  --warning: #96620a;
  --focus: #f0a51b;
  --shadow: 0 16px 36px rgba(20, 30, 48, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: #f4f6f8;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.public-page,
.login-page {
  background: #eef1f5;
}

.public-page {
  background: #fff;
}

.public-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

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

.login-panel,
.message-panel {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.message-panel {
  text-align: center;
}

.product-mark {
  display: grid;
  width: 44px;
  height: 44px;
  margin-bottom: 22px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: #172033;
  font-size: 14px;
  font-weight: 800;
}

.login-panel h1,
.message-panel h1 {
  margin: 0 0 26px;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0;
}

.message-panel h1 {
  margin-bottom: 12px;
}

.message-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

.message-code {
  margin-bottom: 8px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.stack-form {
  display: grid;
  gap: 20px;
}

.public-form-wrap {
  width: min(100%, 384px);
}

.public-status {
  display: grid;
  min-height: 42px;
  align-items: end;
  padding-bottom: 10px;
}

.public-status p {
  margin: 0;
}

.checking-message {
  color: var(--muted);
  font-size: 14px;
}

.public-form {
  display: grid;
  gap: 12px;
}

.public-form input,
.public-form button {
  min-height: 46px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field-group,
.filter-field {
  display: grid;
  gap: 7px;
}

.field-group label,
.filter-field label {
  color: #344054;
  font-size: 14px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:hover,
select:hover {
  border-color: #8993a4;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.13);
  outline: none;
}

input[aria-invalid="true"] {
  border-color: var(--danger);
}

.form-error,
.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-error-summary {
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: #fff3f3;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

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

.button-primary {
  color: #fff;
  background: var(--primary);
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

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

.button-secondary:hover:not(:disabled) {
  border-color: #8993a4;
  background: var(--surface-muted);
}

.button-quiet {
  color: #344054;
  background: transparent;
}

.button-quiet:hover:not(:disabled) {
  color: var(--primary);
  background: #edf4ff;
}

.button-danger {
  color: #fff;
  background: var(--danger);
}

.button-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

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

.button-danger-quiet:hover:not(:disabled) {
  background: #fff0f0;
}

.button-block {
  width: 100%;
}

.button-small {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.admin-page {
  background: #f5f6f8;
}

.admin-header {
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.admin-header__inner {
  display: flex;
  width: min(100% - 40px, 1440px);
  min-height: 58px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
}

.admin-brand {
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  text-decoration: none;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-nav__link {
  padding: 8px 10px;
  color: #344054;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.admin-main {
  width: min(100% - 40px, 1440px);
  margin: 0 auto;
  padding: 30px 0 48px;
}

.admin-main-narrow {
  width: min(100% - 40px, 760px);
}

.page-heading {
  display: flex;
  min-height: 48px;
  margin-bottom: 22px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.page-heading h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.record-count {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.back-link:hover {
  color: var(--primary);
}

.flash-message {
  margin: 0 0 18px;
  padding: 11px 14px;
  border: 1px solid #acd7c3;
  border-left: 4px solid var(--success);
  border-radius: 6px;
  color: #125d3d;
  background: #eefaf4;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 180px auto;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  align-items: end;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.filter-submit {
  min-width: 82px;
}

.data-surface {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

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

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

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid #e8ebf0;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #475467;
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: none;
  white-space: nowrap;
}

tbody tr:hover {
  background: #fafbfc;
}

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

.cell-muted,
.cell-time {
  color: var(--muted);
  white-space: nowrap;
}

.code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0;
}

.origin-link {
  display: inline-block;
  max-width: 270px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.actions-column {
  width: 180px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}

.row-actions form {
  margin: 0;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-active {
  color: #12653f;
  background: #e9f7ef;
}

.status-disabled {
  color: #596273;
  background: #eceff3;
}

.status-expired {
  color: #7b5008;
  background: #fff3d5;
}

.empty-state {
  height: 160px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  min-height: 58px;
  padding: 11px 14px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

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

.edit-form {
  display: grid;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.check-field {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 9px;
  color: #344054;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.check-field input {
  width: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

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

.confirm-dialog {
  width: min(calc(100% - 32px), 420px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(17, 24, 39, 0.55);
}

.confirm-dialog form {
  padding: 24px;
}

.confirm-dialog h2 {
  margin: 0 0 8px;
  font-size: 19px;
  letter-spacing: 0;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
}

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

@media (max-width: 720px) {
  .login-shell {
    align-items: start;
    padding: 28px 16px;
  }

  .login-panel,
  .message-panel {
    margin-top: 8vh;
    padding: 26px 22px;
  }

  .admin-header__inner,
  .admin-main,
  .admin-main-narrow {
    width: min(100% - 24px, 100%);
  }

  .admin-header__inner {
    min-height: 54px;
  }

  .admin-nav__link {
    display: none;
  }

  .admin-main {
    padding-top: 22px;
  }

  .page-heading {
    align-items: flex-start;
  }

  .page-heading h1 {
    font-size: 21px;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .filter-submit {
    width: 100%;
  }

  .edit-form {
    padding: 20px 16px;
  }
}

@media (max-width: 460px) {
  .page-heading {
    display: grid;
  }

  .page-heading > .button {
    width: 100%;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .pagination-actions {
    width: 100%;
  }

  .pagination-actions .button {
    flex: 1;
  }

  .form-actions .button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
