:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #17212f;
  --muted: #5d6b7e;
  --line: #e1e6ee;
  --navy: #13294b;
  --navy-2: #1c3a66;
  --accent: #1f6fd1;
  --accent-soft: #e7f0fc;
  --green: #18794e; --green-soft: #e3f4ea;
  --amber: #9a5b00; --amber-soft: #fdf1dc;
  --red: #b42318; --red-soft: #fde8e6;
  --gray-soft: #eef1f5;
  --purple: #5b3cc4; --purple-soft: #efeafd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: var(--navy); color: #cfd8e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: #13294b; box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); overflow: hidden; color: #fff; font-weight: 800; display: grid; place-items: center; letter-spacing: .5px; }
.logo svg { width: 100%; height: 100%; display: block; }
.brand-name { color: #fff; font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: #8fa3c0; }
nav { padding: 6px 8px; overflow-y: auto; flex: 1; }
nav a { display: block; color: #cfd8e6; padding: 8px 12px; border-radius: 7px; margin: 1px 0; font-weight: 500; }
nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
nav a.active { background: #2a4f86; color: #fff; }
[data-states][hidden] { display: none !important; }
.overdue { color: var(--red); font-weight: 600; }
.appeal { padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.appeal:last-child { border-bottom: 0; }
.appeal .list-item { border-bottom: 0; padding-bottom: 2px; }
.appeal-meta { margin-top: -2px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7d90ad; padding: 14px 12px 4px; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid #22406d; font-size: 12.5px; }
.sidebar-foot a { color: #9cc3ff; }
.demo-tag { margin-top: 6px; color: #7d90ad; font-size: 11px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; }
.muni-select { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.muni-select select { font-size: 14px; font-weight: 600; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.top-right { margin-left: auto; color: var(--muted); font-size: 13px; }
.view { padding: 22px 24px 60px; max-width: 1280px; width: 100%; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 3px; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
/* Two cards side by side while both fit at their narrowest; otherwise they stack. */
.grid-2 { display: flex; flex-wrap: wrap; }
.grid-2 > * { flex: 1 1 0; }
.grid-2 > .card + .card { margin-top: 0; }
.grid-3 { grid-template-columns: 2fr 1fr; }
/* Grid columns and form controls shrink to fit, so a long option (some states' permit type names are long) can't widen the page. */
.grid > * { min-width: 0; }
.form select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: #c4d3e8; }
.stat .n { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.stat.warn .n { color: var(--amber); }
.stat.bad .n { color: var(--red); }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: #f7f9fc; }
.t .num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.small { font-size: 12.5px; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--gray-soft); color: #3b4758; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--gray-soft); color: var(--muted); margin-left: 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #185fb5; }
.btn.danger { color: var(--red); border-color: #f2c4bf; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cdd5e0; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d3f7; border-color: var(--accent); }
.search { min-width: 260px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.workflow { display: flex; gap: 0; margin: 4px 0 16px; overflow-x: auto; }
.step { flex: 1; min-width: 110px; text-align: center; font-size: 12px; color: var(--muted); position: relative; padding-top: 22px; }
.step::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 3px; background: var(--line); }
.step .dot { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 17px; height: 17px; border-radius: 50%; background: #fff; border: 3px solid var(--line); z-index: 1; }
.step.done { color: var(--ink); }
.step.done::before { background: var(--accent); }
.step.done .dot { background: var(--accent); border-color: var(--accent); }
.step.current { color: var(--accent); font-weight: 700; }
.step.current .dot { border-color: var(--accent); }
.step.alert .dot { border-color: var(--red); background: var(--red); }
.step.alert { color: var(--red); font-weight: 700; }

.list-item { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.list-item:last-child { border-bottom: 0; }
.feed { font-size: 13px; }
.feed .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
.alert-box { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13.5px; }
.alert-box.red { background: var(--red-soft); color: var(--red); }
.alert-box.amber { background: var(--amber-soft); color: var(--amber); }
.alert-box.blue { background: var(--accent-soft); color: #164b8c; }

.photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photos a img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.checklist { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; }
.checklist li { padding: 2px 0; }
.checklist .pass { color: var(--green); }
.checklist .fail { color: var(--red); }
.checklist .na { color: var(--muted); }
details.insp > summary { cursor: pointer; list-style: none; }
details.insp > summary::-webkit-details-marker { display: none; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; }
.modal header button { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: #3b4758; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.fee-preview { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; color: #164b8c; }
.error { color: var(--red); font-size: 13px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #17212f; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: all .2s; z-index: 60; font-size: 13.5px; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.report-table th { width: 70%; white-space: normal; }
.bar { height: 8px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--accent); }

@media (max-width: 1180px) {
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: block; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 > * { flex-basis: 100%; min-width: 0; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .kv { grid-template-columns: 120px 1fr; }
  .search { min-width: 0; flex: 1; }
  .form .row { grid-template-columns: 1fr; }
}

/* sign-in page and accounts */
.auth-page { background: var(--navy); min-height: 100vh; }
.auth { max-width: 440px; margin: 0 auto; padding: 48px 16px; }
.auth-brand { display: flex; gap: 12px; align-items: center; color: #fff; margin-bottom: 20px; }
.auth-brand .logo { width: 44px; height: 44px; }
.auth-name { font-size: 20px; font-weight: 700; }
.auth-sub { font-size: 12px; color: #8fa3c0; }
.auth-card { padding: 24px; }
.auth-card h1 { margin-bottom: 14px; }
.auth-card p { margin: 0 0 14px; }
.auth-links { margin-top: 14px !important; font-size: 13px; }
.auth-foot { text-align: center; font-size: 13px; }
.auth-foot a { color: #cfd8e6; }
.btn.wide { width: 100%; justify-content: center; padding: 10px 14px; font-size: 14px; }
.form input, .form select { font: inherit; padding: 8px 10px; border: 1px solid #c9d2df; border-radius: 7px; background: #fff; }
.code-input { font-size: 22px !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.setup-key { margin: 8px 0 4px; padding: 10px 12px; background: var(--gray-soft); border-radius: 8px; font-size: 15px; letter-spacing: .06em; word-break: break-all; user-select: all; }
.steps-list { padding-left: 20px; margin: 0 0 14px; }
.steps-list li { margin-bottom: 10px; }
.recovery-codes { columns: 2; list-style: none; padding: 12px 14px; margin: 0 0 14px; background: var(--gray-soft); border-radius: 8px; font-size: 15px; }
.recovery-codes li { padding: 3px 0; }
.demo-card { margin-top: 16px; }
.demo-card h3 { margin-top: 14px; }
.demo-list { display: grid; gap: 6px; }
.demo-account { display: grid; gap: 1px; text-align: left; font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.demo-account:hover { border-color: var(--accent); background: var(--accent-soft); }
.demo-account span { color: var(--muted); font-size: 12.5px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.muni-checks { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: grid; gap: 6px; margin: 0; }
.muni-checks legend { font-size: 12.5px; font-weight: 600; color: #3b4758; padding: 0 4px; }
.muted-row td { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
body.readonly .view::before { content: "Read-only access: you can view and print records, but not change them."; display: block; margin-bottom: 14px; padding: 8px 12px; border-radius: 8px; background: var(--gray-soft); color: var(--muted); font-size: 13px; }
.grid + .card { margin-top: 16px; }
