/*
 * Application styles for the server-rendered Keymaster UI.
 */

:root {
  color-scheme: light;
  --bg: #f4f5f6;
  --panel: #ffffff;
  --ink: #20262d;
  --muted: #6d7782;
  --line: #d9dde2;
  --line-dark: #c5cbd2;
  --accent: #0b7285;
  --accent-dark: #075b6a;
  --danger: #9d3224;
  --pending: #f7c948;
  --warn-bg: #fff6d8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.35;
}

button,
input,
textarea {
  font: inherit;
}

.page-shell {
  margin: 0 auto;
  max-width: 920px;
  padding: 24px;
}

.page-header {
  align-items: center;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.home-title-row {
  align-items: center;
  display: flex;
  gap: 10px;
}

.page-header h1,
.matrix-topbar h1 {
  font-size: 24px;
  line-height: 1.1;
  margin: 0;
}

.eyebrow,
.fingerprint,
.app-row small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.app-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.app-row {
  align-items: center;
  color: inherit;
  display: flex;
  justify-content: space-between;
  min-height: 58px;
}

.app-row-link {
  align-items: center;
  color: inherit;
  display: flex;
  flex: 1;
  justify-content: space-between;
  padding: 14px 16px;
  text-decoration: none;
}

.app-row + .app-row {
  border-top: 1px solid var(--line);
}

.app-row:hover {
  background: #edf7f8;
}

.app-row form {
  margin: 0 12px 0 0;
}

.access-shell {
  margin: 0 auto;
  max-width: 980px;
  padding: 28px 24px 48px;
}

.access-header,
.access-title-row,
.access-section-heading,
.access-binding,
.access-grant-command {
  align-items: center;
  display: flex;
}

.access-header {
  justify-content: space-between;
  margin-bottom: 20px;
}

.access-title-row {
  gap: 12px;
}

.access-title-row h1,
.access-section-heading h2 {
  margin: 0;
}

.access-title-row h1 {
  font-size: 24px;
}

.access-logo {
  height: 34px;
  width: 34px;
}

.access-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 16px;
}

.access-section-heading {
  border-bottom: 1px solid var(--line);
  justify-content: space-between;
  padding: 13px 15px;
}

.access-section-heading h2 {
  font-size: 16px;
}

.access-count {
  color: var(--muted);
  font-size: 12px;
}

.access-grant-form {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 15px;
}

.access-field {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 5px;
}

.access-field select {
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--ink);
  min-width: 0;
  padding: 7px 8px;
  width: 100%;
}

.access-grant-command {
  gap: 10px;
  grid-column: 1 / -1;
}

.access-empty {
  color: var(--muted);
  margin: 0;
  padding: 15px;
}

.access-binding-list {
  display: grid;
}

.access-binding {
  border-bottom: 1px solid var(--line);
  justify-content: space-between;
  padding: 12px 15px;
}

.access-binding:last-child {
  border-bottom: 0;
}

.access-binding strong,
.access-binding span,
.access-binding small {
  display: block;
  overflow-wrap: anywhere;
}

.access-binding span,
.access-binding small {
  color: var(--muted);
  font-size: 12px;
}

.matrix-shell {
  background: #eef0f2;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  position: relative;
}

.matrix-sidebar {
  background: #252b31;
  color: #f7f8f9;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  position: sticky;
  top: 0;
}

.sidebar-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-footer {
  border-top: 1px solid #3a424a;
  flex: 0 0 auto;
}

.account-menu-container {
  position: relative;
}

.sidebar-brand {
  border-bottom: 1px solid #3a424a;
  display: flex;
  justify-content: center;
  padding: 14px 0;
}

.brand-logo-full {
  display: block;
  height: auto;
  margin: 0 auto;
  max-width: 100%;
  object-fit: contain;
  width: 60%;
}

.sidebar-profile {
  align-items: center;
  background: transparent;
  border: 0;
  color: #f7f8f9;
  cursor: pointer;
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
}

.sidebar-profile:hover {
  background: #333b44;
}

.sidebar-profile strong,
.sidebar-profile small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-profile small {
  color: #aab3bc;
  font-size: 12px;
}

.sidebar-profile strong {
  color: #f7f8f9;
  font-size: 13px;
}

.avatar-circle {
  align-items: center;
  background: var(--avatar-color, var(--accent));
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  flex: 0 0 auto;
  font-weight: 700;
  height: 34px;
  justify-content: center;
  overflow: hidden;
  width: 34px;
}

.avatar-image {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.home-brand {
  align-items: center;
  display: flex;
  gap: 8px;
}

.home-brand-logo {
  height: 26px;
  object-fit: contain;
  width: 26px;
}

.current-user,
.home-profile-button {
  align-items: center;
  display: flex;
  gap: 10px;
}

.home-profile-button {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

.account-menu {
  background: #fff;
  border: 1px solid #d4dae0;
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(24, 35, 45, 0.18);
  min-width: 176px;
  opacity: 0;
  padding: 4px;
  pointer-events: none;
  position: absolute;
  transform: translateY(6px) scale(0.96);
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
  visibility: hidden;
  z-index: 20;
}

.account-menu.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.sidebar-account-menu-container .account-menu {
  bottom: calc(100% + 8px);
  left: 8px;
  transform-origin: bottom left;
}

.home-account-menu-container .account-menu {
  right: 0;
  top: calc(100% + 8px);
  transform-origin: top right;
}

.account-menu-item {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: #252b31;
  cursor: pointer;
  display: flex;
  font: inherit;
  gap: 9px;
  min-height: 36px;
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
  width: 100%;
}

.account-menu-icon {
  flex: 0 0 auto;
  height: 17px;
  width: 17px;
}

.account-menu-item:hover,
.account-menu-item:focus-visible {
  background: #e7f0ff;
  color: #0b57a7;
  outline: 0;
  transform: translateX(2px);
}

.account-menu-item:focus-visible {
  box-shadow: 0 0 0 2px #75a7e6;
}

.account-menu-sign-out {
  color: #b42318;
}

.account-menu-sign-out:hover,
.account-menu-sign-out:focus-visible {
  background: #fff0ee;
  color: #a51d14;
}

.account-menu-sign-out-form {
  margin: 0;
}

.account-menu-divider {
  border-top: 1px solid #e2e7ec;
  margin: 4px 6px;
}

.sidebar-app-list {
  display: grid;
  gap: 2px;
}

.sidebar-app {
  align-items: center;
  border-radius: 4px;
  color: #f7f8f9;
  display: flex;
  justify-content: space-between;
  min-height: 30px;
  padding: 6px 8px;
  text-decoration: none;
}

.sidebar-app:hover {
  background: #333b44;
}

.sidebar-app.active {
  background: #333b44;
  font-weight: 700;
}

.sidebar-app.disabled {
  color: #aab3bc;
  cursor: not-allowed;
}

.sidebar-app-actions {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.sidebar-config-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: #aab3bc;
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  height: 22px;
  justify-content: center;
  padding: 0;
  width: 22px;
}

.sidebar-config-button:hover {
  background: rgb(255 255 255 / 12%);
  color: #20262d;
}

.sidebar-section {
  border-bottom: 1px solid #3a424a;
  padding: 12px 14px;
}

.sidebar-section h2 {
  color: #aab3bc;
  font-size: 11px;
  font-weight: 700;
  margin: 0;
  text-transform: uppercase;
}

.sidebar-section-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.stage-cell-button,
.header-icon-button,
.app-remove-button,
.sidebar-add-button,
.pending-remove-button {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 30px;
  min-width: 30px;
  padding: 0 8px;
}

.app-remove-button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--danger);
  min-height: 30px;
  min-width: 30px;
  padding: 0;
}

.app-remove-button:hover {
  background: #f9e1de;
  border-color: #e6b0aa;
}

.sidebar-add-button {
  background: transparent;
  color: #8fc6be;
  min-height: 22px;
  min-width: 22px;
  padding: 0;
}

.sidebar-add-button:hover {
  background: #333b44;
}

.matrix-workspace {
  min-width: 0;
}

.matrix-topbar {
  align-items: center;
  background: #f8f9fa;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  min-height: 68px;
  padding: 14px 18px;
}

.matrix-topbar .eyebrow {
  color: var(--muted);
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.compact-button {
  margin-left: 10px;
  min-height: 32px;
}

.icon-toggle-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  min-height: 32px;
  min-width: 38px;
  padding: 0 8px;
}

.icon-toggle-button:hover {
  border-color: #9fb4b1;
}

.icon-toggle-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.icon-toggle-button .icon-eye-off {
  display: none;
}

.icon-toggle-button.active .icon-eye {
  display: none;
}

.icon-toggle-button.active .icon-eye-off {
  display: inline;
}

.matrix-layout {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  padding: 12px 12px 0;
}

.matrix-footer {
  align-items: center;
  background: #f8f9fa;
  border-top: 1px solid var(--line);
  bottom: 0;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
  position: sticky;
  /* Above the sticky key column (z-index 3) and header corner (4) so the
     last row doesn't bleed through the footer at the bottom of the scroll. */
  z-index: 5;
}

.footer-pending {
  color: var(--muted);
  font-weight: 700;
}

.footer-pending.has-pending {
  background: #fff4bf;
  border: 1px solid #e5c653;
  border-radius: 4px;
  color: #5e4700;
  padding: 6px 8px;
}

.footer-actions {
  display: flex;
  gap: 8px;
}

.footer-actions form {
  margin: 0;
}

.matrix-editor {
  min-width: 0;
}

.matrix-frame {
  background: var(--panel);
  border: 1px solid #c8ced5;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgb(16 24 32 / 5%);
  max-height: calc(100vh - 150px);
  overflow: auto;
}

.matrix-table {
  border-collapse: collapse;
  min-width: 1040px;
  table-layout: fixed;
  width: 100%;
}

.matrix-table th,
.matrix-table td {
  border-bottom: 1px solid #dde2e6;
  border-right: 1px solid #dde2e6;
  padding: 0;
  text-align: left;
  vertical-align: top;
}

.matrix-table th:last-child,
.matrix-table td:last-child {
  border-right: 0;
}

.matrix-table thead th {
  background: #2f6661;
  border-bottom: 1px solid #25534f;
  color: #fff;
  min-width: 215px;
  padding: 9px 10px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.matrix-table thead .key-column {
  background: #2b3138;
  left: 0;
  z-index: 4;
}

.matrix-table tbody .key-column {
  left: 0;
  position: sticky;
  z-index: 3;
}

.matrix-key-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.header-icon-button {
  background: #fff;
  color: var(--accent-dark);
}

.key-column {
  background: #f6f7f8;
  width: 270px;
}

.key-column[scope="row"] {
  padding: 10px 12px;
}

.key-name,
.environment-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* Key cell head: name (left, editable) + stacked action icons (top-right) */
.key-column-head {
  align-items: flex-start;
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.key-name-area {
  flex: 1 1 auto;
  min-width: 0;
}

.key-actions-stack {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 4px;
}

.key-icon-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  min-height: 26px;
  min-width: 26px;
  padding: 0;
}

.key-icon-button svg {
  height: 15px;
  width: 15px;
}

.key-icon-button:hover {
  border-color: #9fb4b1;
  color: var(--ink);
}

.key-icon-button.danger {
  color: var(--danger);
}

.key-icon-button.danger:hover {
  background: #fbeaea;
  border-color: var(--danger);
}

/* Inline key rename: double-click the name to edit (mirrors environment names) */
.key-name-display {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: text;
  display: block;
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
  padding: 2px 4px;
  text-align: left;
  width: 100%;
}

.key-name-display:hover,
.key-name-display:focus {
  border-color: var(--line-dark);
  outline: 0;
}

.key-name-display:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.key-name-display[hidden] {
  display: none;
}

.key-name-editor[hidden] {
  display: none;
}

.key-name-input {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  min-height: 30px;
  padding: 4px 6px;
  width: 100%;
}

.key-name-warning {
  color: var(--danger);
  font-size: 11px;
  margin: 4px 0 0;
}

.key-name-warning[hidden] {
  display: none;
}

.key-name-warning code {
  overflow-wrap: anywhere;
}

.environment-header {
  min-height: 31px;
}

.environment-name-display {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #fff;
  cursor: text;
  display: block;
  font-size: 14px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  padding: 3px 4px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.environment-name-display:hover,
.environment-name-display:focus {
  border-color: rgb(255 255 255 / 55%);
  outline: 0;
}

.environment-name-display:focus-visible {
  border-color: rgb(255 255 255 / 55%);
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.environment-name-editor {
  align-items: center;
  display: flex;
  gap: 5px;
}

.environment-name-editor[hidden] {
  display: none;
}

.environment-name-input {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  min-height: 30px;
  min-width: 0;
  padding: 5px 7px;
  width: 130px;
}

.key-description {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 4px;
}

.sensitivity {
  border-radius: 999px;
  display: inline-block;
  font-size: 11px;
  margin-top: 8px;
  padding: 2px 7px;
}

.sensitivity.sensitive {
  background: #fdecea;
  color: var(--danger);
}

.sensitivity.public {
  background: #e2f4f7;
  color: var(--accent-dark);
}

.fingerprint {
  color: #d7f5fa;
  margin: 3px 0 0;
  text-transform: none;
}

.cell-summary {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 24px;
  padding: 7px 9px 0;
}

.cell-status {
  color: #59636e;
  font-size: 12px;
  font-weight: 700;
  max-width: 135px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dirty-dot {
  background: var(--pending);
  border-radius: 999px;
  color: #3c2f00;
  font-size: 11px;
  padding: 2px 7px;
}

.cell-summary-actions {
  align-items: center;
  display: inline-flex;
  flex: 0 0 auto;
  gap: 6px;
}

.cell-inspect-button {
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  min-height: 22px;
  min-width: 22px;
  opacity: 0;
  padding: 0 5px;
  transition: opacity 120ms ease;
}

.matrix-cell:hover .cell-inspect-button,
.matrix-cell.selected-cell .cell-inspect-button {
  opacity: 1;
}

.cell-inspect-button:hover {
  border-color: #9fb4b1;
  color: var(--ink);
}

.cell-value {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 44px;
  padding: 5px 8px 8px;
}

.cell-value.editing {
  align-items: stretch;
  gap: 5px;
}

.cell-value.editing .value-button,
.cell-value.editing > .copy-button {
  display: none;
}

.value-button {
  background: transparent;
  border: 1px solid #e8ecef;
  border-radius: 4px;
  color: inherit;
  cursor: text;
  display: block;
  flex: 1;
  height: 34px;
  min-height: 31px;
  min-width: 0;
  overflow: hidden;
  padding: 6px 7px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

.value-button code {
  overflow: hidden;
  text-overflow: ellipsis;
}

.value-button.masked {
  color: var(--muted);
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  letter-spacing: 1px;
}

.value-button:focus {
  border-color: var(--accent);
  outline: 0;
}

.value-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.value-button:hover,
.copy-button:hover {
  border-color: #9fb4b1;
}

.copy-button {
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 11px;
  min-height: 30px;
  min-width: 30px;
  padding: 4px 7px;
}

.cell-value > .copy-button {
  opacity: 0;
  transition: opacity 120ms ease;
}

.matrix-cell:hover .cell-value > .copy-button,
.matrix-cell.selected-cell .cell-value > .copy-button,
.cell-value.editing > .copy-button {
  opacity: 1;
}

.value-display {
  background: #f4f6f7;
  border-radius: 4px;
  display: block;
  min-height: 31px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 7px;
  white-space: nowrap;
  word-break: normal;
}

.cell-editor {
  display: flex;
  flex: 1;
  gap: 5px;
  min-width: 0;
  position: relative;
}

.cell-editor[hidden] {
  display: none;
}

.matrix-input {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  flex: 1 1 auto;
  min-height: 31px;
  min-width: 0;
  padding: 5px 7px;
  width: 100%;
}

.inherit-menu {
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  box-shadow: 0 10px 22px rgb(0 0 0 / 18%);
  display: grid;
  gap: 2px;
  max-height: 240px;
  min-width: 170px;
  overflow: auto;
  padding: 4px;
  position: fixed;
  z-index: 70;
}

.inherit-menu[hidden] {
  display: none;
}

.inherit-menu-item {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 7px 9px;
  text-align: left;
  white-space: nowrap;
}

.inherit-menu-item:hover {
  background: #eef7f8;
}

.inherit-menu-item.current {
  color: var(--accent-dark);
  font-weight: 700;
}

.inherit-trigger-button {
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
  min-height: 31px;
  min-width: 31px;
  padding: 4px 7px;
}

.inherit-trigger-button:hover {
  border-color: #9fb4b1;
  color: var(--ink);
}

.matrix-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.matrix-cell {
  background: #fff;
  cursor: default;
  height: 82px;
}

.matrix-cell:hover {
  background: #f7fbfb;
}

.matrix-cell.selected-cell {
  box-shadow: inset 0 0 0 2px #3d7f78;
  position: relative;
}

.staged-cell {
  background: #fff8d6;
}

.staged-cell:hover {
  background: #fff4bf;
}

.edited-cell {
  background: #fffdf0;
}

.hidden-form {
  display: none;
}

.footer-apply-form {
  margin: 0;
}

.pending-remove-button {
  background: transparent;
  color: var(--muted);
  min-height: 24px;
  min-width: 24px;
  padding: 0;
}

.pending-remove-button:hover {
  background: #f7e7e4;
  color: var(--danger);
}

.production-warning {
  background: var(--warn-bg);
  border: 1px solid #ead38d;
  border-radius: 4px;
  margin: 0;
  padding: 8px;
}

.primary-button,
.secondary-button,
.link-button {
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  min-height: 32px;
  padding: 7px 10px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #ffffff;
  border-color: var(--line-dark);
  color: var(--ink);
  margin: 12px;
}

.no-margin {
  margin: 0;
}

.link-button {
  background: transparent;
  color: var(--muted);
  padding-inline: 0;
}

.danger-button {
  background: #fff;
  border: 1px solid #e6b0aa;
  border-radius: 4px;
  color: var(--danger);
  cursor: pointer;
  min-height: 32px;
  padding: 7px 10px;
}

.danger-button:hover {
  background: #f9e1de;
  border-color: #d99a91;
}

.primary-button.production-apply {
  background: var(--danger);
}

.primary-button.production-apply:hover {
  background: #7f271b;
}

.notice {
  background: #e2f4f7;
  border: 1px solid #a8d8d1;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 14%);
  left: 50%;
  margin: 0;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 12px;
  position: fixed;
  text-align: center;
  top: 18px;
  transform: translateX(-50%);
  width: max-content;
  z-index: 90;
}

.notice.alert {
  background: var(--warn-bg);
  border-color: #ead38d;
}

.notice[hidden] {
  display: none;
}

.toast {
  background: #0b7285;
  border: 1px solid #075b6a;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 18%);
  color: #fff;
  left: 50%;
  min-width: 220px;
  padding: 11px 14px;
  position: fixed;
  text-align: center;
  top: 18px;
  transform: translateX(-50%);
  z-index: 80;
}

.toast[hidden] {
  display: none;
}

.value-modal {
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  max-width: min(560px, 92vw);
  padding: 0;
  width: 540px;
}

.small-modal {
  width: 380px;
}

.environment-management-modal {
  width: min(680px, 94vw);
}

.value-modal::backdrop {
  background: rgb(0 0 0 / 35%);
}

.value-modal header {
  align-items: center;
  background: #eef1f4;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.value-modal h2 {
  font-size: 15px;
  margin: 0;
}

.value-modal pre {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-form {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.modal-form input[type="text"],
.modal-form input[type="file"],
.modal-form textarea {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  padding: 8px;
  width: 100%;
}

.modal-form label {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

.modal-form .field-label {
  align-items: stretch;
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 4px;
}

.modal-form footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.settings-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  min-height: 320px;
}

.settings-tabs {
  background: #f7f8f9;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
}

.settings-tab {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  padding: 8px;
  text-align: left;
}

.settings-tab:hover,
.settings-tab.active {
  background: #e7eaed;
  color: var(--ink);
}

.settings-content {
  min-width: 0;
}

.settings-panel {
  min-width: 0;
}

.settings-form {
  border-bottom: 1px solid var(--line);
}

.settings-danger-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.settings-danger-row span {
  color: var(--muted);
  font-size: 13px;
}

.environment-management-list {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
  padding: 12px;
}

.environment-add-form {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr);
}

.environment-add-form label {
  align-self: center;
}

.environment-add-form footer {
  grid-column: 1 / -1;
}

.environment-management-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 8px;
}

.environment-management-row > span {
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.environment-management-actions {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.environment-management-actions form {
  margin: 0;
}

.environment-management-lock {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.color-swatch-group {
  border: 0;
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.color-swatch-group legend {
  color: var(--muted);
  flex: 0 0 100%;
  font-size: 12px;
  margin-bottom: 2px;
}

.color-swatch {
  cursor: pointer;
  display: inline-flex;
}

.color-swatch input {
  position: absolute;
  opacity: 0;
}

.color-swatch span {
  background: var(--swatch-color);
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--line-dark);
  display: block;
  height: 24px;
  width: 24px;
}

.color-swatch input:checked + span {
  box-shadow: 0 0 0 3px var(--accent);
}

.profile-image-preview {
  align-items: center;
  display: flex;
  gap: 12px;
}

.profile-image-thumb {
  border-radius: 999px;
  display: block;
  height: 48px;
  object-fit: cover;
  width: 48px;
}

.modal-textarea {
  min-height: 360px;
  resize: both;
}

.empty-state,
.cell-error {
  background: var(--warn-bg);
  border: 1px solid #ead38d;
  border-radius: 4px;
  margin: 12px;
  padding: 10px 12px;
}

/* Workbench detail surface: one right slide-over hosting the inspector or the change review. */
.matrix-panel {
  background: #fff;
  border-left: 1px solid #c8ced5;
  box-shadow: -8px 0 24px rgb(16 24 32 / 12%);
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 92vw;
  overflow: hidden;
  position: fixed;
  right: 0;
  top: 0;
  transform: translateX(100%);
  transition: transform 160ms ease;
  width: 360px;
  z-index: 60;
}

.matrix-panel.open {
  transform: translateX(0);
}

.matrix-panel[hidden] {
  display: none;
}

.panel-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.panel-section[hidden] {
  display: none;
}

.panel-close {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  margin-left: auto;
  padding: 2px 8px;
}

.panel-close:hover {
  background: #eef1f4;
  color: var(--ink);
}

.inspector-panel,
.change-cart {
  background: #fff;
  overflow: hidden;
}

.panel-heading {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  padding: 12px 13px;
}

.panel-heading h2 {
  font-size: 16px;
  line-height: 1.2;
  margin: 0;
  overflow-wrap: anywhere;
}

.inspector-empty,
.cart-empty {
  color: var(--muted);
  padding: 13px;
}

.inspector-body[hidden],
.inspector-empty[hidden],
.inspector-reveal[hidden] {
  display: none;
}

.inspector-body {
  display: grid;
  gap: 13px;
  padding: 13px;
}

.inspector-facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.inspector-facts div {
  display: grid;
  gap: 2px;
}

.inspector-facts dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.inspector-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.sensitive-text {
  color: var(--danger);
  font-weight: 800;
}

.public-text {
  color: #176f5f;
  font-weight: 800;
}

.inspector-value-block,
.inspector-activity-block {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.inspector-value-heading {
  align-items: center;
  background: #f5f7f8;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: space-between;
  padding: 7px 9px;
  text-transform: uppercase;
}

.inspector-activity-summary {
  background: #f5f7f8;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  list-style-position: inside;
  padding: 7px 9px;
  text-transform: uppercase;
}

.inspector-activity-block[open] .inspector-activity-summary {
  border-bottom: 1px solid var(--line);
}

.inspector-value {
  display: block;
  max-height: 220px;
  min-height: 76px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.inspector-activity-list {
  display: grid;
  max-height: 260px;
  overflow: auto;
}

.inspector-activity-item {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding: 10px;
}

.inspector-activity-item:last-child {
  border-bottom: 0;
}

.inspector-activity-heading {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.inspector-activity-heading strong,
.inspector-activity-heading span,
.inspector-activity-item p,
.inspector-activity-item code {
  overflow-wrap: anywhere;
}

.inspector-activity-heading span,
.inspector-activity-item p {
  color: var(--muted);
  font-size: 12px;
}

.inspector-activity-item p {
  margin: 0;
}

.inspector-activity-item code {
  color: var(--accent-dark);
  font-size: 12px;
}

.inspector-history-value {
  background: #f7f9fa;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: block;
  max-height: 120px;
  overflow: auto;
  padding: 7px;
  white-space: pre-wrap;
}

.inspector-history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.inspector-activity-empty {
  color: var(--muted);
  margin: 0;
  padding: 10px;
}

.inspector-actions,
.change-cart-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.inspector-actions button[hidden],
.change-cart-actions [hidden] {
  display: none;
}

.inspector-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.change-cart-actions {
  border-bottom: 1px solid var(--line);
  padding: 12px 13px;
}

.change-cart-actions form {
  margin: 0;
}

.apply-context-form {
  display: grid;
  gap: 8px;
  width: 100%;
}

.apply-context-fields {
  display: grid;
  gap: 8px;
  width: 100%;
}

.apply-context-fields input {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  min-width: 0;
  padding: 7px 8px;
  width: 100%;
}

.apply-status {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 7px;
  margin: 0;
}

.apply-status[hidden] {
  display: none;
}

.apply-status::before {
  animation: apply-status-spin 700ms linear infinite;
  border: 2px solid #b7c3c5;
  border-right-color: var(--accent);
  border-radius: 50%;
  content: "";
  height: 13px;
  width: 13px;
}

.apply-context-form .primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

@keyframes apply-status-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .apply-status::before {
    animation: none;
  }
}

.cart-list {
  max-height: 420px;
  overflow: auto;
}

.cart-change {
  border-bottom: 1px solid var(--line);
  padding: 11px 13px;
}

.cart-change:last-child {
  border-bottom: 0;
}

.cart-change-heading {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.cart-change-heading strong,
.cart-change-heading span {
  display: block;
  overflow-wrap: anywhere;
}

.cart-change-heading span,
.cart-change p {
  color: var(--muted);
  font-size: 12px;
}

.cart-change p {
  margin: 8px 0;
}

.change-cart .production-warning {
  margin: 12px 13px 0;
}

@media (max-width: 980px) {
  .matrix-shell {
    grid-template-columns: 1fr;
  }

  .matrix-sidebar {
    height: auto;
    min-height: auto;
    position: static;
  }

  .matrix-frame {
    max-height: none;
  }
}

/* Landing page (logged-out root) */
.landing {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.landing-nav {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1080px;
  padding: 18px 24px;
  width: 100%;
}

.landing-nav-brand {
  align-items: center;
  display: flex;
  font-weight: 700;
  gap: 9px;
}

.landing-nav-logo {
  height: 26px;
  object-fit: contain;
  width: 26px;
}

.landing-nav-links {
  display: flex;
  gap: 18px;
}

.landing-nav-link {
  color: var(--muted);
  text-decoration: none;
}

.landing-nav-link:hover {
  color: var(--ink);
}

.landing-main {
  flex: 1;
  margin: 0 auto;
  max-width: 1080px;
  padding: 8px 24px 48px;
  width: 100%;
}

.landing-hero {
  margin: 0 auto;
  max-width: 680px;
  padding: 40px 0 28px;
  text-align: center;
}

.landing-hero-logo {
  height: auto;
  max-width: 320px;
  width: 60%;
}

.landing-eyebrow {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  margin: 18px 0 6px;
  text-transform: uppercase;
}

.landing-title {
  font-size: 34px;
  line-height: 1.1;
  margin: 0 0 14px;
}

.landing-lede {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
  margin: 0 auto 22px;
  max-width: 600px;
}

.landing-cta {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.landing-signin {
  align-items: center;
  display: inline-flex;
  min-height: 40px;
  padding: 0 18px;
  text-decoration: none;
}

.landing-arch-link {
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
}

.landing-arch-link:hover {
  text-decoration: underline;
}

.landing-overview {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  margin: 8px auto 0;
  max-width: 720px;
  padding: 26px 0 6px;
  text-align: center;
}

.landing-features {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, 1fr);
  margin: 24px 0 0;
}

.landing-feature {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
}

.landing-feature h2 {
  font-size: 15px;
  margin: 0 0 6px;
}

.landing-feature p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

.landing-feature code,
.landing-lede code {
  background: #eef1f4;
  border-radius: 4px;
  font-size: 0.92em;
  padding: 1px 5px;
}

.landing-footer {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 13px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1080px;
  padding: 18px 24px;
  width: 100%;
}

/* Logged-in empty state (no apps) */
.empty-shell {
  min-height: 60vh;
}

.empty-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 48px auto 0;
  max-width: 520px;
  padding: 32px;
  text-align: center;
}

.empty-panel h1 {
  font-size: 20px;
  margin: 0 0 8px;
}

.empty-panel p {
  color: var(--muted);
  margin: 0 0 18px;
}

/* Architecture page */
.arch-page {
  margin: 0 auto;
  max-width: 1200px;
  padding: 18px 24px 48px;
}

.arch-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 0 0 12px;
}

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

.arch-intro {
  margin: 12px 0 18px;
  max-width: 820px;
}

.arch-intro h1 {
  font-size: 26px;
  margin: 2px 0 10px;
}

.arch-lede {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.arch-diagram {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}

.arch-diagram svg {
  display: block;
  height: auto;
  width: 100%;
}

.arch-notes {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, 1fr);
  margin: 22px 0 0;
}

.arch-notes h2 {
  font-size: 15px;
  margin: 0 0 6px;
}

.arch-notes p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.arch-notes code {
  background: #eef1f4;
  border-radius: 4px;
  font-size: 0.92em;
  padding: 1px 5px;
}

@media (max-width: 860px) {
  .landing-features,
  .arch-notes {
    grid-template-columns: 1fr;
  }

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

/* Matrix key search + pagination toolbar */
.matrix-toolbar {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 12px 0;
}

.matrix-search {
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  max-width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  width: 300px;
}

.matrix-search:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.matrix-toolbar-right {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 16px;
}

.matrix-page-size {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  gap: 6px;
  white-space: nowrap;
}

.matrix-page-size select {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--ink);
  min-height: 30px;
  padding: 4px 6px;
}

.matrix-pagination {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.matrix-pagination[hidden] {
  display: none;
}

.matrix-page-info {
  color: var(--muted);
  font-size: 12px;
}

.pager-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 15px;
  justify-content: center;
  line-height: 1;
  min-height: 30px;
  min-width: 30px;
}

.pager-button:hover:not(:disabled) {
  border-color: #9fb4b1;
}

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

.matrix-empty-filter {
  background: var(--warn-bg);
  border: 1px solid #ead38d;
  border-radius: 4px;
  color: var(--ink);
  margin: 12px;
  padding: 10px 12px;
}

.matrix-empty-filter[hidden] {
  display: none;
}
