:root {
  color-scheme: light;
  --page-bg: #f2f4f8;
  --surface: #fff;
  --surface-soft: #fafbfc;
  --text: #273449;
  --muted: #788397;
  --border: #e5e9ef;
  --border-strong: #d9dfe8;
  --brand: #b8323a;
  --brand-focus: #b8323a33;
  --neutral: #687386;
  --success: #18835c;
  --warning-bg: #fff2df;
  --warning-text: #81500d;
  --radius: 8px;
  --shadow-card: 0 15px 45px #14213d18;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--page-bg);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button,
.button,
.edit-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  line-height: 1.2;
}

button:hover,
.button:hover,
.edit-trigger:hover {
  filter: brightness(.96);
}

button:focus-visible,
a:focus-visible,
.edit-trigger:focus-visible,
.close:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--brand-focus);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: .65;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

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

label {
  display: block;
  margin: 8px 0 4px;
  font-weight: 600;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 24px;
  font-size: clamp(22px, 4vw, 28px);
  line-height: 1.25;
}

h2 {
  margin-bottom: 12px;
  font-size: 19px;
}

.hint {
  margin: 5px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.box,
.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* First-time setup */
.setup-page {
  padding: 5vh 16px;
}

.setup-page .box {
  max-width: 650px;
  margin: 0 auto;
  padding: 28px;
}

.setup-page .setup-qr {
  float: left;
  width: 220px;
  max-width: 42%;
  height: auto;
  margin: 0 22px 15px 0;
}

.setup-page .secret {
  overflow-wrap: anywhere;
  padding: 8px;
  background: var(--page-bg);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.setup-page .clear {
  clear: both;
}

.setup-page button {
  width: 100%;
  min-height: 44px;
  margin-top: 16px;
}

/* Login */
.login-page {
  display: grid;
  min-height: 100vh;
  padding: 20px;
  place-items: center;
}

.login-page .box {
  width: min(420px, 100%);
  padding: 30px;
}

.login-page label {
  margin-top: 14px;
}

.login-page button {
  width: 100%;
  min-height: 46px;
  margin-top: 20px;
  font-size: 16px;
}

/* Recovery codes */
.recovery-page {
  padding: 7vh 16px;
  font-size: 16px;
}

.recovery-page .box {
  max-width: 600px;
  margin: 0 auto;
  padding: 28px;
}

.recovery-page .codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  font: 20px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.recovery-page .codes > div {
  overflow-wrap: anywhere;
}

.recovery-page .hint-warning {
  padding: 12px;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning-text);
}

.recovery-page .button {
  margin-top: 8px;
}

/* Authorization list */
.license-page .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px max(18px, calc((100% - 1200px) / 2));
  background: var(--surface);
}

.license-page .head > span {
  display: flex;
  margin-left: 16px;
  align-items: center;
}

.license-page .head > span > * + * {
  margin-left: 12px;
}

.inline-form,
.actions form,
.confirm-actions form {
  display: flex;
  margin: 0;
}

.license-page .wrap {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 16px;
}

.panel {
  margin-bottom: 16px;
  padding: 17px;
  box-shadow: none;
}

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

.time-label {
  display: flex;
  justify-content: space-between;
}

.time-label small {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 400;
}

.muted {
  background: var(--neutral);
}

.green {
  background: var(--success);
}

.table {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  padding: 10px;
  border-bottom: 1px solid #edf0f4;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-soft);
  white-space: nowrap;
}

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

.code {
  max-width: 180px;
  word-break: break-all;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.domain {
  max-width: 180px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.date {
  white-space: nowrap;
}

.state {
  color: #167650;
  font-weight: 600;
}

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

.expiry {
  display: inline-block;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}

.expiry-critical,
.expiry-expired {
  color: #b4232d;
}

.expiry-warning {
  color: #a86408;
}

.expiry-neutral {
  color: var(--neutral);
}

.expiry-disabled {
  color: var(--muted);
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  white-space: nowrap;
}

.row-actions > form,
.row-actions > .modal-control {
  display: inline-flex;
  height: 38px;
  align-items: center;
  margin: 0;
}

.row-actions > form + .modal-control,
.row-actions > .modal-control + .modal-control {
  margin-left: 10px;
}

.row-actions button,
.row-actions .edit-trigger {
  height: 38px;
  min-height: 38px;
  margin: 0;
  padding: 8px 12px;
  line-height: 1.2;
}

.modal-control {
  display: inline-flex;
  align-items: center;
}

.modal-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.modal-toggle:focus-visible + .edit-trigger {
  outline: 3px solid var(--brand-focus);
  outline-offset: 2px;
}

.edit-trigger {
  min-height: 38px;
  margin: 0;
}

.modal-overlay {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: none;
  overflow: auto;
  padding: 5vh 12px;
  background: #172033bb;
}

.modal-toggle:checked ~ .modal-overlay {
  display: block;
}

.modal-card,
.confirm-card {
  margin: 0 auto;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 20px 70px #14213d55;
}

.modal-card {
  width: min(900px, 100%);
  overflow: hidden;
}

.confirm-card {
  width: min(480px, 100%);
  margin-top: 10vh;
  padding: 22px;
}

.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #edf0f4;
  background: var(--surface);
}

.dialog-head h2 {
  margin: 0;
}

.dialog-body {
  padding: 14px 20px 20px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 14px;
}

.dialog-actions > * + * {
  margin-left: 8px;
}

.license-form-actions {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.license-form-actions .form-submit {
  width: auto;
  min-width: 120px;
  height: 42px;
  min-height: 42px;
  margin: 0;
  padding: 0 18px;
}

.close {
  display: inline-flex;
  min-width: 92px;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 12px;
  border-radius: 7px;
  background: var(--neutral);
  color: #fff;
  cursor: pointer;
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.confirm-actions button {
  min-width: 92px;
  min-height: 38px;
  margin: 0;
  padding: 0 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.search,
.pages {
  display: flex;
  align-items: center;
  margin: 10px 0;
}

.search > * + *,
.pages > * + * {
  margin-left: 8px;
}

.search input {
  max-width: 340px;
}

.pages a {
  padding: 7px 10px;
  border-radius: 7px;
  background: #f0f2f6;
  color: var(--text);
  text-decoration: none;
}

@media (max-width: 720px) {
  .setup-page .box,
  .login-page .box,
  .recovery-page .box {
    padding: 22px 18px;
  }

  .setup-page .setup-qr {
    float: none;
    display: block;
    width: min(220px, 70vw);
    max-width: 100%;
    margin: 0 auto 16px;
  }

  .license-page .head {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .license-page .head > span {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .license-page .wrap {
    margin: 12px auto;
  }

  .panel {
    padding: 13px;
  }

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

  .dialog-body {
    padding: 10px 14px 16px;
  }
}

@media (max-width: 420px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .recovery-page .codes {
    grid-template-columns: minmax(0, 1fr);
  }

  .confirm-card {
    padding: 18px;
  }

  .dialog-actions {
    justify-content: stretch;
  }

  .dialog-actions > * + * {
    margin-left: 8px;
  }

  .confirm-actions .close,
  .confirm-actions form,
  .confirm-actions button {
    flex: 1 1 0;
  }
}
