:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  --ink: #17202a;
  --muted: #66727f;
  --line: #d9e0e6;
  --paper: #f4f7f8;
  --surface: #ffffff;
  --accent: #087e8b;
  --accent-strong: #05636d;
  --danger: #b42318;
  --success: #177245;
  --warning: #9a6700;
  --radius: 10px;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.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: 100dvh; display: grid; place-items: center; padding: 32px 20px; background: linear-gradient(140deg, #edf5f5 0%, #f7f8f4 58%, #eef2f5 100%); }
.login-panel { width: min(440px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.94); box-shadow: 0 24px 70px rgba(23,32,42,.1); }
.brand-mark { width: 38px; height: 38px; display: flex; align-items: flex-end; gap: 3px; padding: 7px; border-radius: 9px; background: var(--ink); }
.brand-mark span { width: 6px; background: #dce8e6; border-radius: 2px 2px 0 0; }
.brand-mark span:nth-child(1) { height: 11px; }
.brand-mark span:nth-child(2) { height: 18px; }
.brand-mark span:nth-child(3) { height: 24px; background: #80c7c8; }
.login-copy { margin: 24px 0 28px; }
.eyebrow { margin: 0 0 8px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
h1, h2 { margin: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.15; }
.login-copy p:last-child, .workspace-header p:last-child, .panel-heading p { margin: 10px 0 0; color: var(--muted); line-height: 1.7; }
.stack-form, .dialog-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #34404b; font-size: 14px; }
input, select, textarea { width: 100%; border: 1px solid #cbd4db; border-radius: 7px; background: #fff; color: var(--ink); padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,126,139,.12); }
.primary-button, .secondary-button { border-radius: 7px; padding: 10px 16px; border: 1px solid transparent; font-weight: 700; transition: transform .12s, background .12s; }
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { background: #fff; color: #34404b; border-color: #cbd4db; }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.text-button, .icon-button { border: 0; background: transparent; color: var(--accent); padding: 6px; }
.text-button { white-space: nowrap; }
.icon-button { font-size: 24px; line-height: 1; color: var(--muted); }
.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.secure-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 218px 1fr; }
.sidebar { position: sticky; top: 0; height: 100dvh; padding: 22px 18px; display: flex; flex-direction: column; border-right: 1px solid #d8e0e5; background: #edf2f3; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { display: block; color: var(--muted); margin-top: 3px; }
nav { margin-top: 34px; display: grid; gap: 6px; }
.nav-item { border: 0; border-radius: 7px; padding: 10px 12px; text-align: left; color: #4b5762; background: transparent; }
.nav-item.active { color: var(--accent-strong); background: #dbecec; font-weight: 700; }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; font-size: 13px; }
.status-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #1f9d68; }

.workspace { min-width: 0; padding: 34px clamp(20px, 4vw, 54px) 52px; }
.workspace-header { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.workspace-header h1 { font-size: 32px; }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metrics article { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metrics span { display: block; color: var(--muted); font-size: 13px; }
.metrics strong { display: block; margin-top: 8px; font-size: 28px; font-variant-numeric: tabular-nums; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.search-field { flex: 1 1 260px; }
.search-field input { margin: 0; }
.toolbar select { width: auto; min-width: 130px; }
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 14px; border-bottom: 1px solid #e6ebee; text-align: left; vertical-align: middle; }
th { color: #5b6873; font-size: 12px; font-weight: 700; letter-spacing: .035em; background: #f8fafb; }
tbody tr:hover { background: #f6faf9; }
.chip { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip.unused { color: #4b5563; background: #eef1f3; }
.chip.active { color: var(--success); background: #e5f5ec; }
.chip.revoked { color: var(--danger); background: #fdecea; }
.chip.expired { color: var(--warning); background: #fff4d6; }
.actions-column { min-width: 180px; }
.row-actions { display: flex; gap: 8px; }
.row-action { border: 0; background: transparent; color: var(--accent); padding: 4px 0; font-size: 12px; }
.row-action.danger { color: var(--danger); }
.empty-state { padding: 72px 20px; display: grid; gap: 8px; place-items: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.events-panel { margin-top: 18px; }
.panel-heading { display: flex; justify-content: space-between; gap: 20px; padding: 18px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { font-size: 18px; }
.event-list { max-height: 360px; overflow: auto; }
.event-item { display: grid; grid-template-columns: 108px 130px 1fr; gap: 14px; padding: 12px 18px; border-bottom: 1px solid #edf0f2; font-size: 13px; }
.event-item time, .event-item .key { color: var(--muted); }

dialog { width: min(500px, calc(100vw - 28px)); padding: 0; border: 1px solid #cfd8df; border-radius: var(--radius); box-shadow: 0 30px 90px rgba(23,32,42,.25); }
dialog::backdrop { background: rgba(23,32,42,.38); backdrop-filter: blur(2px); }
.dialog-form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; }
.dialog-header h2 { font-size: 23px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.dialog-hint { color: var(--muted); line-height: 1.6; margin: 0; }
#new-cards-output { font-family: Consolas, monospace; resize: vertical; line-height: 1.65; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 16px; border-radius: 8px; background: #17202a; color: #fff; transform: translateY(20px); opacity: 0; pointer-events: none; transition: .18s; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 20px; padding: 14px 18px; }
  nav { margin: 0 0 0 auto; grid-auto-flow: column; }
  .sidebar-footer { margin: 0; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .workspace { padding: 24px 14px 40px; }
  .workspace-header { align-items: stretch; flex-direction: column; }
  .workspace-header .primary-button { width: 100%; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article:last-child { grid-column: 1 / -1; }
  .sidebar { align-items: flex-start; flex-wrap: wrap; }
  .sidebar-brand { width: 100%; }
  nav { margin-left: 0; }
  .event-item { grid-template-columns: 1fr; gap: 4px; }
  .panel-heading { align-items: flex-start; }
}
