:root {
	--bg: #0f1218;
	--panel: #171b24;
	--panel-2: #1e2430;
	--line: #2a3140;
	--text: #e6e9ef;
	--muted: #98a2b3;
	--accent: #5b8cff;
	--accent-ink: #ffffff;
	--ok: #35c08a;
	--warn: #e0a336;
	--bad: #ef5f5f;
	--radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
	background: var(--bg);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

code, .codes, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.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;
}

/* ---------- top bar ---------- */
.topbar {
	display: flex; align-items: center; justify-content: space-between; gap: 16px;
	flex-wrap: wrap;
	padding: 18px 24px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -0.2px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- layout ---------- */
main { padding: 24px; max-width: 1240px; margin: 0 auto; }
.card {
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 20px;
	margin-bottom: 20px;
}
.login { max-width: 520px; margin: 48px auto; }
.login h2 { margin: 0 0 6px; font-size: 18px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.hint code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- stats ---------- */
.stats {
	display: grid; gap: 12px; margin-bottom: 20px;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
	background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
	padding: 16px; text-align: center;
}
.stat-num { display: block; font-size: 28px; font-weight: 600; letter-spacing: -0.5px; }
.stat-lbl { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.grow { flex: 1 1 260px; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 5px; font-size: 13px; color: var(--muted); }
.field em { font-style: normal; opacity: 0.65; }
.field input, .field select, .codes {
	width: 100%; padding: 9px 11px;
	background: var(--panel-2); color: var(--text);
	border: 1px solid var(--line); border-radius: 8px;
	font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .codes:focus {
	outline: none; border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); padding: 9px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.field input:disabled { opacity: 0.5; cursor: not-allowed; }

.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }

/* ---------- buttons ---------- */
.btn {
	padding: 9px 14px; border-radius: 8px; cursor: pointer;
	background: var(--panel-2); color: var(--text);
	border: 1px solid var(--line);
	font-size: 14px; font-family: inherit; font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-warn { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-warn:hover { background: rgba(239, 95, 95, 0.12); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.icon-btn {
	background: none; border: 0; color: var(--muted); cursor: pointer;
	font-size: 24px; line-height: 1; padding: 0 6px; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.grid thead th {
	font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
	color: var(--muted); font-weight: 600; white-space: nowrap;
}
.grid tbody tr:hover { background: var(--panel-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; }
.compact th, .compact td { padding: 7px 10px; font-size: 13px; }
.code-cell { display: flex; align-items: center; gap: 8px; }
.code-cell code { font-size: 13px; white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
	display: inline-block; padding: 2px 9px; border-radius: 999px;
	font-size: 12px; font-weight: 600; text-transform: capitalize;
	border: 1px solid transparent;
}
.badge.active { background: rgba(53, 192, 138, 0.14); color: var(--ok); border-color: rgba(53, 192, 138, 0.35); }
.badge.revoked { background: rgba(239, 95, 95, 0.14); color: var(--bad); border-color: rgba(239, 95, 95, 0.35); }
.badge.expired { background: rgba(224, 163, 54, 0.14); color: var(--warn); border-color: rgba(224, 163, 54, 0.35); }
.badge.never { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.badge.missing { background: rgba(152, 162, 179, 0.14); color: var(--muted); border-color: var(--line); }

.muted { color: var(--muted); }
.sub-note { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; margin: 0; }
.warn {
	margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px;
	background: rgba(224, 163, 54, 0.1); border: 1px solid rgba(224, 163, 54, 0.3); color: var(--warn);
}
.error {
	margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px;
	background: rgba(239, 95, 95, 0.1); border: 1px solid rgba(239, 95, 95, 0.3); color: var(--bad);
}

/* ---------- modals ---------- */
.modal {
	position: fixed; inset: 0; z-index: 50;
	background: rgba(6, 8, 12, 0.7);
	display: flex; align-items: center; justify-content: center;
	padding: 20px; overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-box {
	background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
	padding: 22px; width: 100%; max-width: 520px;
	max-height: calc(100vh - 40px); overflow-y: auto;
}
.modal-box.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.codes { font-size: 13px; resize: vertical; margin-bottom: 14px; }

/* ---------- detail ---------- */
.detail { display: grid; grid-template-columns: 1fr 1.2fr; gap: 22px; }
.detail-main .code-line { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.detail-main code { font-size: 14px; }
#d-meta { margin: 10px 0 0; font-size: 13px; }

.devices { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 18px; }
.devices-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.devices-head h3 { margin: 0; font-size: 15px; }
.devid { font-size: 12px; color: var(--muted); word-break: break-all; }

.danger {
	display: flex; gap: 10px; margin-top: 20px; padding-top: 18px;
	border-top: 1px solid var(--line);
}

/* ---------- toast ---------- */
.toast {
	position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
	background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
	padding: 11px 18px; border-radius: 8px; font-size: 14px; z-index: 90;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.toast[hidden] { display: none; }
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.good { border-color: var(--ok); color: var(--ok); }

@media (max-width: 640px) {
	.grid2, .detail { grid-template-columns: 1fr; }
	main, .topbar { padding: 16px; }
}
