:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --paper: #fffdf8;
  --ink: #1f2924;
  --muted: #68736c;
  --line: #d8d2c5;
  --line-strong: #b9b09e;
  --accent: #1f6b4f;
  --accent-soft: #e2f0e8;
  --danger: #a33a32;
  --danger-soft: #fbe9e6;
  --warn: #8a5a12;
  --warn-soft: #fbf1dd;
  --shadow: 0 16px 40px rgba(31, 41, 36, 0.12);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 10% 0%, rgba(31, 107, 79, 0.08), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.skip-link:focus {
  left: 8px;
}

.app {
  min-height: 100vh;
}

.loading,
.empty {
  margin: 0;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

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

.small {
  font-size: 12px;
}

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #f0ede5;
  font-family: var(--mono);
  font-size: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand--large {
  font-size: 17px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--paper);
  font-family: Georgia, serif;
  font-size: 18px;
}

/* ---------- auth ---------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 20px 0 4px;
  font-size: 24px;
}

.auth-card > .muted {
  margin: 0 0 20px;
}

/* ---------- shell ---------- */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 18px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.identity-name {
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.7);
  overflow-x: auto;
}

.tab {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover {
  background: #f0ede5;
  color: var(--ink);
}

.tab.is-active {
  background: var(--ink);
  color: var(--paper);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.page-head p {
  margin: 6px 0 0;
}

/* ---------- panels/forms ---------- */

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.panel--center {
  max-width: 520px;
  margin: 64px auto;
  text-align: center;
}

.panel--center h1 {
  margin-top: 0;
}

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

.panel-head h2,
.panel > h2 {
  margin: 0;
  font-size: 17px;
}

.panel-foot {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.form--grid > h2,
.field--full,
.form-actions,
.form--grid > button[type="submit"] {
  grid-column: 1 / -1;
}

.form--grid > button[type="submit"] {
  justify-self: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field > legend {
  font-weight: 600;
  color: var(--ink);
}

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

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

.field fieldset,
fieldset.field {
  margin: 0;
  padding: 0;
  border: 0;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 14px 0 0;
}

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

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

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

.button:disabled {
  opacity: 0.55;
  cursor: wait;
}

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

.button--primary:hover {
  background: #18583f;
  border-color: #18583f;
}

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

.button--ghost:hover {
  color: var(--ink);
  background: #f0ede5;
}

.button--small {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.button--danger {
  border-color: #d9aaa4;
  color: var(--danger);
  background: var(--danger-soft);
}

/* ---------- notices/tables ---------- */

.notice {
  margin: 0;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
}

.notice--error {
  border-color: #e3b7b1;
  background: var(--danger-soft);
  color: var(--danger);
}

.notice--ok {
  border-color: #b9d8c7;
  background: var(--accent-soft);
  color: var(--accent);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr.is-revoked td {
  opacity: 0.62;
}

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

.status {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.status--on {
  background: var(--accent-soft);
  color: var(--accent);
}

.status--off {
  background: var(--warn-soft);
  color: var(--warn);
}

.scopes {
  max-width: 260px;
}

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 8px 16px;
  margin: 0;
}

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

.kv dd {
  margin: 0;
  word-break: break-word;
}

@media (max-width: 780px) {
  .shell {
    padding: 16px 12px 40px;
  }

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

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

  .form--grid > h2,
  .field--full,
  .form-actions,
  .form--grid > button[type="submit"] {
    grid-column: auto;
  }

  .page-head h1 {
    font-size: 22px;
  }

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