:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --panel: #fafafa;
  --hover: #f2f2f2;
  --accent: #111111;
  --danger: #8a1f1f;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }

/* Buttons */
.btn {
  font: inherit; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

/* Login */
.login-view { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  width: 320px; padding: 28px; border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); color: var(--fg);
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

/* Topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 22px; }
.stat-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--panel); }
.stat-card .num { font-size: 24px; font-weight: 600; }
.stat-card .lbl { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; }

/* Table */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.data-table th { background: var(--panel); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.data-table tbody tr:hover { background: var(--hover); cursor: pointer; }
.data-table td.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* Status pills */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.active { background: #eef7ee; border-color: #cfe6cf; }
.pill.revoked { background: #fbecec; border-color: #efcaca; }
.pill.suspended { background: #fdf4e7; border-color: #f0ddb8; }
.pill.unused { background: var(--panel); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--bg); border-radius: var(--radius); padding: 22px; width: 420px; max-height: 90vh; overflow: auto; }
.modal-card.wide { width: 640px; }
.modal-card h2 { margin-top: 0; }
.modal-card form { display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Detail */
.detail-code { font-family: ui-monospace, Menlo, monospace; font-size: 20px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 14px 0; }
.kv .k { color: var(--muted); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.sub-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.sub-table th, .sub-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
h3 { margin: 18px 0 6px; font-size: 14px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 10px 18px; border-radius: var(--radius);
}

@media (max-width: 800px) { .stats-grid { grid-template-columns: repeat(3, 1fr); } }
