:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --text: #172026;
  --muted: #66717a;
  --line: #d8dee3;
  --primary: #176b5b;
  --primary-hover: #105346;
  --danger: #b42318;
  --warning: #9a5b00;
  --success: #1b6e3a;
  --used: #4854a4;
  --focus: #2f80ed;
  --shadow: 0 18px 54px rgb(23 32 38 / 18%);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.header-actions form {
  display: flex;
  margin: 0;
}

.header-user {
  display: none;
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  width: min(760px, calc(100% - 20px));
  margin: 14px auto 28px;
}

button,
select,
input,
textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

button,
select {
  padding: 0 12px;
}

textarea {
  padding: 10px;
}

button {
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  border-color: var(--muted);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.ghost-button {
  background: transparent;
}

.toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.register-form {
  display: grid;
  grid-template-columns: auto 72px minmax(104px, 1fr);
  align-items: center;
  gap: 8px;
  margin: 0;
}

.register-form label {
  color: var(--muted);
  font-weight: 700;
}

.flash-message {
  min-height: 21px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 650;
}

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

.filters a,
.pagination a,
.pagination span,
.pagination strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.filters a.active {
  border-color: var(--primary);
  background: #edf7f4;
  color: var(--primary);
  font-weight: 750;
}

.account-list-wrap {
  min-height: 220px;
}

.account-list {
  display: grid;
  gap: 8px;
}

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 9px 10px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
}

.account-row:active {
  transform: translateY(1px);
}

.account-row-email {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.account-row[data-status="pending"] .status-pill {
  background: #fff5df;
  color: var(--warning);
}

.account-row[data-status="unused"] .status-pill {
  background: #eaf7ef;
  color: var(--success);
}

.account-row[data-status="used"] .status-pill {
  background: #eef0ff;
  color: var(--used);
}

.account-row[data-status="failed"] .status-pill {
  background: #fff0ee;
  color: var(--danger);
}

.empty-state {
  margin: 0;
  padding: 34px 12px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.pagination strong {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.details-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  padding: 0;
  background: rgb(23 32 38 / 42%);
  color: var(--text);
}

.details-dialog[hidden] {
  display: none;
}

.details-open {
  overflow: hidden;
}

.details-panel,
.manual-copy-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.manual-copy-panel {
  max-height: min(420px, calc(100dvh - 24px));
}

.details-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.details-header h2 {
  margin: 0 auto 0 0;
  font-size: 17px;
}

.details-list {
  display: grid;
  min-height: 0;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.detail-copy-row,
.detail-advanced summary {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
  background: var(--panel);
  text-align: left;
}

.detail-copy-row {
  cursor: pointer;
}

.detail-copy-row:active {
  background: #edf7f4;
}

.detail-copy-row.is-copying {
  opacity: 0.75;
}

.detail-copy-row.is-copied {
  background: #eaf7ef;
}

.detail-label {
  color: var(--muted);
  font-weight: 750;
}

.detail-value {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-copy-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-copy-row.is-copied .detail-copy-state {
  background: var(--primary);
  color: #fff;
}

.detail-advanced {
  border-bottom: 1px solid var(--line);
}

.detail-advanced summary {
  list-style: none;
  cursor: pointer;
}

.detail-advanced summary::-webkit-details-marker {
  display: none;
}

.detail-advanced summary::after {
  content: ">";
  color: var(--muted);
  font-weight: 800;
}

.detail-advanced[open] summary::after {
  transform: rotate(90deg);
}

.advanced-status {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.advanced-list {
  display: grid;
  margin: 0;
  background: #fafbfb;
}

.advanced-list div {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.advanced-list dt {
  color: var(--muted);
  font-weight: 750;
}

.advanced-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.details-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.manual-copy-body {
  display: grid;
  gap: 10px;
  min-height: 0;
  padding: 14px;
}

.manual-copy-body p {
  margin: 0;
  color: var(--muted);
}

.manual-copy-body textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  overflow-wrap: anywhere;
}

form[action$="/login"] {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
  margin: 64px auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

[role="alert"] {
  margin: 0;
  color: var(--danger);
  font-weight: 650;
}

@media (min-width: 560px) {
  .app-header {
    padding: 8px 20px;
  }

  .header-user {
    display: inline-block;
  }

  main {
    margin-top: 20px;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .flash-message {
    text-align: right;
  }

  .details-dialog {
    place-items: center;
    padding: 20px;
  }

  .details-panel,
  .manual-copy-panel {
    width: min(560px, 100%);
    max-height: calc(100dvh - 40px);
    border-bottom: 1px solid var(--line);
    border-radius: 8px;
  }
}
