:root {
  --bg: #f5f7fa; --card: #ffffff; --text: #1f2933; --muted: #616e7c; --line: #dde3ea;
  --accent: #1d4ed8; --accent-text: #ffffff; --new: #fff8e1; --new-line: #f0b429; --bad: #c2410c;
  --tag: #e8eefc; --tag-text: #1e3a8a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --card: #1b2129; --text: #e4e7eb; --muted: #9aa5b1; --line: #2c3540;
    --accent: #5b8def; --accent-text: #0b1220; --new: #2a2414; --new-line: #c99a2e; --bad: #f08a5d;
    --tag: #23304a; --tag-text: #c7d6fb;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.top { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; justify-content: space-between;
  padding: .75rem 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.top nav a { text-decoration: none; }
.top nav form { margin: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-bottom: 1rem; }
.narrow { max-width: 460px; margin: 2rem auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.notice { background: var(--tag); color: var(--tag-text); padding: .5rem .75rem; border-radius: 6px; }
.bad { color: var(--bad); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
input, select { font: inherit; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); width: 100%; }
input[type=checkbox] { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: .5rem .75rem; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
legend { font-size: .9rem; padding: 0 .25rem; }
button, .button { font: inherit; cursor: pointer; padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); text-decoration: none; display: inline-block; text-align: center; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { background: none; border: none; padding: 0; color: var(--accent); }
button.link.bad { color: var(--bad); }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.row2 input { min-width: 0; padding: .45rem .3rem; font-size: .85rem; }

.layout { display: grid; grid-template-columns: 280px 1fr; gap: 1.25rem; align-items: start; }
.filters { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; position: sticky; top: 1rem; }
.filters summary { font-weight: 600; cursor: pointer; margin-bottom: .5rem; }
.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .75rem; }
.permits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.permit { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem;
  display: grid; grid-template-columns: 1fr 260px; gap: 1rem; }
.permit.new { background: var(--new); border-left: 4px solid var(--new-line); }
.permit h2 { margin: .35rem 0 .2rem; font-size: 1.05rem; }
.desc { margin: 0 0 .25rem; }
.p-top { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.tag { background: var(--tag); color: var(--tag-text); font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; font-weight: 600; }
.new-tag { background: var(--new-line); color: #1f1300; }
.p-contact { border-left: 1px solid var(--line); padding-left: 1rem; font-size: .92rem; overflow-wrap: anywhere; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

.actions-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.filter-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.filter-row input { flex: 1 1 240px; width: auto; }
.filter-row select { flex: 0 1 200px; width: auto; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.table-wrap { overflow-x: auto; }
table.plain { border-collapse: collapse; width: 100%; }
table.plain th, table.plain td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.inactive { opacity: .5; }
td.actions { display: flex; gap: .75rem; }
td.actions form { margin: 0; }

@media (max-width: 800px) {
  .layout, .admin-grid { grid-template-columns: 1fr; }
  .filters { position: static; }
  .filters:not([open]) { padding-bottom: .5rem; }
  .permit { grid-template-columns: 1fr; }
  .p-contact { border-left: none; border-top: 1px solid var(--line); padding: .75rem 0 0; }
  .results-head { flex-direction: column; }
}
