:root {
  --brand: #1c5d38;
  --brand-dark: #14432a;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1e2a24;
  --muted: #64716a;
  --border: #dde4e0;
  --danger: #c0392b;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); text-decoration: none; }
main { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
body.is-home {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
body.is-home main { overflow: hidden; position: relative; }
body.is-home .map-full { height: auto; }

/* header */
.topbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 0 12px;
  background: var(--brand); color: #fff;
  position: sticky; top: 0; z-index: 1100;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; min-width: 0; flex-shrink: 0; }
.brand img { height: 38px; width: 38px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.brand-copy { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.brand-intro { display: none; }
.topbar-end { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.mainnav { display: flex; gap: 4px; }
.mainnav a { color: #dfeae4; padding: 6px 10px; border-radius: 6px; font-size: 14px; white-space: nowrap; }
.mainnav a.act, .mainnav a:hover { background: var(--brand-dark); color: #fff; }
.mainnav a.adminlink { background: #fff2; }
.userbox { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.langs { display: flex; gap: 2px; }
.langs a { color: #cfe0d7; font-size: 12px; padding: 3px 5px; border-radius: 4px; }
.langs a.act { background: #fff; color: var(--brand); font-weight: 700; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.linkbtn { background: none; border: 0; color: #dfeae4; cursor: pointer; font-size: 14px; padding: 6px; }
.inline { display: inline; }
.nav-toggle {
  display: none;
  width: 44px; height: 44px; margin-left: auto; padding: 0;
  border: 0; background: transparent; cursor: pointer;
  flex-direction: column; justify-content: center; align-items: center; gap: 5px;
}
.nav-toggle span {
  display: block; width: 20px; height: 2px; background: #fff; border-radius: 1px;
}

/* buttons */
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-size: 14px; cursor: pointer;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-big { padding: 12px 22px; font-size: 16px; }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-signin { background: #fff; color: #333; font-weight: 600; }

.auth-buttons {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  margin: 20px auto 8px; max-width: 280px;
}
.btn-sso {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 10px; width: 100%; height: 40px; padding: 0 12px;
  border-radius: 4px; font-size: 14px; font-weight: 500; line-height: 20px;
  text-decoration: none; box-sizing: border-box;
}
.btn-sso img { display: block; flex-shrink: 0; }
.btn-google-brand {
  background: #ffffff; color: #1f1f1f; border: 1px solid #747775;
}
.btn-google-brand:hover { background: #f8f8f8; }
.btn-x-brand {
  background: #000000; color: #ffffff; border: 1px solid #000000;
}
.btn-x-brand:hover { background: #1a1a1a; color: #fff; }
.btn-facebook-brand {
  background: #1877F2; color: #ffffff; border: 1px solid #1877F2;
}
.btn-facebook-brand:hover { background: #166fe5; color: #fff; }
.btn-microsoft-brand {
  background: #ffffff; color: #1f1f1f; border: 1px solid #8c8c8c;
}
.btn-microsoft-brand:hover { background: #f3f3f3; color: #1f1f1f; }
.btn-github-brand {
  background: #24292f; color: #ffffff; border: 1px solid #24292f;
}
.btn-github-brand:hover { background: #1b1f23; color: #fff; }
.btn-telegram-brand {
  background: #229ED9; color: #ffffff; border: 1px solid #229ED9;
}
.btn-telegram-brand:hover { background: #1b8fc4; color: #fff; }

/* layout */
.page { max-width: 1000px; margin: 0 auto; padding: 16px; }
.page.narrow { max-width: 640px; }
.page.wide { max-width: 1200px; }
.page.center { text-align: center; padding-top: 48px; }
.hint { color: var(--muted); }
.flash {
  max-width: 640px; margin: 12px auto; padding: 10px 16px;
  background: #e3f4e9; border: 1px solid #9ed3b2; border-radius: 8px; color: #14572e;
}
.errors { background: #fdeceb; border: 1px solid #f3b6b0; border-radius: 8px; padding: 4px 16px; color: var(--danger); margin: 12px 0; }
.hiddenbox { display: none; }
.hiddenbox.show { display: block; }

/* home */
.home-hero { display: flex; align-items: center; gap: 16px; padding: 12px 16px; flex-wrap: wrap; flex-shrink: 0; }
.home-hero p { margin: 0 0 8px; color: var(--muted); }
.home-hero p:last-of-type { margin-bottom: 0; }
.home-stats {
  display: flex; flex-wrap: wrap; gap: 2px 14px;
  margin-top: 6px; font-size: 13px; color: var(--muted);
}
.home-stats span { white-space: nowrap; }
.home-stats strong { color: var(--brand-dark); font-weight: 700; }
.home-stats:hover strong { text-decoration: underline; }
.map-toolbar { display: flex; gap: 8px; padding: 0 16px 10px; flex-shrink: 0; }
.cat-legend {
  display: flex; flex-wrap: wrap; gap: 6px 12px;
  padding: 0 16px 10px; flex-shrink: 0;
  font-size: 12px; color: var(--muted);
}
.cat-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.map-wrap {
  flex: 1 1 auto; min-height: 280px; position: relative;
  display: flex; flex-direction: column;
}
.map-full { flex: 1 1 auto; min-height: 280px; height: calc(100vh - 210px); }
.map-sheet {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 1200;
  background: #fff; border-radius: 12px; padding: 10px 36px 10px 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.28); border: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center; cursor: pointer; color: inherit;
  text-decoration: none;
}
.map-sheet[hidden] { display: none !important; }
.map-sheet .popup-thumb { width: 72px; height: 72px; max-width: 72px; object-fit: cover; margin: 0; flex-shrink: 0; }
.map-sheet-body {
  min-width: 0; font-size: 14px; line-height: 1.35; flex: 1;
  display: flex; color: inherit; text-decoration: none;
}
.map-sheet-body > div { display: flex; gap: 10px; align-items: center; min-width: 0; width: 100%; }
.popup-info { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; }
.popup-info strong { overflow-wrap: anywhere; }
.popup-meta { color: var(--muted); font-size: 13px; }
.popup-id { color: var(--brand); font-weight: 700; }
.map-sheet-close {
  position: absolute; top: 4px; right: 6px; border: 0; background: none;
  font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px;
}
.map-picker { height: 320px; border-radius: 10px; margin-bottom: 16px; }
.map-mini { height: 260px; border-radius: 10px; margin: 16px 0; }

/* forms */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
input[type=text], input[type=email], input[type=number], select, textarea {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit; background: #fff; width: 100%;
}
.filters { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 400; flex-direction: row; }
.row3 { display: flex; gap: 8px; }
.row3 > * { flex: 1; }
.w-s { width: 70px !important; }
.bounds-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.bounds-readout label { margin: 0; }
.bounds-readout input { font-variant-numeric: tabular-nums; }
.map-bounds { height: 420px; width: 100%; border-radius: 10px; border: 1px solid var(--border); z-index: 0; }
.bounds-handle, .map-center-handle {
  position: relative;
  background: #fff;
  border: 2px solid var(--brand);
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.bounds-handle { border-radius: 3px; cursor: nwse-resize; }
.map-center-handle {
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(28,93,56,.25), 0 1px 4px rgba(0,0,0,.35);
}
.map-center-handle::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  background: var(--brand);
  border-radius: 50%;
}

.photo-pick { display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 600; }
.photo-pick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-pick-btn {
  position: relative; overflow: hidden; margin: 0; font-weight: 600;
  display: inline-flex; flex-direction: row; align-items: center; justify-content: center;
  gap: 0;
}
.photo-pick-btn input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0;
}
.photo-pick-btn.has-file { border-color: var(--brand); background: #e3f4e9; }
.photo-pick-chosen { font-weight: 400; margin: 0; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #fff; vertical-align: middle; }
.st-new { background: #e67e22; }
.st-confirmed { background: #2980b9; }
.st-in_progress { background: #8e44ad; }
.st-resolved { background: #27ae60; }
.st-rejected { background: #7f8c8d; }
.st-duplicate { background: #95a5a6; }
.st-overdue { background: var(--danger); }
.st-hidden { background: #333; }

/* report cards */
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.report-card {
  display: flex; gap: 10px; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px; color: var(--text);
}
.report-card:hover { border-color: var(--brand); }
.report-card img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.rc-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rc-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rc-addr { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.rc-when { font-size: 12px; color: var(--muted); }
.catdot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.caticon {
  display: inline-block; flex-shrink: 0; vertical-align: middle;
  background: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.cat-icon-preview { width: 22px; height: 22px; flex-shrink: 0; }
.cat-icon-select { min-width: 132px; }
.cat-marker { background: none !important; border: none !important; }
.cat-marker-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.cat-marker-pin {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.cat-marker-glyph {
  width: 16px; height: 16px; display: block;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}

/* report detail */
.report-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.report-head h1 { margin: 8px 0; }
.meta { color: var(--muted); font-size: 14px; }
.note { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.photo-grid { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.photo-grid figure { margin: 0; text-align: center; }
.photo-grid img { width: 160px; height: 160px; object-fit: cover; border-radius: 10px; }
.photo-grid figure.after img { outline: 3px solid #27ae60; }
.photo-grid figcaption { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* timeline */
.timeline { list-style: none; padding: 0 0 0 18px; border-left: 3px solid var(--border); }
.timeline li { position: relative; margin: 0 0 16px; }
.timeline li::before {
  content: ""; position: absolute; left: -25px; top: 4px;
  width: 11px; height: 11px; border-radius: 50%; background: var(--brand);
}
.timeline li.internal { opacity: 0.75; }
.timeline li.internal::before { background: #999; }
.tl-when { display: block; font-size: 12px; color: var(--muted); }
.tl-what { font-weight: 600; }
.tl-body { margin: 4px 0 0; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

/* pager */
.pager { display: flex; gap: 6px; margin: 16px 0; }
.pager a { padding: 5px 11px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.pager a.act { background: var(--brand); color: #fff; border-color: var(--brand); }

/* admin */
.admin-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.admin-head h1 { margin: 8px 0; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
.admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table tr.overdue { background: #fdf1f0; }
.admin-table tr.hidden-row { opacity: 0.55; }
.audit-wrap { overflow-x: auto; }
.audit-table { font-size: 13px; }
.audit-table td { vertical-align: top; }
.audit-details { font-size: 12px; color: var(--muted); word-break: break-word; max-width: 320px; }
.cell-photo img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; display: block; }
.cell-when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.rownum { font-weight: 700; margin-right: 6px; }
.admin-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
.admin-actions { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.catrow { border-bottom: 1px dashed var(--border); padding-bottom: 8px; }

/* map popup (desktop Leaflet); mobile uses .map-sheet thumb sizes */
.leaflet-popup-content { min-width: 200px; }
.leaflet-popup-content > div {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-width: 0;
}
.popup-thumb {
  width: 88px;
  height: 88px;
  max-width: 88px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  margin: 0;
  flex-shrink: 0;
}

.home-hero > div { flex: 1; min-width: 200px; }

.sitefoot {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted); background: #fff;
  flex-shrink: 0;
}
.sitefoot a { color: var(--brand); font-weight: 600; }

.legal { max-width: 760px; }
.legal h2 { margin-top: 28px; font-size: 18px; }
.legal p, .legal li { line-height: 1.55; }
.legal ul { padding-left: 20px; }

/* public / admin stats */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 16px 0 24px;
}
.stat-card, .kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat-card strong, .kpi strong { display: block; font-size: 26px; line-height: 1.15; }
.stat-card span, .kpi span { font-size: 13px; color: var(--muted); }
.kpi {
  display: flex; flex-direction: column; gap: 2px;
  color: var(--text); padding: 10px 12px;
}
.kpi:hover { border-color: var(--brand); }
.kpi.act { border-color: var(--brand); background: #e8f3ec; }
.kpi.overdue:hover, .kpi.overdue.act { border-color: var(--danger); }
.kpi.overdue.act { background: #fdf1f0; }
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin: 8px 0 16px;
}
.stat-bars { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 24px; }
.stat-bar {
  display: grid;
  grid-template-columns: minmax(110px, 1.2fr) 3fr 2rem;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}
.stat-bar-label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.stat-bar-track { height: 10px; background: #e8eeea; border-radius: 6px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 6px; }
.stat-bar-n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
a.stat-bar { color: inherit; }
.admin-cat-bars { max-width: 720px; margin-bottom: 8px; }
.month-legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.swatch.submitted { background: var(--brand); }
.swatch.resolved { background: #27ae60; }
.month-bars {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 28px;
}
.month-col { text-align: center; font-size: 12px; color: var(--muted); }
.month-pair { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 80px; }
.month-pair span { width: 12px; border-radius: 3px 3px 0 0; min-height: 0; }
.month-pair span.submitted { background: var(--brand); }
.month-pair span.resolved { background: #27ae60; }
.month-n { font-variant-numeric: tabular-nums; }
.page h2 { font-size: 18px; margin: 28px 0 8px; }

@media (max-width: 760px) {
  .brand {
    flex: 1;
    min-width: 0;
    align-items: flex-start;
    padding: 8px 0;
  }
  .brand-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    line-height: 1.2;
  }
  body.is-home .brand-intro {
    display: block;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.35;
    color: #d7e8de;
    white-space: normal;
  }
  .admin-grid { grid-template-columns: 1fr; }
  .home-hero { padding: 6px 12px 4px; gap: 6px; align-items: flex-start; }
  .home-hero p { font-size: 12px; }
  .home-hero .home-title,
  .home-hero .home-intro { display: none; }
  .home-hero .btn-big { padding: 8px 14px; font-size: 15px; }
  .home-stats { margin-top: 0; }
  .map-toolbar { padding: 0 12px 6px; }
  .cat-legend {
    flex-wrap: nowrap; overflow-x: auto; gap: 10px;
    padding: 0 12px 8px; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cat-legend::-webkit-scrollbar { display: none; }
  .cat-legend-item { flex-shrink: 0; }
  .map-wrap { min-height: 240px; }
  .map-full { height: auto; min-height: 0; }
  body.is-home .sitefoot { padding: 6px 12px; }
  body.is-home .sitefoot span { display: none; }
  .nav-toggle { display: flex; }
  .topbar-end {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    margin: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--brand-dark);
    padding: 8px 0 12px;
    box-shadow: 0 10px 24px rgba(0,0,0,.28);
  }
  .topbar.is-open .topbar-end { display: flex; }
  .mainnav { flex-direction: column; gap: 0; }
  .mainnav a { padding: 12px 16px; border-radius: 0; font-size: 16px; }
  .userbox {
    padding: 8px 16px 4px;
    flex-wrap: wrap;
    border-top: 1px solid #fff3;
  }
  .month-bars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-bar { grid-template-columns: 1fr 2.5rem; }
  .stat-bar-track { grid-column: 1 / -1; order: 3; }
}
