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

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  background: #f4f6f8;
  color: #1a1a1a;
  line-height: 1.5;
}

a {
  color: #0b5fff;
}

.site-header {
  background: #102a43;
  color: #fff;
  padding: 0.75rem 1rem;
}

.site-header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.site-title {
  font-size: 1.05rem;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  flex: 1 1 auto;
}

.site-nav a {
  color: #fff;
  text-decoration: none;
  padding: 0.4rem 0.25rem;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  text-decoration: underline;
}

.nav-logout-form {
  display: inline;
  margin: 0;
}

main {
  max-width: 960px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.flash-success { background: #d1fae5; }
.flash-danger { background: #fee2e2; }
.flash-warning { background: #fef3c7; }
.flash-info { background: #dbeafe; }

.impersonation-banner {
  background: #92400e;
  color: #fff;
  padding: 0.65rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
}

.impersonation-stop-form {
  display: inline;
  margin: 0;
}

.btn-impersonation-stop {
  margin-top: 0;
  background: #fff;
  color: #92400e;
  border: none;
  min-height: 2.25rem;
  padding: 0.4rem 0.9rem;
}

.btn-impersonation-stop:hover,
.btn-impersonation-stop:focus-visible {
  background: #fef3c7;
}

label {
  display: block;
  margin-top: 0.75rem;
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  padding: 0.625rem 1.25rem;
  min-height: 2.75rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  background: #0b5fff;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.1s ease;
}

button:hover,
.btn:hover {
  background: #0948d4;
}

button:focus-visible,
.btn:focus-visible {
  outline: 2px solid #0b5fff;
  outline-offset: 2px;
}

.btn-secondary {
  background: #64748b;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-nav {
  margin-top: 0;
  padding: 0.4rem 0.75rem;
  min-height: 2.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-nav:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-copy {
  margin-top: 0;
  flex-shrink: 0;
  min-width: 5rem;
  padding: 0.625rem 1rem;
  background: #e2e8f0;
  color: #1e293b;
}

.btn-copy:hover {
  background: #cbd5e1;
}

.btn-copy--success {
  background: #d1fae5;
  color: #065f46;
}

.btn-table {
  margin-top: 0;
  padding: 0.4rem 0.85rem;
  min-height: 2.25rem;
  font-size: 0.875rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1.25rem;
}

.actions--toolbar {
  margin-top: 0;
  margin-bottom: 1rem;
}

.actions form {
  display: inline;
  margin: 0;
}

.actions .btn,
.actions button {
  margin-top: 0;
}

.card-narrow {
  max-width: 420px;
  margin: 0 auto 2rem;
}

.page-login main {
  max-width: 32rem;
}

.page-terms main {
  max-width: 40rem;
}

.terms-body {
  max-height: min(28rem, 60vh);
  overflow-y: auto;
  margin: 1rem 0 0;
  padding-right: 0.35rem;
}

.terms-body p,
.terms-body ul,
.terms-body ol {
  margin: 0 0 0.75rem;
}

.terms-body ul,
.terms-body ol {
  padding-left: 1.25rem;
}

.terms-body li {
  margin: 0.4rem 0;
}

.terms-body p:last-child,
.terms-body ul:last-child,
.terms-body ol:last-child {
  margin-bottom: 0;
}

.terms-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.terms-actions .btn {
  margin-top: 0;
  flex: 1 1 10rem;
}

.page-login .flash {
  border-radius: 8px;
  padding: 1.25rem;
}

.login-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.login-stack > .card {
  margin: 0;
  width: 100%;
  max-width: none;
}

.login-hero,
.login-form {
  max-width: none;
}

.login-hero {
  margin: 0 auto 1rem;
}

.login-hero h1,
.login-form h2 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
  line-height: 1.3;
}

.login-hero p,
.login-form p {
  margin: 0 0 0.75rem;
}

.login-hero p:last-child,
.login-form p:last-child {
  margin-bottom: 0;
}

.login-form .btn {
  width: 100%;
}

.credential-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1.25rem 0;
}

.credential-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.credential-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.credential-value-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.credential-value {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 0.85rem 1rem;
  font-size: 1.125rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.4;
  word-break: break-all;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  user-select: all;
  -webkit-user-select: all;
}

.credential-qr {
  text-align: center;
  margin: 1.5rem 0 0.5rem;
}

.credential-qr img {
  max-width: min(100%, 240px);
  height: auto;
  border-radius: 8px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

code {
  background: #f1f5f9;
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
}

.help-panel {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 1rem 1.1rem;
  margin: 0.75rem 0 1.25rem;
  font-weight: 400;
}

.help-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.help-panel p {
  margin: 0.5rem 0;
}

.help-panel ol,
.help-panel ul {
  margin: 0.4rem 0 0.6rem;
  padding-left: 1.25rem;
}

.help-panel li {
  margin: 0.35rem 0;
}

.help-note {
  color: #475569;
  font-size: 0.95rem;
}

.bulk-rows {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-height: 16rem;
}

.bulk-status {
  font-weight: 600;
}

.bulk-status-provisioned {
  color: #065f46;
}

.bulk-status-pending {
  color: #92400e;
}

.bulk-status-failed {
  color: #991b1b;
}

.field-hint {
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  font-weight: 400;
  color: #64748b;
}

.contact-edit {
  border-top: 1px solid #e2e8f0;
  padding: 1rem 0;
  margin-top: 0.5rem;
}

.contact-row {
  border-top: 1px solid #e2e8f0;
  padding: 0.85rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
}

.contact-row:first-of-type {
  border-top: none;
  padding-top: 0.25rem;
}

.contact-summary {
  flex: 1 1 220px;
  min-width: 0;
}

.contact-identity {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.contact-name {
  font-weight: 600;
}

.contact-email {
  word-break: break-all;
}

.permission-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
}

.permission-list li {
  font-size: 0.875rem;
}

.perm-yes::before {
  content: "✓ ";
  color: #15803d;
  font-weight: 700;
}

.perm-no {
  color: #64748b;
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
}

.contact-edit-details > form,
.contact-add-details > form {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 8px;
  min-width: min(100%, 320px);
}

summary.btn {
  margin-top: 0;
  list-style: none;
}

.contact-edit-details summary,
.contact-add-details summary {
  list-style: none;
  cursor: pointer;
}

.contact-edit-details summary::-webkit-details-marker,
.contact-add-details summary::-webkit-details-marker {
  display: none;
}

.contact-edit-details[open],
.contact-add-details[open] {
  flex-basis: 100%;
}

.contact-add-details {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e2e8f0;
}

.contact-edit h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.muted {
  color: #64748b;
  font-weight: 400;
}

.inline-form {
  display: inline;
}

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

.filter-grid label {
  margin-top: 0;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-actions .btn,
.filter-actions button {
  margin-top: 0;
}

.audit-table {
  font-size: 0.95rem;
}

.nowrap {
  white-space: nowrap;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin: 1rem 0 0;
}

.profile-users-table .profile-email-input {
  width: 100%;
  margin-top: 0;
}

.profile-role-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.profile-role-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0;
  font-weight: 400;
  white-space: nowrap;
}

.profile-user-actions {
  white-space: nowrap;
}

.profile-user-actions .btn,
.profile-user-actions button {
  margin-top: 0;
  margin-right: 0.35rem;
}

.profile-add-heading {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.1rem;
}

.profile-add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
}

.profile-add-email {
  flex: 1 1 220px;
  margin-top: 0;
}

.profile-add-email input {
  margin-top: 0;
}

.profile-add-row .btn {
  margin-top: 0;
}

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

.usage-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.usage-stat {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.usage-stat-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.usage-stat-value {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: #102a43;
}

.usage-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 720px) {
  .usage-charts {
    grid-template-columns: 1fr 1fr;
  }
}

.usage-chart-card {
  margin: 0;
  padding: 0.85rem 0.85rem 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.usage-chart-card figcaption {
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: #102a43;
}

.usage-chart {
  position: relative;
  width: 100%;
}

.usage-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.usage-chart-tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: #102a43;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.35;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(16, 42, 67, 0.25);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
  opacity: 0;
}

.usage-chart-tooltip.is-visible {
  opacity: 1;
}

.usage-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: #475569;
}

.usage-chart-legend i {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  margin-right: 0.35rem;
  vertical-align: -0.05rem;
}

@media (max-width: 640px) {
  main {
    margin: 1rem auto;
  }

  .card {
    padding: 1rem;
  }

  .site-header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-nav {
    width: 100%;
  }

  .credential-value-row {
    flex-direction: column;
  }

  .credential-value {
    font-size: 1rem;
  }

  .btn-copy {
    width: 100%;
    min-width: 0;
  }

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

  .actions .btn,
  .actions button,
  .actions form {
    width: 100%;
  }

  .actions form button {
    width: 100%;
  }

  .contact-actions {
    width: 100%;
  }

  .contact-actions .btn,
  .contact-actions button {
    flex: 1 1 auto;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn,
  .filter-actions button {
    flex: 1 1 auto;
  }

  .pagination {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .pagination .btn {
    width: 100%;
  }

  .terms-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .terms-actions .btn {
    width: 100%;
  }

  th, td {
    padding: 0.65rem 0.5rem;
    font-size: 0.9rem;
  }
}

.locale-switcher {
  margin: 0;
}

.locale-switcher select {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font: inherit;
}

.locale-switcher select option {
  color: #1a1a1a;
}

.bilingual-field {
  margin-bottom: 1rem;
}

.bilingual-field-label {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.bilingual-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.bilingual-col-label {
  display: block;
  font-size: 0.85rem;
  color: #627d98;
  margin-bottom: 0.25rem;
}

.bilingual-col input,
.bilingual-col textarea {
  width: 100%;
}

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