:root {
  --bg: #f3f7f7;
  --ink: #101820;
  --muted: #66737c;
  --panel: #ffffff;
  --line: #dce8e6;
  --dark: #020b11;
  --teal: #00bfa6;
  --teal-bright: #19f1d2;
  --red: #b42318;
  --amber: #b7791f;
  --violet: #6d5bd0;
  --shadow: 0 18px 46px rgba(2, 11, 17, 0.09);
  --input-bg: #fff;
  --table-hover: #f9fcfb;
  --table-head: #fbfdfd;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --ink: #e6edf3;
  --muted: #8b949e;
  --panel: #161b22;
  --line: #30363d;
  --dark: #010409;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.3);
  --input-bg: #0d1117;
  --table-hover: #1c2128;
  --table-head: #161b22;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

button:hover:not(:disabled) {
  opacity: 0.88;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  cursor: progress;
  opacity: 0.65;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--input-bg);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 191, 166, 0.14);
}

.shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
  color: #effafa;
  background: var(--dark);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 0 24px rgba(25, 241, 210, 0.18);
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.token-box label {
  color: #a8b7bd;
  font-size: 12px;
}

nav {
  display: grid;
  gap: 4px;
}

nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #dcebea;
  text-decoration: none;
  border-radius: 8px;
  padding: 11px 12px;
  transition: background 0.12s;
}

nav a:hover,
nav a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

nav a .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  color: #a8b7bd;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  min-height: 36px;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.token-box {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.token-box input {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
}

.token-box button,
.secondary {
  color: #06201d;
  background: #dff8f4;
}

main {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 28px;
}

.hero {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 132px;
  padding: 22px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #020b11, #04272d 58%, #06786d);
  box-shadow: 0 22px 60px rgba(2, 11, 17, 0.17);
}

.hero img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 10px;
}

.hero p,
.panel-head p,
.dialog-head p {
  margin: 0 0 5px;
  color: var(--teal-bright);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.hero h1,
.panel h2,
.dialog-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.hero h1 {
  max-width: 760px;
  font-size: 28px;
  line-height: 1.25;
}

.hero span {
  display: block;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.72);
}

.hero button,
.primary {
  color: #02100f;
  background: linear-gradient(135deg, #19f1d2, #75ffea);
  box-shadow: 0 10px 24px rgba(25, 241, 210, 0.18);
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stats article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats article {
  display: grid;
  gap: 6px;
  padding: 16px;
  transition: transform 0.12s;
}

.stats article:hover {
  transform: translateY(-2px);
}

.stats span,
.muted {
  color: var(--muted);
}

.stats strong {
  font-size: 25px;
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.panel-head p,
.dialog-head p {
  color: var(--teal);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search {
  max-width: 340px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: var(--table-head);
  font-size: 12px;
}

tbody tr {
  transition: background 0.1s;
}

tbody tr:hover {
  background: var(--table-hover);
}

.row-title {
  display: grid;
  gap: 3px;
}

.key {
  direction: ltr;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  min-width: 72px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.badge.active,
.badge.ok {
  color: #08745f;
  background: #dff8ef;
}

.badge.revoked,
.badge.invalid,
.badge.danger {
  color: var(--red);
  background: #ffe4e0;
}

.badge.suspended,
.badge.warn {
  color: var(--amber);
  background: #fff1d6;
}

.badge.expired {
  color: #6b21a8;
  background: #f3e8ff;
}

.table-actions {
  display: flex;
  gap: 7px;
}

.table-actions button {
  min-height: 32px;
  padding: 6px 9px;
}

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

.danger {
  color: #fff;
  background: var(--red);
}

/* Confirm dialog overlay */
.confirm-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 11, 17, 0.5);
  z-index: 9999;
  animation: fadeIn 0.15s ease;
}

.confirm-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.confirm-box h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.confirm-box p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

.confirm-box .confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

dialog {
  width: min(920px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(2, 11, 17, 0.24);
}

dialog::backdrop {
  background: rgba(2, 11, 17, 0.46);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

#closeDialogBtn,
.close-btn {
  width: 38px;
  padding: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 22px;
}

.dialog-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(5, auto) 1fr auto;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.pagination button {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
}

/* Templates section */
.template-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 20px;
}

.template-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.template-card:hover {
  border-color: var(--teal);
  transform: translateY(-2px);
}

.template-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.template-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.template-card .template-meta {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.template-card .template-meta span {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
}

.template-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.template-actions button {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--dark);
  box-shadow: var(--shadow);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Activation details in edit dialog */
.activation-info {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  font-size: 12px;
}

.activation-info .info-item {
  display: grid;
  gap: 3px;
}

.activation-info .info-label {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
}

.activation-info .info-value {
  font-family: Consolas, monospace;
  font-size: 12px;
}

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

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

  nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .token-box {
    margin-top: 0;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hero {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .hero button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  main {
    padding: 16px;
  }

  .stats,
  .form-grid,
  .dialog-grid,
  .dialog-actions,
  nav {
    grid-template-columns: 1fr;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .activation-info {
    grid-template-columns: 1fr;
  }
}
