:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f0f3f7;
  --border: #dce1e7;
  --border-strong: #bec6d0;
  --text: #202124;
  --muted: #68717d;
  --blue: #1769ff;
  --blue-soft: #eef4ff;
  --cyan: #00aeb8;
  --green: #168a57;
  --green-soft: #eaf7f1;
  --orange: #d96b2b;
  --purple: #6f55d9;
  --danger: #c9364f;
  --danger-soft: #fff0f2;
  --shadow: 0 18px 46px rgba(43, 55, 72, 0.11);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(#e9edf2 1px, transparent 1px),
    linear-gradient(90deg, #e9edf2 1px, transparent 1px);
  background-size: 56px 56px;
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px max(24px, env(safe-area-inset-right)) 10px max(24px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.admin-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.brand-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small {
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-button,
.secondary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: #404750;
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.home-button:hover,
.secondary-button:hover {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.shell {
  width: min(calc(100% - 48px), 1080px);
  margin: 0 auto;
  padding: 42px 0 max(64px, env(safe-area-inset-bottom));
}

.auth-view {
  min-height: calc(100svh - 156px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(100%, 520px);
  padding: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel::before {
  content: "SECURE ADMIN";
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-bottom: 24px;
  padding: 0 8px;
  border: 1px solid #b9d4c6;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
}

.section-heading,
.generator-header {
  margin-bottom: 26px;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
}

h1,
h2 {
  color: var(--text);
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.18;
  font-weight: 600;
}

form {
  display: grid;
  gap: 20px;
}

label,
legend {
  color: #3d444d;
  font-size: 13px;
  font-weight: 700;
}

label span {
  color: var(--muted);
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input {
  min-height: 50px;
  padding: 0 14px;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 255, 0.12);
}

input::placeholder {
  color: #929aa5;
}

.primary-button {
  min-height: 50px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  color: var(--surface);
  background: var(--blue);
  font-weight: 750;
  transition: background 160ms ease, transform 160ms ease;
}

.primary-button:hover {
  background: #0d54d7;
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.security-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.generator-view {
  width: 100%;
}

.generator-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 30px;
}

.secure-badge {
  flex: 0 0 auto;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #b9d4c6;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
}

.generator-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(43, 55, 72, 0.06);
}

.field {
  min-width: 0;
  display: grid;
  gap: 9px;
}

.duration-field {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0;
  border: 0;
}

.duration-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}

.duration-tabs label {
  min-width: 0;
}

.duration-tabs input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.duration-tabs span {
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.duration-tabs input:checked + span {
  border-color: var(--blue);
  color: var(--surface);
  background: var(--blue);
}

.duration-amount,
.generate-button {
  grid-column: 1 / -1;
}

.number-control {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 50px;
}

.number-control button {
  min-height: 50px;
  border: 1px solid var(--border-strong);
  color: var(--blue);
  background: var(--surface-soft);
  font-size: 20px;
  font-weight: 800;
}

.number-control button:first-child {
  border-radius: 6px 0 0 6px;
}

.number-control button:last-child {
  border-radius: 0 6px 6px 0;
}

.number-control input {
  border-inline: 0;
  border-radius: 0;
  text-align: center;
}

.result-panel {
  margin-top: 18px;
  padding: 26px;
  border: 1px solid #c9d7ed;
  border-radius: 8px;
  background: var(--blue-soft);
}

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.result-heading div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-heading span {
  color: var(--blue);
  font-family: Consolas, "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
}

.result-heading strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#licenseResult {
  min-height: 150px;
  padding: 14px;
  resize: vertical;
  color: #094d35;
  background: var(--surface);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.result-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.result-meta div {
  min-width: 0;
  padding: 12px;
  border: 1px solid #d3dce8;
  border-radius: 6px;
  background: var(--surface);
}

.result-meta dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
}

.result-meta dd {
  overflow: hidden;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-section {
  margin-top: 18px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.history-header h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.history-count-badge {
  min-width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border: 1px solid #b9d4c6;
  border-radius: 13px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 11px;
  font-weight: 750;
}

.danger-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #e6a8b2;
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.danger-button:hover {
  border-color: var(--danger);
  background: #ffe4e9;
}

.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.history-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 12px;
}

.history-table thead {
  position: sticky;
  z-index: 2;
  top: 0;
}

.history-table th {
  padding: 12px 13px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 10px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.history-table td {
  padding: 12px 13px;
  border-bottom: 1px solid #edf0f3;
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
}

.history-table tbody tr:hover {
  background: var(--blue-soft);
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-table .customer-cell {
  max-width: 150px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
}

.type-badge {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.type-badge.permanent {
  border-color: #b9d4c6;
  color: var(--green);
  background: var(--green-soft);
}

.type-badge.daily {
  border-color: #efca9e;
  color: var(--orange);
  background: #fff6ea;
}

.type-badge.monthly {
  border-color: #c9bff0;
  color: var(--purple);
  background: #f4f0ff;
}

.copy-key-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: #48505a;
  background: var(--surface);
  font-size: 11px;
  font-weight: 700;
}

.copy-key-button:hover {
  color: var(--blue);
  border-color: var(--blue);
}

.history-empty {
  margin: 0;
  padding: 42px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 18px;
  max-width: 480px;
  margin: 0 auto;
  padding: 13px 16px;
  border: 1px solid #356ba8;
  border-radius: 7px;
  color: var(--surface);
  background: #183b66;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.toast.error {
  border-color: #a92f45;
  color: var(--surface);
  background: #762438;
}

@keyframes historyFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.history-row-new {
  animation: historyFadeIn 300ms ease forwards;
}

@media (max-width: 700px) {
  body {
    background-image: none;
  }

  .topbar {
    min-height: 64px;
    padding-inline: max(14px, env(safe-area-inset-left));
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand-copy strong {
    max-width: 210px;
    font-size: 13px;
  }

  .brand-copy small {
    font-size: 9px;
  }

  .home-button {
    display: none;
  }

  .shell {
    width: 100%;
    padding: 20px 12px max(40px, env(safe-area-inset-bottom));
  }

  .auth-view {
    min-height: calc(100svh - 112px);
  }

  .auth-panel {
    padding: 26px 20px;
    border-radius: 7px;
    box-shadow: none;
  }

  h1 {
    font-size: 25px;
  }

  .generator-header {
    align-items: flex-start;
    padding: 8px 4px 22px;
  }

  .secure-badge {
    margin-top: 3px;
  }

  .generator-form {
    grid-template-columns: 1fr;
    padding: 20px 16px;
    border-radius: 7px;
    box-shadow: none;
  }

  .generator-form > *,
  .duration-amount,
  .generate-button {
    grid-column: 1;
  }

  .duration-tabs span {
    min-height: 46px;
    padding-inline: 4px;
  }

  .result-panel,
  .history-section {
    padding: 20px 16px;
    border-radius: 7px;
  }

  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .result-heading .secondary-button {
    width: 100%;
  }

  #licenseResult {
    min-height: 180px;
  }

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

  .history-header {
    align-items: stretch;
    flex-direction: column;
  }

  .history-header h2 {
    font-size: 16px;
  }

  .danger-button {
    align-self: flex-start;
    min-height: 42px;
  }

  .history-table-wrap {
    margin-inline: -1px;
  }
}

@media (max-width: 380px) {
  .brand-copy strong {
    max-width: 170px;
  }

  .secure-badge {
    display: none;
  }

  .duration-tabs span {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
