:root {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.5;
  color: #0f172a;
  background-color: #f4f7fb;
}

body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #eef2ff, #fef3c7);
  min-height: 100vh;
}

main {
  width: min(3000px, calc(100vw - 3rem));
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

header {
  background: #1d4ed8;
  color: white;
  padding: 1.5rem 1rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
}

h1,
h2,
h3 {
  margin-top: 0;
}

.card {
  background: white;
  border-radius: 18px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  width: 100%;
  box-sizing: border-box;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

button.secondary {
  background: #f87171;
}

form {
  display: grid;
  gap: 0.75rem;
}

label {
  font-weight: 600;
  color: #475569;
}

input,
select,
textarea {
  border: 1px solid #cbd5f5;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  background: #f8fafc;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

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

table th {
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  color: #64748b;
}

.status {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.status.ok {
  background: #dcfce7;
  color: #166534;
}

.status.error {
  background: #fee2e2;
  color: #b91c1c;
}

.badge {
  background: #e0e7ff;
  color: #1d4ed8;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
}

code {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 0.15rem 0.35rem;
  font-size: 0.85rem;
}

.form-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.form-table th {
  text-align: left;
  width: 160px;
  color: #475569;
  padding: 0.35rem 0.5rem 0.35rem 0;
}

.form-table td {
  padding: 0.35rem 0;
}

.table-select-cell {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.user-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.user-cell span {
  font-size: 0.85rem;
  color: #475569;
}

.perm-checkboxes {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.form-actions.space-between {
  justify-content: space-between;
}

.form-actions-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pill-chip {
  border-radius: 999px;
  padding: 0.2rem 0.8rem;
  font-size: 0.85rem;
  background: #e2e8f0;
  color: #475569;
}

.pill-chip.allowed {
  background: #dcfce7;
  color: #166534;
}

.pill-chip.denied {
  background: #fee2e2;
  color: #b91c1c;
}

.hidden {
  display: none !important;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

textarea.small {
  min-height: 120px;
}

.muted {
  color: #64748b;
}

.muted.small {
  font-size: 0.85rem;
}

.double-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.double-grid.align-start {
  align-items: flex-start;
}

.builder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  align-items: flex-start;
}

.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.ghost {
  background: transparent;
  color: #2563eb;
  border: 1px dashed #bfdbfe;
  padding: 0.35rem 0.8rem;
}

.resource-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.resource-pill {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  min-width: 160px;
  background: #f8fafc;
}

.kv-list {
  margin-top: 0.5rem;
}

.kv-row,
.filter-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.kv-row input,
.filter-row input {
  flex: 1;
}

.filter-row select {
  width: 110px;
}

.icon-button {
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  background: #e2e8f0;
  color: #475569;
}

.table-wrapper {
  overflow-x: auto;
}

details {
  margin-top: 1rem;
}

.dialog-buttons {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.dialog-buttons .spacer {
  flex: 1;
}

#record-dialog {
  border: none;
  border-radius: 20px;
  padding: 1.5rem;
  max-width: 760px;
  width: 92%;
}

#record-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-field-list {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.5rem;
  margin-top: 1rem;
}

.dialog-field-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.4fr) 42px;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.dialog-field-row .record-field-name[readonly] {
  background: #eef2ff;
  color: #475569;
  font-weight: 600;
}

.dialog-field-row input {
  width: 100%;
}

.table-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.table-actions button {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
}

.table-actions .danger {
  background: #fee2e2;
  color: #b91c1c;
}

.table-actions .neutral {
  background: #e0f2fe;
  color: #0369a1;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.result-table th,
.result-table td {
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
