:root {
  color-scheme: dark;
  --bg: #07080b;
  --panel: #0e1016;
  --panel-2: #13161f;
  --line: #1f2431;
  --text: #e9ebf2;
  --muted: #8b91a3;
  --accent: #8f7dff;
  --accent-soft: rgba(143, 125, 255, 0.18);
  --ok: #54d6a0;
  --warn: #f5b963;
  --danger: #ff6b81;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(1100px 560px at 12% -10%, rgba(143, 125, 255, 0.18), transparent 62%),
    radial-gradient(900px 520px at 112% 8%, rgba(84, 214, 160, 0.08), transparent 60%),
    var(--bg);
}

body.admin-body {
  place-items: start center;
}

.shell {
  width: 100%;
  max-width: 560px;
}

.shell.wide {
  max-width: 1120px;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 22px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 22px 4px;
}

.brand-bar .brand {
  margin: 0;
}

.brand .mark {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  filter: drop-shadow(0 0 12px rgba(143, 125, 255, 0.45));
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.hidden {
  display: none !important;
}

h2 {
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.tab-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #fff;
}

form {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.row-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 10px;
}

.row-form input,
.row-form select {
  flex: 1;
}

.row-form button {
  flex: none;
  white-space: nowrap;
}

label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0a0c11;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  font-family: inherit;
}

.key-input {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

input::placeholder,
textarea::placeholder {
  color: #4d5364;
  text-transform: none;
  letter-spacing: normal;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: #08070f;
  cursor: pointer;
  transition: filter 120ms ease, border-color 120ms ease, color 120ms ease;
}

button.sm {
  padding: 7px 11px;
  border-radius: 9px;
  font-size: 12px;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

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

button.ghost:hover {
  border-color: var(--accent);
  color: #fff;
}

button.danger-btn {
  background: rgba(255, 107, 129, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 129, 0.35);
}

.error {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.notice {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--ok);
  font-size: 13px;
}

.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.pill {
  flex: none;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.pill.active {
  color: var(--ok);
  border-color: rgba(84, 214, 160, 0.35);
  background: rgba(84, 214, 160, 0.08);
}

.pill.warn {
  color: var(--warn);
  border-color: rgba(245, 185, 99, 0.4);
  background: rgba(245, 185, 99, 0.1);
}

.pill.revoked,
.pill.expired {
  color: var(--danger);
  border-color: rgba(255, 107, 129, 0.35);
  background: rgba(255, 107, 129, 0.08);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 18px 0 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-box {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0a0c11;
}

.stat-box .value {
  font-size: 22px;
  font-weight: 600;
}

.label {
  margin: 0 0 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.value {
  margin: 0;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.mono {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.usage {
  padding: 18px 0 6px;
}

.usage-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 13px;
}

.usage-head span:last-child {
  color: var(--text);
}

.bar {
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0a0c11;
  overflow: hidden;
}

.fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #b6a9ff);
  transition: width 320ms ease;
}

.fill.unlimited {
  background: linear-gradient(90deg, var(--ok), #9bf0cf);
}

.fill.empty {
  background: linear-gradient(90deg, var(--danger), #ff9aa8);
}

.section-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.device-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0a0c11;
  font-size: 13px;
}

.keyrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding: 18px 0 4px;
  border-top: 1px solid var(--line);
}

.keyrow code {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  text-align: right;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.actions button {
  flex: 1;
}

/* Admin layout */
.admin-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0a0c11;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
}

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

.banner {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(84, 214, 160, 0.45);
  background: rgba(84, 214, 160, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.captures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.capture-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0a0c11;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.capture-card img {
  width: 100%;
  max-height: 210px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #050608;
  cursor: zoom-in;
}

.pre-box {
  margin: 0;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #07090d;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 440px;
  overflow-y: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.88);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 90;
}

.modal-inner {
  max-width: 94vw;
  max-height: 92vh;
  display: grid;
  gap: 10px;
  justify-items: end;
}

.modal-inner img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #000;
}

footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
}

.dot {
  opacity: 0.5;
}

@media (max-width: 720px) {
  .admin-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .card {
    padding: 20px;
  }

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

  .actions,
  .row-form {
    flex-direction: column;
  }
}
