:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #d9e2ef;
  --blue: #1769e0;
  --green: #168a54;
  --red: #c2413a;
  --amber: #bd7a19;
  --shadow: 0 12px 30px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, textarea {
  font: inherit;
}
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
}
button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
button.ghost {
  background: #fff;
}
button.danger {
  border-color: #f1c1bd;
  background: #fff5f4;
  color: var(--red);
}
button.small {
  min-height: 30px;
  padding: 0 10px;
}
button:disabled {
  opacity: .55;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}
label span {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}
.shell {
  min-height: 100vh;
}
.login-panel {
  width: min(420px, calc(100vw - 28px));
  margin: 9vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0;
}
.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.brand.compact h1 {
  font-size: 18px;
}
.mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #132238;
  color: #fff;
  font-weight: 700;
}
.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}
.error-line {
  min-height: 22px;
  color: var(--red);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(14px, 3vw, 26px);
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px clamp(14px, 3vw, 26px) 0;
}
.stats-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}
.stats-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px clamp(14px, 3vw, 26px);
}
.workspace {
  display: grid;
  grid-template-columns: minmax(300px, .92fr) minmax(420px, 1.4fr);
  gap: 14px;
  padding: 0 clamp(14px, 3vw, 26px) 28px;
}
.list-pane,
.detail-pane {
  min-width: 0;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.section-head h2 {
  margin: 0;
  font-size: 16px;
}
.section-head span {
  color: var(--muted);
}
.grant-list {
  display: grid;
  gap: 8px;
}
.grant-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-height: 78px;
  padding: 12px;
}
.grant-row.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(23,105,224,.12);
}
.grant-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 650;
}
.grant-sub {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  background: #fff;
}
.pill.open {
  border-color: #a9dec2;
  color: var(--green);
  background: #f0fbf5;
}
.pill.closed {
  border-color: #efd59c;
  color: var(--amber);
  background: #fff9eb;
}
.pill.revoked {
  border-color: #efb6b2;
  color: var(--red);
  background: #fff5f4;
}
.empty-state,
.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-height: 240px;
}
.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
}
.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.detail h2 {
  margin: 0;
  font-size: 20px;
}
.detail p {
  margin: 5px 0 0;
  color: var(--muted);
  word-break: break-all;
}
.meter {
  height: 8px;
  border-radius: 999px;
  background: #edf1f7;
  overflow: hidden;
  margin: 16px 0;
}
.meter div {
  height: 100%;
  width: 0%;
  background: var(--blue);
}
.kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}
.kv div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.kv dt {
  color: var(--muted);
  font-size: 12px;
}
.kv dd {
  margin: 5px 0 0;
  word-break: break-word;
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}
.audit-list {
  display: grid;
  gap: 8px;
}
.audit-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcff;
}
.audit-item strong {
  display: block;
}
.audit-item span {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-size: 13px;
  word-break: break-all;
}
dialog {
  width: min(520px, calc(100vw - 22px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgba(15,23,42,.36);
}
.dialog-form {
  display: grid;
  gap: 13px;
}
.dialog-form h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check input {
  width: auto;
}
.check span {
  margin: 0;
  color: var(--ink);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
#tokenText {
  min-height: 120px;
  font-family: Consolas, monospace;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}
[hidden] { display: none !important; }

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .detail-pane {
    order: -1;
  }
}

@media (max-width: 560px) {
  .login-panel {
    margin-top: 0;
    min-height: 100vh;
    width: 100vw;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding: max(22px, env(safe-area-inset-top)) 18px 18px;
  }
  .topbar {
    align-items: flex-start;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .actions {
    justify-content: stretch;
  }
  .actions button,
  .detail-actions button {
    flex: 1;
  }
  .kv {
    grid-template-columns: 1fr;
  }
  .two {
    grid-template-columns: 1fr;
  }
  .detail {
    padding: 14px;
  }
}
