:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #172026;
  --muted: #62707c;
  --line: #d8dde3;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.app-header nav,
.actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
}

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

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

.auth-shell {
  min-height: 80vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  align-items: center;
  gap: 48px;
}

.panel,
table,
.details,
.error-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel { padding: 24px; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  background: #fff;
}

input[type="submit"],
.button,
button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.button:hover { color: #fff; text-decoration: none; background: var(--accent-dark); }
.danger { background: var(--danger); color: #fff; }
.link-button { background: transparent; color: var(--accent-dark); padding: 0; }

.flash {
  border-radius: 6px;
  padding: 12px 14px;
  background: #e8f5f3;
  color: #0f514b;
}

.flash.alert,
.error-box {
  background: #fff1f0;
  color: var(--danger);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.metric-grid span,
.page-title p,
dt {
  color: var(--muted);
}

.metric-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

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

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th { background: #eef2f5; }

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

.form-grid textarea,
.form-actions,
.error-box {
  grid-column: 1 / -1;
}

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

.checkbox input { width: auto; }

.details {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  padding: 18px;
  gap: 12px 18px;
}

.details dd { margin: 0; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
}

.inline-form {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

@media (max-width: 720px) {
  .app-header,
  .page-title,
  .auth-shell,
  .split {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .app-header { display: grid; padding: 14px 16px; }
  .details { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}

/* ── RBAC / activity additions ─────────────────────────────── */

.pad { padding: 24px; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
  grid-column: span 1;
}

fieldset:last-of-type { grid-column: 1 / -1; }

legend {
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 6px;
}

.filters {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 18px;
}

.filters label { min-width: 180px; flex: 1; }
.filters label:has(input[type="checkbox"]) {
  display: flex; align-items: center; gap: 8px; min-width: auto; flex: 0;
}
.filters input[type="submit"],
.filters .button { flex: 0; }
.filters a { align-self: center; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  background: #eef2f5;
  color: var(--muted);
}

.pill.ok { background: #e8f5f3; color: #0f514b; }
.pill.danger { background: #fff1f0; color: var(--danger); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }

.whoami {
  color: var(--muted);
  font-size: 13px;
  margin-left: auto;
  white-space: nowrap;
}

.pagination {
  margin: 18px 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pagination a,
.pagination .page,
.pagination .gap {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.pagination .current { background: var(--accent); color: #fff; }

.permission-group h3 { margin-bottom: 6px; }
.permission-row { display: flex; flex-wrap: wrap; gap: 10px; }

.permission-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.permission-cell input { width: auto; }
