:root,
html[data-theme="blue"] {
  --bg: #e8eef6;
  --panel: #ffffff;
  --ink: #12233d;
  --muted: #5a6d86;
  --line: #c7d3e3;
  --line-strong: #aebdd0;
  --accent: #1b4f9c;
  --accent-hover: #163f7d;
  --accent-soft: #e6eef9;
  --accent-ink: #ffffff;
  --sidebar: #0d213f;
  --sidebar-ink: #d7e3f4;
  --sidebar-muted: #8fa6c4;
  --sidebar-active: #15325a;
  --nav-indicator: #4d8fd6;
  --brand-mark-bg: #3d74b8;
  --login-glow: rgba(27, 79, 156, 0.14);
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #f0c7c3;
  --surface-2: #f3f7fc;
  --surface-hover: #eef4fb;
  --mono: "Cascadia Mono", "Sarasa Mono SC", Consolas, monospace;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 2px;
  --shadow: 0 1px 2px rgba(13, 33, 63, 0.05), 0 8px 18px rgba(13, 33, 63, 0.06);
  color-scheme: light;
}

html[data-theme="green"] {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #5b6b7c;
  --line: #d8dee6;
  --line-strong: #c9d3de;
  --accent: #0c6b56;
  --accent-hover: #095544;
  --accent-soft: #e7f4ef;
  --accent-ink: #ffffff;
  --sidebar: #15202b;
  --sidebar-ink: #d7e0ea;
  --sidebar-muted: #8fa0b3;
  --sidebar-active: #1f3344;
  --nav-indicator: #0c6b56;
  --brand-mark-bg: #0c6b56;
  --login-glow: rgba(12, 107, 86, 0.14);
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(21, 32, 43, 0.04), 0 8px 20px rgba(21, 32, 43, 0.05);
}

html[data-theme="slate"] {
  --bg: #eceff2;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #667484;
  --line: #d0d7df;
  --line-strong: #b8c2cd;
  --accent: #3d4f63;
  --accent-hover: #2f3e4f;
  --accent-soft: #e8edf2;
  --accent-ink: #ffffff;
  --sidebar: #232b36;
  --sidebar-ink: #dce3eb;
  --sidebar-muted: #9aa7b5;
  --sidebar-active: #2e3846;
  --nav-indicator: #8fa0b3;
  --brand-mark-bg: #4a5c70;
  --login-glow: rgba(61, 79, 99, 0.14);
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.05), 0 8px 18px rgba(28, 36, 48, 0.06);
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #151e2e;
  --ink: #e8eef8;
  --muted: #9aadc4;
  --line: #2b3b52;
  --line-strong: #3d516c;
  --accent: #4d8fef;
  --accent-hover: #3b7bd9;
  --accent-soft: #1a2f4d;
  --accent-ink: #ffffff;
  --sidebar: #070e1a;
  --sidebar-ink: #dce6f5;
  --sidebar-muted: #8da0b8;
  --sidebar-active: #13233a;
  --nav-indicator: #6aa8ff;
  --brand-mark-bg: #3d7fd4;
  --login-glow: rgba(77, 143, 239, 0.22);
  --surface-2: #101a2b;
  --surface-hover: #1a2740;
  --danger: #ff7b72;
  --danger-soft: #3a1f24;
  --danger-border: #6b3036;
  --radius: 4px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 10px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* 拟物：浮雕质感 */
html[data-theme="skeuo"] {
  --bg: #d8dee8;
  --panel: #e8edf4;
  --ink: #243044;
  --muted: #66788f;
  --line: #c3ccd8;
  --line-strong: #aeb9c8;
  --accent: #2f5f9e;
  --accent-hover: #254c80;
  --accent-soft: #d9e5f5;
  --accent-ink: #ffffff;
  --sidebar: #2a3648;
  --sidebar-ink: #e8eef7;
  --sidebar-muted: #a7b4c7;
  --sidebar-active: #38465c;
  --nav-indicator: #7eb0ea;
  --brand-mark-bg: #3a6eb0;
  --login-glow: rgba(47, 95, 158, 0.18);
  --danger: #b42318;
  --danger-soft: #f5e4e2;
  --radius: 12px;
  --shadow:
    6px 6px 14px rgba(140, 155, 175, 0.45),
    -5px -5px 12px rgba(255, 255, 255, 0.75);
}

/* 企业简洁：大量留白、细线、直角 */
html[data-theme="enterprise"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #111827;
  --accent-hover: #000000;
  --accent-soft: #f3f4f6;
  --accent-ink: #ffffff;
  --sidebar: #111827;
  --sidebar-ink: #f9fafb;
  --sidebar-muted: #9ca3af;
  --sidebar-active: #1f2937;
  --nav-indicator: #60a5fa;
  --brand-mark-bg: #2563eb;
  --login-glow: rgba(37, 99, 235, 0.1);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 0;
  --shadow: none;
}

/* 柔和：圆角、粉雾蓝紫 */
html[data-theme="soft"] {
  --bg: #f3f0f8;
  --panel: #fffcff;
  --ink: #2d2a3a;
  --muted: #7a738c;
  --line: #e4dcee;
  --line-strong: #d2c8e0;
  --accent: #6b5ce7;
  --accent-hover: #5748d1;
  --accent-soft: #eee9ff;
  --accent-ink: #ffffff;
  --sidebar: #3d3560;
  --sidebar-ink: #f4f0ff;
  --sidebar-muted: #b7aed4;
  --sidebar-active: #4d4474;
  --nav-indicator: #c4b5fd;
  --brand-mark-bg: #7c6cf0;
  --login-glow: rgba(107, 92, 231, 0.16);
  --danger: #e11d48;
  --danger-soft: #ffe4e9;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(90, 70, 140, 0.08);
}

/* 现代渐变：青蓝渐变强调 */
html[data-theme="gradient"] {
  --bg: #e9f2ff;
  --panel: #ffffff;
  --ink: #0f1b33;
  --muted: #5b6f8c;
  --line: #cfe0f5;
  --line-strong: #b5cce8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-ink: #ffffff;
  --sidebar: #0b1c3d;
  --sidebar-ink: #eaf2ff;
  --sidebar-muted: #9db4d4;
  --sidebar-active: #14305f;
  --nav-indicator: #38bdf8;
  --brand-mark-bg: linear-gradient(135deg, #2563eb, #06b6d4);
  --login-glow: rgba(37, 99, 235, 0.18);
  --danger: #e11d48;
  --danger-soft: #ffe4e9;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(37, 99, 235, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 0.98rem; }

.muted { color: var(--muted); font-size: 0.86rem; }
.error { color: var(--danger); margin: 0.5rem 0 0; font-size: 0.9rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 2px;
  background: var(--brand-mark-bg);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

/* —— Login —— */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(circle at 12% 8%, var(--login-glow), transparent 36%),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 70%, #fff), var(--bg) 48%, var(--bg));
}

.login-shell[hidden],
.shell[hidden],
.tab-panel[hidden],
[hidden] {
  display: none !important;
}

.login-panel {
  width: min(420px, 100%);
  padding: 1.75rem 1.8rem 1.9rem;
}

.login-brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.login-panel form {
  display: grid;
  gap: 0.9rem;
}

.login-panel label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 600;
}

/* —— Controls —— */
input, select, button {
  font: inherit;
}

input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.4;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 0.48rem 0.9rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
}

button:hover { background: var(--accent-hover); filter: none; }
button.primary:hover,
button:not(.ghost):not(.danger):hover { background: var(--accent-hover); }

button.ghost {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}

button.ghost:hover {
  background: var(--surface-hover);
  filter: none;
  color: var(--accent);
}

button.danger {
  background: var(--panel);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  font-weight: 500;
}

button.primary {
  min-height: 38px;
  padding-inline: 1.15rem;
}

/* —— Shell / Sidebar —— */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand .brand-mark {
  width: 1.85rem;
  height: 1.85rem;
  font-size: 0.65rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 0.9rem;
  line-height: 1.2;
}

.sidebar-brand .muted {
  color: var(--sidebar-muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

.side-nav {
  display: grid;
  gap: 0.2rem;
  padding: 0.55rem 0.55rem;
  align-content: start;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  text-align: left;
  background: transparent;
  color: var(--sidebar-ink);
  border: 0;
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  min-height: 36px;
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  filter: none;
}

.nav-item.active {
  background: var(--sidebar-active);
  box-shadow: inset 3px 0 0 var(--nav-indicator);
}

.theme-switch {
  display: grid;
  gap: 0.3rem;
  font-size: 0.74rem;
}

.theme-switch select {
  min-height: 34px;
  padding: 0.3rem 0.5rem;
  font-size: 0.84rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-ink);
  border-color: rgba(255, 255, 255, 0.16);
}

.theme-switch select option {
  color: #12233d;
  background: #fff;
}

.login-theme {
  color: var(--muted);
  font-weight: 600;
}

.login-theme select {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .panel-block,
html[data-theme="dark"] .device-card,
html[data-theme="dark"] .license-item,
html[data-theme="dark"] .fake-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .page-bar,
html[data-theme="dark"] .login-panel {
  background: var(--panel);
  border-color: var(--line);
}

html[data-theme="dark"] .page-bar {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom-color: var(--line);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] button.ghost {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] button.ghost:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

html[data-theme="dark"] button.danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

html[data-theme="dark"] th {
  background: var(--surface-2);
  color: var(--muted);
}

html[data-theme="dark"] td {
  border-bottom-color: var(--line);
}

html[data-theme="dark"] .device-detail,
html[data-theme="dark"] .fold-body {
  background: var(--surface-2);
  border-color: var(--line);
}

html[data-theme="dark"] .device-summary:hover,
html[data-theme="dark"] .device-card.open {
  background: var(--surface-hover);
}

html[data-theme="dark"] .device-list {
  border-color: var(--line);
  background: var(--panel);
}

html[data-theme="dark"] .license-count {
  background: var(--accent-soft);
  color: var(--sidebar-ink);
}

html[data-theme="dark"] .license-count.live {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: #cfe0ff;
}

html[data-theme="dark"] .status-pill {
  background: var(--surface-2);
  color: var(--muted);
}

html[data-theme="dark"] .status-pill.active {
  background: var(--accent-soft);
  color: #cfe0ff;
}

html[data-theme="dark"] .status-pill.issued {
  background: #3a3218;
  color: #f0d48a;
}

html[data-theme="dark"] .status-pill.revoked {
  background: var(--danger-soft);
  color: var(--danger);
}

html[data-theme="dark"] .code-banner {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--ink);
}

html[data-theme="dark"] .flag-item {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
}

html[data-theme="dark"] .flag-item:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #d7e6ff;
}

html[data-theme="dark"] .panel-block-head,
html[data-theme="dark"] .section-head {
  border-bottom-color: var(--line);
}

html[data-theme="dark"] .theme-switch select {
  background: var(--surface-2);
  color: var(--sidebar-ink);
  border-color: var(--line);
}

html[data-theme="dark"] .theme-switch select option {
  background: var(--panel);
  color: var(--ink);
}

html[data-theme="dark"] .login-shell {
  background:
    radial-gradient(circle at 12% 8%, var(--login-glow), transparent 36%),
    linear-gradient(180deg, #0a1424, var(--bg));
}

html[data-theme="dark"] .device-meta,
html[data-theme="dark"] .license-item-meta,
html[data-theme="dark"] .license-note.muted {
  color: var(--muted);
}

html[data-theme="dark"] .fold > summary {
  color: var(--muted);
}

/* 浅色通用优化 */
html:not([data-theme="dark"]) .page-bar {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px);
}

html:not([data-theme="dark"]) .device-detail {
  background: var(--surface-2);
}

html:not([data-theme="dark"]) .device-summary:hover {
  background: var(--surface-hover);
}

html:not([data-theme="dark"]) th {
  background: var(--surface-2);
}

.nav-label {
  font-size: 0.9rem;
  font-weight: 650;
}

.nav-desc {
  display: none;
}

.sidebar-foot {
  padding: 0.65rem 0.75rem 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 0.45rem;
}

.who-block {
  display: grid;
  gap: 0.15rem;
}

.who-block .muted {
  color: var(--sidebar-muted);
  font-size: 0.74rem;
}

.sidebar-foot .ghost {
  background: transparent;
  color: var(--sidebar-ink);
  border-color: rgba(255, 255, 255, 0.16);
}

.sidebar-foot .ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-foot .theme-switch .muted {
  color: var(--sidebar-muted);
}

/* —— Workspace —— */
.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.15rem 1.5rem 1rem;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
  backdrop-filter: blur(8px);
}

.page-bar h2 { margin-bottom: 0.2rem; }

.page-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.content {
  padding: 1.15rem 1.5rem 2rem;
  width: min(1280px, 100%);
}

.tab-panel[hidden] {
  display: none !important;
}

.panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem 1.15rem;
  margin-bottom: 1rem;
}

.panel-block-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.95rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid #eef2f5;
}

.issue-panel {
  max-width: 920px;
}

.split-2 {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1rem;
  align-items: start;
}

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.form-stack {
  display: grid;
  gap: 1rem;
}

.form-cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field > span,
.field-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  grid-template-columns: none;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-start;
  gap: 0.5rem;
}

.flag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.flag-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: var(--ink);
  user-select: none;
  white-space: nowrap;
  line-height: 1.2;
}

.flag-item input {
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.flag-item .flag-text {
  font-size: 0.84rem;
  font-weight: 500;
}

.flag-item .flag-code {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
}

.flag-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #153a72;
}

.date-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.date-row input[type="datetime-local"] {
  width: 240px;
  flex: 0 0 240px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.preset-row .ghost {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.preset-row .preset-long {
  border-color: var(--accent);
  color: #153a72;
  background: var(--accent-soft);
}

.expires-hint {
  margin-left: 0.35rem;
  font-style: normal;
  font-weight: 500;
  color: var(--accent);
}

/* —— Device list (desktop rows) —— */
.device-list {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.device-list > .muted {
  padding: 1rem;
}

.device-card {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.device-card:last-child {
  border-bottom: 0;
}

.device-card.open {
  background: #f7faff;
}

.device-summary {
  display: grid;
  grid-template-columns: 28px 72px minmax(140px, 1.1fr) minmax(180px, 1.4fr) minmax(160px, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  width: 100%;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
}

.device-summary:hover {
  background: #f3f7fc;
}

.device-summary:focus-visible {
  outline: 2px solid rgba(27, 79, 156, 0.35);
  outline-offset: -2px;
}

.device-chevron {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.device-card.open .device-chevron {
  color: var(--accent);
}

.device-id {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}

.device-name {
  font-weight: 650;
  font-size: 0.92rem;
}

.device-fp {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.device-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
}

.license-count {
  font-size: 0.75rem;
  color: var(--muted);
  background: #eef2f5;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.license-count.live {
  background: var(--accent-soft);
  color: #153a72;
}

.device-actions {
  display: flex;
  gap: 0.35rem;
}

.device-detail {
  display: none;
  border-top: 1px solid var(--line);
  background: #f2f6fb;
  padding: 0.85rem 0.95rem 1rem 2.4rem;
}

.device-card.open .device-detail {
  display: block;
}

.license-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.license-under {
  display: grid;
  gap: 0.45rem;
}

.license-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem 0.85rem;
  align-items: center;
  padding: 0.65rem 0.8rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.license-item.revoked {
  opacity: 0.7;
}

.license-item-main {
  display: grid;
  gap: 0.18rem;
  min-width: 0;
}

.license-item-meta {
  color: var(--muted);
  font-size: 0.76rem;
}

.license-note {
  margin-top: 0.15rem;
  font-size: 0.82rem;
  color: var(--ink);
  word-break: break-word;
}

.license-note.muted {
  color: var(--muted);
}

.fold {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  margin-top: 0.55rem;
  overflow: hidden;
}

.fold > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--muted);
  user-select: none;
}

.fold > summary::-webkit-details-marker { display: none; }

.fold > summary::before {
  content: "▶";
  display: inline-block;
  width: 1rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.fold[open] > summary::before {
  content: "▼";
  color: var(--accent);
}

.fold-body {
  margin: 0;
  padding: 0 0.75rem 0.75rem;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid #eef1f4;
  vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  background: #f8fafb;
}

code, .mono {
  font-family: var(--mono);
  font-size: 0.82rem;
}

.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.status-pill {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.74rem;
  background: #eef2f6;
  color: var(--muted);
}

.status-pill.active { background: var(--accent-soft); color: #153a72; }
.status-pill.revoked { background: var(--danger-soft); color: var(--danger); }
.status-pill.issued { background: #fff7e8; color: #9a6700; }

.code-banner {
  margin: 1rem 0 0;
  padding: 0.75rem 0.9rem;
  background: var(--accent-soft);
  border: 1px solid #b4c9e4;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  background: #15202b;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  max-width: min(420px, calc(100% - 2rem));
  z-index: 5;
  box-shadow: var(--shadow);
}

/* —— Theme extras —— */
html[data-theme="skeuo"] .panel,
html[data-theme="skeuo"] .panel-block,
html[data-theme="skeuo"] .login-panel {
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
}

html[data-theme="skeuo"] .device-list {
  border: 0;
  background: transparent;
  gap: 0.65rem;
  overflow: visible;
}

html[data-theme="skeuo"] .device-card {
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
  margin-bottom: 0.15rem;
}

html[data-theme="skeuo"] button:not(.ghost):not(.danger),
html[data-theme="skeuo"] button.primary {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 8px rgba(40, 70, 110, 0.28);
}

html[data-theme="skeuo"] button.ghost,
html[data-theme="skeuo"] input,
html[data-theme="skeuo"] select,
html[data-theme="skeuo"] textarea {
  box-shadow:
    inset 3px 3px 7px rgba(150, 165, 185, 0.35),
    inset -2px -2px 6px rgba(255, 255, 255, 0.8);
  border-color: transparent;
  background: #e8edf4;
}

html[data-theme="enterprise"] .panel,
html[data-theme="enterprise"] .panel-block,
html[data-theme="enterprise"] .page-bar,
html[data-theme="enterprise"] .device-list,
html[data-theme="enterprise"] .table-wrap,
html[data-theme="enterprise"] .license-item {
  border-radius: 0;
  box-shadow: none;
}

html[data-theme="enterprise"] .sidebar-brand,
html[data-theme="enterprise"] .section-head,
html[data-theme="enterprise"] .panel-block-head {
  border-color: #e5e7eb;
}

html[data-theme="enterprise"] button {
  border-radius: 0;
  letter-spacing: 0.04em;
  text-transform: none;
}

html[data-theme="enterprise"] .brand-mark,
html[data-theme="enterprise"] .status-pill,
html[data-theme="enterprise"] .license-count {
  border-radius: 0;
}

html[data-theme="soft"] .panel,
html[data-theme="soft"] .panel-block,
html[data-theme="soft"] .login-panel,
html[data-theme="soft"] .device-card,
html[data-theme="soft"] .license-item,
html[data-theme="soft"] .table-wrap {
  border-radius: var(--radius);
  border-color: transparent;
}

html[data-theme="soft"] button,
html[data-theme="soft"] input,
html[data-theme="soft"] select,
html[data-theme="soft"] textarea,
html[data-theme="soft"] .brand-mark,
html[data-theme="soft"] .nav-item {
  border-radius: 999px;
}

html[data-theme="soft"] input,
html[data-theme="soft"] select,
html[data-theme="soft"] textarea {
  border-radius: 12px;
  background: #faf7ff;
}

html[data-theme="soft"] .device-list {
  border: 0;
  gap: 0.75rem;
  overflow: visible;
  background: transparent;
}

html[data-theme="soft"] .device-card {
  overflow: hidden;
}

html[data-theme="gradient"] .sidebar {
  background: linear-gradient(180deg, #0b1c3d 0%, #12315f 48%, #0c4a6e 100%);
}

html[data-theme="gradient"] .login-shell {
  background:
    radial-gradient(circle at 15% 10%, rgba(37, 99, 235, 0.22), transparent 32%),
    radial-gradient(circle at 85% 20%, rgba(6, 182, 212, 0.18), transparent 30%),
    linear-gradient(160deg, #dbeafe, #e0f2fe 50%, #f0f9ff);
}

html[data-theme="gradient"] button:not(.ghost):not(.danger),
html[data-theme="gradient"] button.primary {
  background: linear-gradient(135deg, #2563eb, #06b6d4);
}

html[data-theme="gradient"] button:not(.ghost):not(.danger):hover,
html[data-theme="gradient"] button.primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
}

html[data-theme="gradient"] .brand-mark {
  background: linear-gradient(135deg, #2563eb, #06b6d4);
}

html[data-theme="gradient"] .nav-item.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.18), transparent);
}

html[data-theme="gradient"] .code-banner {
  background: linear-gradient(135deg, #dbeafe, #cffafe);
  border-color: #93c5fd;
}

html[data-theme="dark"] .toast {
  background: #0a1220;
}

@media (max-width: 1100px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-actions {
    grid-column: 1 / -1;
  }

  .device-summary {
    grid-template-columns: 28px 56px minmax(0, 1fr) auto;
    grid-template-areas:
      "chev id name side"
      "chev id fp   side"
      "chev id meta side";
  }

  .device-chevron { grid-area: chev; align-self: start; padding-top: 0.2rem; }
  .device-id { grid-area: id; align-self: start; padding-top: 0.15rem; }
  .device-name { grid-area: name; }
  .device-fp { grid-area: fp; white-space: normal; }
  .device-meta { grid-area: meta; }
  .device-side { grid-area: side; align-self: start; flex-direction: column; align-items: flex-end; }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-desc { display: none; }

  .split-2,
  .form-cols-2,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 1rem;
  }

  .device-detail {
    padding-left: 0.95rem;
  }

  .date-row input[type="datetime-local"] {
    width: 100%;
    flex: 1 1 100%;
  }
}
