:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f7f9fb;
  --text: #15202b;
  --muted: #66717d;
  --border: #dce2e8;
  --blue: #1769aa;
  --blue-dark: #0d4e82;
  --blue-soft: #e8f2fa;
  --amber: #a45d00;
  --amber-soft: #fff3dc;
  --red: #b42318;
  --red-soft: #fff0ee;
  --green: #16794b;
  --green-soft: #e8f7ef;
  --radius: 10px;
  --shadow: 0 14px 40px rgba(25, 43, 61, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 8px;
  padding: 0 12px; color: var(--text); background: var(--surface);
}
textarea { padding-top: 10px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(23, 105, 170, .2); outline-offset: 2px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.02em; }
h2 { margin-bottom: 0; font-size: 20px; }
.eyebrow, .section-kicker { margin-bottom: 5px; color: var(--blue); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e9eef3; }
.login-card { width: min(100%, 430px); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 38px; box-shadow: var(--shadow); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 22px; border-radius: 10px; background: var(--blue); color: #fff; font-size: 22px; font-weight: 800; }
.login-copy { margin: 14px 0 26px; color: var(--muted); line-height: 1.7; }
.login-form, .stack-form { display: grid; gap: 10px; }
.login-form label, .stack-form label { font-weight: 650; font-size: 14px; }
.stack-form label span { color: var(--muted); font-weight: 400; }
.password-field { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.form-error { min-height: 20px; margin: 0; color: var(--red); font-size: 13px; }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.primary-button, .secondary-button, .danger-button, .text-button { min-height: 40px; border-radius: 8px; padding: 0 15px; font-weight: 650; }
.primary-button { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.primary-button:hover { background: var(--blue-dark); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.danger-button { border: 1px solid var(--red); background: var(--red); color: #fff; }
.text-button { border: 0; background: transparent; color: var(--blue); }
.full-width { width: 100%; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 88px; padding: 18px max(24px, calc((100vw - 1440px) / 2)); border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, .96); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.service-status { display: inline-flex; align-items: center; gap: 7px; color: var(--green); font-size: 13px; font-weight: 650; }
.service-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 24px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.summary-item { min-height: 116px; display: flex; flex-direction: column; justify-content: center; padding: 20px 24px; border-right: 1px solid var(--border); }
.summary-item:last-child { border-right: 0; }
.summary-item span { color: var(--muted); font-size: 13px; }
.summary-item strong { margin-top: 7px; font-size: 32px; letter-spacing: -.03em; }
.summary-item.attention strong { color: var(--amber); }
.content-grid { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; margin-top: 20px; align-items: start; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.issue-panel { padding: 22px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.issue-panel .panel-heading { padding: 0 0 20px; border-bottom: 0; }
.stack-form { gap: 11px; }
.rule-note { margin-top: 22px; padding: 14px; border-left: 3px solid var(--blue); background: var(--blue-soft); color: var(--muted); font-size: 13px; line-height: 1.6; }
.rule-note strong { display: block; color: var(--text); }
.rule-note p { margin: 4px 0 0; }
.records-heading { align-items: flex-end; }
.filters { display: grid; grid-template-columns: minmax(180px, 260px) 150px; gap: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-muted); font-size: 12px; font-weight: 650; }
td { font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
.record-label { display: block; font-weight: 680; }
.record-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-ACTIVE { color: var(--green); background: var(--green-soft); }
.status-UNUSED { color: var(--blue); background: var(--blue-soft); }
.status-REAUTH_REQUIRED { color: var(--amber); background: var(--amber-soft); }
.status-REVOKED { color: var(--red); background: var(--red-soft); }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-action { border: 0; background: transparent; color: var(--blue); font-weight: 650; white-space: nowrap; }
.row-action.danger { color: var(--red); }
.loading-state, .empty-state { padding: 46px 22px; text-align: center; color: var(--muted); }
.empty-state { display: grid; gap: 6px; }
.empty-state strong { color: var(--text); }
.release-panel, .audit-panel { margin-top: 20px; }
.policy-status { color: var(--muted); font-size: 13px; }
.policy-status.ready { color: var(--green); }
.policy-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding: 22px; }
.policy-form > label { display: grid; align-content: start; gap: 7px; font-size: 14px; font-weight: 650; }
.policy-form > label > span { color: var(--muted); font-size: 12px; font-weight: 400; }
.policy-wide { grid-column: 1 / -1; }
.force-toggle { display: grid !important; grid-template-columns: auto 1fr; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-muted); }
.force-toggle input { width: 20px; min-height: 20px; margin: 0; }
.force-toggle span { display: grid; gap: 2px; color: var(--text) !important; }
.force-toggle small { color: var(--muted); font-weight: 400; }
.mono-input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.policy-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.policy-actions p { max-width: 720px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.audit-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 0; padding: 0; list-style: none; }
.audit-list li { min-height: 72px; padding: 14px 22px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.audit-list li:nth-child(3n) { border-right: 0; }
.audit-action { display: block; font-weight: 650; font-size: 13px; }
.audit-time { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.dialog-card { width: min(calc(100% - 32px), 440px); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.dialog-card::backdrop { background: rgba(15, 28, 40, .48); }
.dialog-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: var(--muted); font-size: 28px; }
.dialog-copy { margin: 12px 0 18px; color: var(--muted); line-height: 1.6; }
.activation-code { display: block; margin-bottom: 16px; padding: 18px 10px; border: 1px dashed var(--blue); border-radius: 8px; background: var(--blue-soft); color: var(--blue-dark); font: 700 clamp(20px, 5vw, 28px)/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .04em; text-align: center; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; max-width: min(380px, calc(100% - 44px)); padding: 13px 16px; border-radius: 8px; background: #15202b; color: #fff; box-shadow: var(--shadow); font-size: 14px; }

@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .content-grid { grid-template-columns: 1fr; }
  .policy-form { grid-template-columns: 1fr; }
  .policy-wide { grid-column: auto; }
  .audit-list { grid-template-columns: repeat(2, 1fr); }
  .audit-list li:nth-child(3n) { border-right: 1px solid var(--border); }
  .audit-list li:nth-child(2n) { border-right: 0; }
}

@media (max-width: 640px) {
  .login-card { padding: 28px 22px; }
  .topbar { position: static; align-items: flex-start; padding: 16px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .service-status { width: 100%; justify-content: flex-end; }
  .workspace { padding: 14px; }
  .summary-item { min-height: 92px; padding: 15px; }
  .summary-item strong { font-size: 26px; }
  .panel-heading { padding: 18px 16px; }
  .records-heading { align-items: stretch; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody { padding: 0 16px; }
  tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 16px 0; border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: block; padding: 0; border: 0; }
  td:nth-child(2), td:nth-child(3), td:nth-child(4) { grid-column: 1; }
  td:last-child { grid-column: 2; grid-row: 1 / span 4; }
  .row-actions { flex-direction: column; align-items: flex-end; }
  .policy-form { padding: 16px; }
  .policy-actions { align-items: stretch; flex-direction: column; }
  .audit-list { grid-template-columns: 1fr; }
  .audit-list li, .audit-list li:nth-child(3n) { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
