:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17251f;
  background: #f2f5f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #dbe9df 0, transparent 42rem), #f2f5f0;
}

button, input, select { font: inherit; }

button, .button-link {
  border: 0;
  border-radius: .75rem;
  background: #245c43;
  color: white;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  padding: .75rem 1rem;
  text-decoration: none;
}

button:hover, .button-link:hover { background: #194832; }
button:disabled { cursor: not-allowed; opacity: .5; }
button.secondary { background: #e3e9e4; color: #17251f; }
button.danger { background: #973c3c; }

.shell { margin: 0 auto; max-width: 72rem; padding: clamp(1rem, 4vw, 3rem); }
.admin-shell { max-width: 108rem; padding-inline: clamp(1rem, 2vw, 2rem); }
.auth-card, .admin-panel, dialog {
  background: rgba(255, 255, 255, .96);
  border: 1px solid #d5ded7;
  border-radius: 1.25rem;
  box-shadow: 0 1rem 3rem rgba(25, 72, 50, .09);
}

.auth-card { margin: 8vh auto 0; max-width: 29rem; padding: clamp(1.5rem, 5vw, 2.5rem); }
h1, h2, p { margin-top: 0; }
.eyebrow { color: #397358; font-size: .76rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.help { color: #5a6a61; line-height: 1.55; }
.error, .notice { border-radius: .7rem; padding: .8rem 1rem; }
.error { background: #fff0f0; color: #922f2f; }
.notice { background: #e6f2e9; color: #245c43; }

form { display: grid; gap: 1rem; }
label { display: grid; font-size: .9rem; font-weight: 650; gap: .4rem; }
input, select {
  background: #fff;
  border: 1px solid #b9c7bd;
  border-radius: .65rem;
  min-width: 0;
  padding: .72rem .8rem;
}
input:focus, select:focus { border-color: #397358; outline: 3px solid #dbe9df; }
.text-link { color: #245c43; font-weight: 650; }
.auth-card .text-link { display: inline-block; margin-top: 1rem; }

.admin-header, .panel-heading, .dialog-heading, .dialog-actions, .user-heading, .user-actions {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}
.admin-header nav { display: flex; gap: 1rem; }
.admin-panel { padding: clamp(1rem, 3vw, 2rem); }
.admin-panel + .admin-panel { margin-top: 1rem; }
.user-meta { color: #69776f; font-size: .85rem; font-weight: 500; }
.active-field { align-items: center; display: flex; gap: .5rem; }
.active-field input, .permission input { min-width: auto; }
fieldset { border: 1px solid #d5ded7; border-radius: .8rem; margin: 0; padding: 1rem; }
legend { font-weight: 750; padding: 0 .35rem; }
.permission-grid { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.permission { align-items: center; display: flex; font-weight: 500; gap: .55rem; }

.visually-hidden {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.permission-matrix-wrap {
  border: 1px solid #d5ded7;
  border-radius: 1rem;
  max-width: 100%;
  overflow-x: auto;
}
.permission-matrix-wrap:focus { outline: 3px solid #dbe9df; outline-offset: 2px; }
.permission-matrix {
  border-collapse: separate;
  border-spacing: 0;
  min-width: max-content;
}
.permission-matrix th, .permission-matrix td { border-bottom: 1px solid #d5ded7; }
.permission-matrix tbody tr:last-child th, .permission-matrix tbody tr:last-child td { border-bottom: 0; }
.permission-matrix thead th { background: #edf3ee; text-align: center; }
.permission-matrix .matrix-category-column {
  border-left: 1px solid #d5ded7;
  color: #245c43;
  letter-spacing: .08em;
}
.permission-matrix .matrix-app-column {
  border-left: 1px solid #d5ded7;
  hyphens: auto;
  max-width: 4.5rem;
  min-width: 3.75rem;
  overflow-wrap: anywhere;
  text-transform: none;
  width: 3.75rem;
  white-space: normal;
}
.matrix-user-column, .matrix-user-cell {
  background: #fff;
  box-shadow: .35rem 0 .7rem rgba(25, 72, 50, .06);
  left: 0;
  min-width: 18rem;
  position: sticky;
  width: 18rem;
  z-index: 2;
}
.permission-matrix thead .matrix-user-column { background: #edf3ee; z-index: 3; }
.matrix-user-cell { padding: 1rem; text-align: left; text-transform: none; white-space: normal; }
.matrix-name-field { gap: .3rem; }
.matrix-name-field > span, .matrix-user-controls label > span { color: #5a6a61; font-size: .75rem; text-transform: uppercase; }
.matrix-user-cell > .user-meta { display: block; margin-top: .35rem; }
.matrix-user-controls {
  align-items: end;
  display: grid;
  gap: .75rem;
  grid-template-columns: minmax(8rem, 1fr) auto;
  margin-top: .75rem;
}
.matrix-user-controls select { padding: .55rem .65rem; }
.matrix-permission-cell { border-left: 1px solid #e4eae5; text-align: center; }
.matrix-checkbox { align-items: center; display: inline-flex; justify-content: center; }
.matrix-checkbox input { cursor: pointer; height: 1.2rem; min-width: auto; width: 1.2rem; }
.matrix-actions-column { min-width: 11rem; }
.matrix-actions-cell { padding: 1rem; }
.matrix-actions { display: grid; gap: .6rem; }
.matrix-actions button { padding: .6rem .75rem; white-space: nowrap; }

dialog { border: 0; max-height: 90vh; max-width: 46rem; overflow: auto; padding: 1.5rem; width: calc(100% - 2rem); }
dialog::backdrop { background: rgba(10, 24, 16, .48); }
.icon-button { background: transparent; color: #17251f; font-size: 1.5rem; padding: .25rem .5rem; }
.temporary-password { background: #edf2ed; border-radius: .75rem; display: block; font-family: ui-monospace, monospace; margin: 1rem 0; overflow-wrap: anywhere; padding: 1rem; user-select: all; }
.audit-table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid #d5ded7; padding: .7rem; text-align: left; white-space: nowrap; }
th { color: #5a6a61; font-size: .78rem; text-transform: uppercase; }

@media (max-width: 700px) {
  .admin-header, .panel-heading { align-items: flex-start; flex-direction: column; }
  .matrix-user-column, .matrix-user-cell { min-width: 15rem; width: 15rem; }
}
