:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #fff;
  --line: #d7dce2;
  --text: #1d252d;
  --muted: #667085;
  --accent: #1f6f5f;
  --accent-soft: #e8f3ef;
  --warn: #9a5b00;
  --bad: #b42318;
  --ok: #067647;
  --admin: #253858;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.42 system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.pem-header,
header {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.pem-brand,
.brand {
  font-weight: 750;
  letter-spacing: 0;
}

.pem-brand small,
.brand small {
  color: var(--muted);
  font-weight: 600;
  margin-left: 8px;
}

.pem-user,
.user {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.pem-shell,
.shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100vh - 54px);
}

.pem-nav,
nav {
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  overflow: auto;
  gap: 2px;
  padding: 8px 12px;
}

.pem-nav a,
nav a {
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 6px;
  margin: 0;
  white-space: nowrap;
}

.pem-nav a:hover,
.pem-nav a.active,
nav a:hover,
nav a.active {
  background: var(--accent-soft);
  color: #155b4e;
}

.pem-main,
main {
  min-width: 0;
  padding: 18px 22px 42px;
}

h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
a { color: #17695b; }

.muted { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric,
.pem-panel,
.panel,
.pem-card,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.metric { padding: 12px; }
.metric .num { font-size: 23px; font-weight: 750; }
.metric .label { color: var(--muted); font-size: 12px; margin-top: 2px; }

.pem-panel,
.panel {
  padding: 12px;
  margin-bottom: 14px;
  overflow: auto;
}

.pem-narrow {
  max-width: 620px;
}

.cards,
.pem-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 10px;
}

.pem-card,
.card {
  padding: 12px;
  min-width: 0;
}

.card-title { font-weight: 720; margin-bottom: 4px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.pem-status,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafb;
  color: #344054;
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok,
.pem-status[data-status="done"],
.pem-status[data-status="paid"],
.pem-status[data-status="confirmed_paid"] {
  color: var(--ok);
  background: #edf8f2;
  border-color: #bbdec8;
}

.badge.warn,
.pem-status[data-status="warn"],
.pem-status[data-status="open"] {
  color: var(--warn);
  background: #fff6e6;
  border-color: #f0d08a;
}

.badge.bad,
.pem-status[data-status="problem"] {
  color: var(--bad);
  background: #fff0ee;
  border-color: #f2b8b5;
}

.pem-table,
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #edf0f3;
  padding: 7px 8px;
  vertical-align: top;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #4b5563;
  font-weight: 700;
  background: #fafbfc;
  position: sticky;
  top: 0;
}

td.wrap {
  white-space: normal;
  min-width: 220px;
}

.pem-toolbar,
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.pem-subnav {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.pem-subnav a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}

.pem-subnav a:hover,
.pem-subnav a.active {
  background: var(--accent-soft);
  color: #155b4e;
}

input,
select,
button,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}

input,
select,
button {
  height: 34px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 130px;
  padding: 9px 10px;
  resize: vertical;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid #1f2937;
  border-radius: 6px;
  background: #1f2937;
  color: #fff;
  padding: 0 12px;
  text-decoration: none;
  cursor: pointer;
}

button.secondary,
.button.secondary {
  background: #fff;
  color: #1f2937;
  border-color: var(--line);
}

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

label {
  display: block;
  font-size: 12px;
  color: #475467;
  font-weight: 650;
  margin-bottom: 4px;
}

.field { margin-bottom: 10px; }
.field input,
.field select { width: 100%; }

details {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  margin-bottom: 9px;
}

summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
}

details .inside { padding: 0 12px 12px; }

.flash {
  background: #e8f3ef;
  border: 1px solid #b9d8cf;
  border-radius: 7px;
  padding: 9px 11px;
  margin-bottom: 12px;
}

.admin-band { border-left: 4px solid var(--admin); }
.danger { color: var(--bad); }
.mobile-only { display: none; }
.desktop-only { display: block; }

@media (max-width: 820px) {
  .pem-header,
  header { padding: 0 12px; }

  .pem-brand small,
  .brand small { display: none; }

  .pem-nav,
  nav { padding: 8px; }

  .pem-main,
  main { padding: 14px 12px 34px; }

  .cards,
  .pem-cards { grid-template-columns: 1fr; }

  table { min-width: 720px; }
  .mobile-only { display: block; }
  .desktop-only { display: none; }
}
