:root {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #151b24;
  --panel: #1b2430;
  --panel-2: #202b38;
  --border: #324151;
  --text: #f2f6fb;
  --muted: #9aa7b7;
  --accent: #21b8b0;
  --accent-2: #087f7a;
  --danger: #ff9daf;
  --warning: #ffd68a;
  --success: #8de3b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

a {
  color: #7fe7df;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 28px;
  background: #121820;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.shell {
  width: min(1540px, calc(100% - 48px));
  margin: 24px auto 64px;
}

.footer {
  width: min(1540px, calc(100% - 48px));
  margin: 0 auto 24px;
  color: var(--muted);
  font-size: 12px;
}

.hero,
.grid-two,
.details-grid,
.issue-form,
.summary-list {
  display: grid;
  gap: 16px;
}

.hero {
  grid-template-columns: 1fr 260px;
  align-items: stretch;
  margin-bottom: 18px;
}

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

.panel,
.auth-panel,
.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.2);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading form {
  flex: 0 0 auto;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 72px auto;
}

.auth-panel-wide {
  width: min(660px, 100%);
}

.status-card {
  display: grid;
  align-content: center;
  gap: 6px;
}

.status-card span,
.eyebrow,
.muted,
.details-grid span,
.summary-list dt,
table span {
  color: var(--muted);
}

.status-card.ok strong {
  color: var(--success);
}

.status-card.warn strong {
  color: var(--warning);
}

.status-card small {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

h1,
h2 {
  margin: 0 0 10px;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 19px;
}

.stacked-form,
.issue-form {
  margin-top: 16px;
}

.stacked-form {
  display: grid;
  gap: 14px;
}

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

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

input,
select,
textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  min-height: 40px;
  padding: 9px 11px;
  font: inherit;
}

textarea {
  resize: vertical;
}

.primary-button,
.secondary-button,
.link-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 9px 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  background: #0f8f89;
  color: white;
}

.primary-button:disabled {
  background: #33404e;
  color: #8d99a8;
}

.secondary-button,
.link-button {
  background: var(--panel-2);
  color: var(--text);
}

.link-button {
  border: 1px solid var(--border);
}

.icon-button {
  place-items: center;
  width: 38px;
  min-height: 38px;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 22px;
  line-height: 1;
}

.compact-button {
  min-height: 34px;
  padding: 7px 12px;
}

.table-actions {
  display: grid;
  gap: 8px;
  width: 100%;
}

.actions-cell {
  width: 188px;
  min-width: 188px;
}

.inline-form {
  display: grid;
  gap: 5px;
}

.compact-role-form {
  grid-template-columns: minmax(110px, 1fr) auto;
  align-items: center;
}

.compact-password-input {
  min-width: 160px;
}

.inline-form small {
  color: var(--warning);
  font-size: 11px;
}

.license-records-table {
  min-width: 1120px;
  table-layout: fixed;
}

.license-col-identity {
  width: 20%;
}

.license-col-type {
  width: 10%;
}

.license-col-meters,
.license-col-revision {
  width: 6%;
}

.license-col-status {
  width: 10%;
}

.license-col-date {
  width: 11%;
}

.license-col-heartbeat {
  width: 12%;
}

.license-col-sync {
  width: 10%;
}

.license-col-actions {
  width: 188px;
}

.license-records-table th,
.license-records-table td {
  padding: 13px 10px;
}

.license-records-table td {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.license-records-table small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.date-value {
  white-space: nowrap;
}

.record-editor {
  position: relative;
}

.record-editor summary {
  cursor: pointer;
  list-style: none;
  text-align: center;
}

.record-editor summary::-webkit-details-marker {
  display: none;
}

.record-editor[open] {
  grid-column: 1 / -1;
}

.record-editor[open] summary {
  margin-bottom: 10px;
}

.record-editor .compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.action-link {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.license-dialog {
  position: fixed;
  inset: 0;
  width: min(1180px, calc(100vw - 32px));
  min-width: 0;
  max-height: calc(100vh - 48px);
  padding: 0;
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
}

.license-dialog::backdrop {
  background: rgba(2, 6, 12, 0.72);
  backdrop-filter: blur(5px);
}

.dialog-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  max-height: inherit;
  overflow: hidden;
  background: linear-gradient(180deg, #18212c 0%, #111821 100%);
}

.dialog-body {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.license-edit-form {
  display: grid;
  gap: 16px;
  padding: 0;
  min-height: auto;
  overflow: visible;
}

.form-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: rgba(32, 43, 56, 0.7);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.app-users-section {
  margin: 0;
}

.compact-app-user-form {
  padding: 0;
  overflow: visible;
}

.renewal-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: rgba(18, 62, 50, 0.42);
  border: 1px solid rgba(141, 227, 184, 0.35);
  border-radius: 10px;
}

.renewal-card.is-expired {
  background: rgba(75, 31, 40, 0.62);
  border-color: rgba(255, 157, 175, 0.48);
}

.renewal-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.renewal-action {
  display: grid;
  gap: 8px;
}

.renewal-action small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.app-user-list {
  display: grid;
  gap: 12px;
}

.app-user-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(0, 1.6fr);
  gap: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.app-user-main {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.app-user-main strong,
.app-user-main span {
  display: block;
  overflow-wrap: anywhere;
}

.app-user-main > div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.app-user-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.app-user-controls {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.app-user-role-form,
.app-user-password-form,
.app-user-toggle-actions {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.app-user-role-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.app-user-password-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.app-user-toggle-actions {
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-table-wrap table {
  margin-top: 0;
}

.compact-table-wrap th,
.compact-table-wrap td {
  padding: 9px 8px;
}

.form-section h3 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 15px;
}

.form-section h3 span,
.field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.dialog-actions {
  display: grid;
  gap: 12px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: rgba(14, 17, 22, 0.72);
}

.dialog-action-note {
  margin: 0;
  color: var(--warning);
  font-size: 13px;
  font-weight: 700;
}

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

.dialog-action-row .inline-form {
  display: inline-flex;
}

.compact-alert {
  margin: 16px 24px 0;
}

.alert {
  margin: 16px 0;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.alert-success {
  background: #123e32;
  color: var(--success);
}

.alert-danger {
  background: #4b1f28;
  color: var(--danger);
}

.alert-warning {
  background: #4a3715;
  color: var(--warning);
}

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

.details-grid div,
.summary-list div {
  display: grid;
  gap: 5px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.signing-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0 0;
}

.signing-grid div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.signing-grid dt,
.signing-grid dd {
  margin: 0;
}

.signing-grid dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.signing-grid dd {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.summary-list dd,
.summary-list dt {
  margin: 0;
}

.summary-list dd {
  font-size: 24px;
  font-weight: 700;
}

.full-width {
  grid-column: 1 / -1;
}

.mt-3 {
  margin-top: 16px;
}

.approval-box,
.approval-summary {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.approval-box legend {
  color: var(--text);
  font-weight: 700;
  padding: 0 6px;
}

.check-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0;
}

.check-line input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

.approval-summary h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.empty-state {
  color: var(--muted);
  padding: 18px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.compact-empty {
  padding: 12px;
  margin: 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill {
  display: inline-block;
  padding: 4px 9px;
  background: #123b43;
  color: #7fe7df;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.ok {
  background: #123e32;
  color: var(--success);
}

.status-pill.warn {
  background: #4a3715;
  color: var(--warning);
}

.status-pill.danger {
  background: #4b1f28;
  color: var(--danger);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.identifier-card {
  min-width: 0;
}

.identifier-card code,
.identifier-line code,
.ops-grid code {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.identifier-actions,
.identifier-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.identifier-actions details {
  min-width: 0;
}

.identifier-actions summary {
  color: #7fe7df;
  cursor: pointer;
  font-size: 12px;
}

.copy-button {
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.ops-details {
  margin-top: 16px;
  color: var(--muted);
}

.ops-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.ops-grid div {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

code {
  color: #b4ede9;
}

.secret-code {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.qr-setup-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-top: 18px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.qr-setup-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.qr-setup-card strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.qr-setup-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.totp-qr-code {
  width: 216px;
  height: 216px;
  padding: 12px;
  background: #ffffff;
  border-radius: 8px;
}

.setup-grid {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

@media (max-width: 900px) {
  .hero,
  .grid-two,
  .details-grid,
  .signing-grid,
  .ops-grid,
  .issue-form {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: grid;
  }

  .license-dialog {
    width: calc(100vw - 24px);
    min-width: 0;
  }

  .dialog-body,
  .dialog-header,
  .dialog-actions {
    padding-left: 16px;
    padding-right: 16px;
  }

  .renewal-card,
  .app-user-card,
  .app-user-controls,
  .app-user-role-form,
  .app-user-password-form,
  .app-user-toggle-actions {
    grid-template-columns: 1fr;
  }

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

  .dialog-action-row {
    justify-content: stretch;
  }

  .dialog-action-row > *,
  .dialog-action-row button,
  .dialog-action-row .inline-form {
    width: 100%;
  }

  .qr-setup-card {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .totp-qr-code {
    width: min(100%, 240px);
    height: auto;
    aspect-ratio: 1;
  }
}
