:root {
  --teal: #0f5e6b;
  --teal-dark: #0b4751;
  --teal-soft: #e6f1f2;
  --saffron: #e8891d;
  --saffron-soft: #fdf1e2;
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1f2a2e;
  --muted: #5e6b70;
  --line: #e2ded5;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #1e7b48;
  --success-soft: #e7f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 45, .06), 0 2px 8px rgba(20, 40, 45, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
img { max-width: 100%; height: auto; }
a { color: var(--teal); }
a:hover { color: var(--teal-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; font-family: Georgia, "Times New Roman", serif; color: var(--teal-dark); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 24px 48px; min-height: 60vh; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.num { font-variant-numeric: tabular-nums; }
.inline { display: inline; }

/* ---- Header ---- */
.dev-strip {
  background: var(--saffron); color: #fff; text-align: center;
  font-size: .82rem; font-weight: 600; padding: 4px 12px; letter-spacing: .02em;
}
.site-header { background: var(--card); border-bottom: 3px solid var(--teal); box-shadow: var(--shadow); position: relative; z-index: 5; }
.header-row { display: flex; align-items: center; gap: 16px; min-height: 68px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--teal-dark); margin-right: auto; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; }
.brand small { color: var(--saffron); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: .72rem; }
.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.site-nav > a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 500; }
.site-nav > a:hover { background: var(--teal-soft); }
.site-nav > a.active { background: var(--teal); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.user-chip { text-decoration: none; color: var(--text); font-size: .9rem; }
.nav-toggle { display: none; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; line-height: 1.2;
}
.btn:hover { border-color: var(--teal); color: var(--teal-dark); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1c13; color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn.active { background: var(--teal); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Cards, alerts, badges ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { background: var(--success-soft); border-color: #b5dfc4; color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: #f3c0bb; color: var(--danger); }
.alert-info { background: var(--teal-soft); border-color: #bcd9dc; color: var(--teal-dark); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--teal-soft); color: var(--teal-dark); font-size: .75rem; font-weight: 700; font-style: normal; vertical-align: middle; }
.badge-admin { background: var(--saffron-soft); color: #9a5305; }
.status-open { background: var(--saffron-soft); color: #9a5305; }
.status-ok { background: var(--success-soft); color: var(--success); }
.status-bad { background: var(--danger-soft); color: var(--danger); }
.count { font: 600 .9rem system-ui, sans-serif; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; vertical-align: middle; }
.crumbs { font-size: .88rem; color: var(--muted); margin: 0 0 8px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

/* ---- Landing ---- */
.hero { display: flex; gap: 24px; align-items: center; margin-bottom: 20px; }
.hero-logo { flex: 0 0 auto; width: 140px; }
.hero h1 { font-size: 2.1rem; margin-bottom: 6px; }
.lead { font-size: 1.1rem; margin: 0 0 4px; }
.notice {
  display: flex; gap: 18px; align-items: flex-start;
  background: #fff7e8; border: 2px solid var(--saffron); border-left-width: 8px;
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 24px;
}
.notice h2 { color: #a3470a; font-size: 1.4rem; letter-spacing: .02em; margin-bottom: 4px; }
.notice p { margin: 0; font-weight: 700; color: #6b3a0c; font-size: 1.05rem; }
.notice .notice-sub { font-weight: 400; margin-top: 6px; font-size: .95rem; }
.notice-icon { flex: 0 0 44px; height: 44px; border-radius: 50%; background: var(--saffron); color: #fff; font: 700 1.6rem/44px Georgia, serif; text-align: center; }
.landing-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 24px; align-items: start; }
.photo { margin: 0; background: var(--card); padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.photo img { display: block; border-radius: 6px; width: 100%; }
.photo figcaption { font-size: .88rem; color: var(--muted); padding: 8px 4px 2px; text-align: center; }
.quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.quick { display: block; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--teal); border-radius: var(--radius); padding: 18px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: transform .12s; }
.quick:hover { transform: translateY(-2px); border-top-color: var(--saffron); color: var(--text); }
.quick strong { display: block; font: 700 1.8rem Georgia, serif; color: var(--teal-dark); }
.quick span { font-weight: 700; }
.quick p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; }
.quick-links > p { grid-column: 1 / -1; }

/* ---- Filters & tables ---- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px; }
.filters label { display: flex; flex-direction: column; font-size: .82rem; font-weight: 600; color: var(--muted); gap: 4px; }
.filters .grow { flex: 1 1 240px; }
.filter-actions { display: flex; gap: 8px; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid #cfcac0; border-radius: 8px; padding: 8px 10px; width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 94, 107, .35); border-color: var(--teal); }
input.readonly { background: #f2f0eb; color: var(--muted); }
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .94rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: #faf8f4; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
.table th a { color: inherit; text-decoration: none; }
.table tbody tr:hover { background: #fbfaf7; }
.table td.actions { white-space: nowrap; text-align: right; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.pager a, .pager span { padding: 6px 11px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); text-decoration: none; }
.pager .current { background: var(--teal); color: #fff; border-color: var(--teal); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--text); font-size: .9rem; }
.chip small { color: var(--muted); }
.chip.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip.active small { color: #d4eaec; }

/* ---- Detail pages ---- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.detail-grid .card { margin: 0; }
.detail-card h2 { color: var(--teal-dark); border-bottom: 2px solid var(--saffron-soft); padding-bottom: 6px; }
.span-2 { grid-column: span 2; }
.dl { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 6px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; word-break: break-word; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---- Forms ---- */
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
.form fieldset { border: 1px solid var(--line); }
.form legend { font-weight: 700; color: var(--teal-dark); padding: 0 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.pw-wrap { display: flex; gap: 6px; }
.pw-wrap input { flex: 1; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }
.inline-label { flex-direction: row !important; align-items: center; margin: 0 !important; }
.inline-label select { width: auto; }
.auth-box { max-width: 420px; margin: 24px auto; text-align: center; }
.auth-box .form { text-align: left; margin-top: 16px; }
.add-petitioner { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); }
.category-row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.category-row > form.form { flex: 1 1 auto; }
.upload-box summary { cursor: pointer; }
.upload-box .form { margin-top: 14px; }

/* ---- Library ---- */
.doc-list { list-style: none; padding: 0; margin: 0; }
.doc { display: flex; gap: 16px; align-items: center; padding: 14px 18px; margin-bottom: 10px; }
.doc-icon { flex: 0 0 48px; height: 56px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); font: 800 .8rem/56px system-ui, sans-serif; text-align: center; border: 1px solid #f3c0bb; }
.doc-body { flex: 1 1 auto; min-width: 0; }
.doc-body h3 { margin: 0 0 2px; font-size: 1.02rem; }
.doc-body h3 a { text-decoration: none; }
.doc-body p { margin: 2px 0; }
.doc-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- PDF viewer ---- */
.pdf-viewer { padding: 0; overflow: hidden; }
.pdf-toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #faf8f4; position: sticky; top: 0; }
.pdf-pages { margin-left: auto; }
.pdf-pages-wrap { background: #e9e6df; padding: 12px; overflow-x: auto; max-height: 85vh; overflow-y: auto; text-align: center; }
.pdf-pages-wrap canvas { display: block; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); max-width: none; }
.pdf-frame { width: 100%; height: 80vh; border: 0; background: #fff; }
.pdf-loading { padding: 40px; }

/* ---- Maps (Leaflet) ---- */
.coords { font-variant-numeric: tabular-nums; }
.map-box { position: relative; z-index: 0; height: 62vh; min-height: 320px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); margin-bottom: 16px; }
.map-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.map-tools label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.map-tools .grow { flex: 1 1 260px; }
.search-results { list-style: none; margin: 8px 0 0; padding: 0; }
.search-results button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 8px 4px; font: inherit; font-size: .9rem; color: var(--teal); cursor: pointer; }
.search-results button:hover { background: var(--teal-soft); }
.map-dialog { width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.map-dialog::backdrop { background: rgba(15, 30, 35, .55); }
.map-dialog-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.map-dialog-head h2 { margin: 0; color: var(--teal-dark); }
.map-dialog-head p { margin: 2px 0 0; }
.map-dialog-map { height: min(65vh, 560px); min-height: 260px; }
.map-dialog-foot { display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }
.map-dialog-foot .coords { margin-right: auto; }

/* ---- Footer ---- */
.site-footer { background: var(--teal-dark); color: #d4eaec; padding-block: 20px; font-size: .9rem; }
.site-footer p { margin: 2px 0; }
.site-footer .muted { color: #9cc3c7; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font: inherit; font-weight: 600; }
  .site-nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 12px; }
  .site-nav.open { display: flex; }
  .nav-user { margin: 8px 0 0; justify-content: space-between; }
  .landing-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media (max-width: 600px) {
  .hero { flex-direction: column; text-align: center; }
  .hero h1 { font-size: 1.6rem; }
  .hero-logo { width: 110px; }
  .notice { flex-direction: column; padding: 16px; }
  .quick-links, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: 6px; }
  .doc { flex-wrap: wrap; }
  .doc-actions { width: 100%; justify-content: flex-start; }
  .brand strong { font-size: .95rem; }
}
