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

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  border-bottom: 1px solid #d7dde2;
  background: #ffffff;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 650;
}

h2 {
  font-size: 18px;
}

.muted {
  margin-top: 4px;
  color: #64717d;
  font-size: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid #d7dde2;
}

.tab {
  min-height: 40px;
  border-color: transparent;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: #54616d;
}

.tab.active {
  border-color: #d7dde2;
  border-bottom-color: #ffffff;
  background: #ffffff;
  color: #182029;
}

.tab-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.tab-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

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

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 32px;
  overflow: hidden;
}

.surface {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid #d7dde2;
  border-radius: 8px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid #e8edf1;
}

.grant-form,
.environment-form,
.audit-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 240px) minmax(180px, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid #e8edf1;
}

.audit-form {
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 160px) auto;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.state-tools {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.compact-button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.generated-key {
  display: grid;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid #e8edf1;
  background: #f4faf7;
  color: #183f30;
  font-size: 13px;
}

.generated-key code,
td code {
  display: inline-block;
  max-width: 520px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}

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

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid #e8edf1;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafb;
  color: #54616d;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

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

.flag-key {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 650;
}

.flag-description {
  display: block;
  max-width: 520px;
  margin-top: 4px;
  color: #64717d;
  font-size: 13px;
}

.flag-meta {
  display: block;
  margin-top: 4px;
  color: #7d8790;
  font-size: 12px;
}

.archived {
  color: #7d8790;
  background: #fafafa;
}

.key-list {
  display: grid;
  gap: 10px;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.key-row code {
  overflow-wrap: anywhere;
}

.key-meta {
  color: #64717d;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  min-height: 36px;
  border: 1px solid #b8c2cc;
  border-radius: 6px;
  background: #ffffff;
  color: #182029;
  font: inherit;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #eef3f5;
}

button:disabled {
  color: #98a3ad;
  cursor: not-allowed;
}

.danger {
  border-color: #d78a7d;
  color: #a83828;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #c7d0d8;
  border-radius: 999px;
  transition: background 140ms ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #ffffff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 24%);
  transition: transform 140ms ease;
}

.switch input:checked + .slider {
  background: #20815d;
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.switch input:disabled + .slider {
  cursor: not-allowed;
  opacity: .52;
}

.empty {
  padding: 28px;
  color: #64717d;
  text-align: center;
}

.login-page {
  min-height: 100vh;
  overflow: auto;
  background:
    linear-gradient(135deg, rgb(32 129 93 / 10%), transparent 40%),
    #f5f7f8;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 22px;
  padding: 28px;
  border: 1px solid #d7dde2;
  border-radius: 8px;
  background: #ffffff;
}

.login-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid #b8c2cc;
  border-radius: 6px;
  background: #ffffff;
  color: #182029;
  font-weight: 700;
  text-decoration: none;
}

.login-button:hover {
  background: #eef3f5;
}

.login-button.disabled {
  color: #7d8790;
  cursor: not-allowed;
  background: #f1f4f6;
}

.login-button.disabled:hover {
  background: #f1f4f6;
}

.login-error {
  padding: 12px 14px;
  border: 1px solid #d78a7d;
  border-radius: 6px;
  background: #fff7f5;
  color: #a83828;
  font-size: 14px;
}

.google-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #1a73e8;
  color: #ffffff;
  font-weight: 800;
}

.login-note {
  margin: 0;
  color: #64717d;
  font-size: 13px;
}

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid #cfd7df;
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgb(18 25 32 / 42%);
}

form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

label {
  display: grid;
  gap: 6px;
  color: #4e5b66;
  font-size: 13px;
  font-weight: 650;
}

.field-hint {
  color: #64717d;
  font-size: 12px;
  font-weight: 500;
}

input, textarea {
  width: 100%;
  border: 1px solid #bac4cc;
  border-radius: 6px;
  color: #182029;
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bac4cc;
  border-radius: 6px;
  background: #ffffff;
  color: #182029;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 4px 0 0;
  padding: 0;
}

.message {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border: 1px solid #b8c2cc;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgb(24 32 41 / 18%);
  font-size: 14px;
}

.message.error {
  border-color: #d78a7d;
  color: #a83828;
}

@media (max-width: 780px) {
  body {
    overflow: hidden;
  }

  .topbar,
  .section-header,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    padding: 20px;
  }

  main {
    padding: 18px;
  }

  .tab-panels,
  .tab-panel {
    min-height: 0;
  }

  .grant-form,
  .environment-form,
  .audit-form {
    grid-template-columns: 1fr;
  }
}
