:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --ink: #18231f;
  --muted: #61716b;
  --line: #d7e0dc;
  --accent: #0f6b5d;
  --accent-dark: #0a5147;
  --accent-soft: #dcefe9;
  --blue-soft: #e8f0ff;
  --blue: #245cba;
  --amber-soft: #fff1cf;
  --amber: #84520a;
  --red-soft: #fde7e5;
  --red: #a02e28;
  --green-soft: #e4f4e9;
  --green: #176b3a;
  --shadow: 0 12px 34px rgba(22, 42, 35, .11);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.app-root { min-height: 100vh; }

.boot-screen, .access-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.boot-screen { align-content: center; text-align: center; }
.boot-screen img { border-radius: 8px; box-shadow: var(--shadow); }
.boot-screen h1 { margin: 18px 0 6px; font-size: 28px; }
.boot-screen p { margin: 0; color: var(--muted); }
.access-card { width: min(430px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.brand-row { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-row img { width: 52px; height: 52px; border-radius: 8px; }
.brand-row h1 { margin: 0; font-size: 24px; }
.brand-row p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.access-card h2 { margin: 0 0 8px; font-size: 20px; }
.access-card > p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
.form-stack { display: grid; gap: 15px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .toolbar-input, .toolbar-select {
  width: 100%; min-height: 46px; padding: 10px 12px; color: var(--ink); background: #fff;
  border: 1px solid #bdcbc5; border-radius: 6px; outline: none;
}
.field input:focus, .toolbar-input:focus, .toolbar-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 107, 93, .13); }
.field small { color: var(--muted); line-height: 1.4; }
.form-error { min-height: 20px; margin: 0; color: var(--red); font-size: 14px; }
.btn {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px; color: var(--ink); background: #fff; border: 1px solid #bdcbc5; border-radius: 6px; font-weight: 700;
}
.btn:hover { border-color: #8ca39a; background: #f8faf9; }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.text { min-height: 38px; padding: 7px 8px; border-color: transparent; background: transparent; color: var(--accent-dark); }
.btn.icon-only { width: 44px; padding: 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 4px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.shell { min-height: 100vh; padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.app-header {
  position: sticky; top: 0; z-index: 500; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 70px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line);
}
.header-title { min-width: 0; }
.header-title h1 { margin: 0; font-size: 21px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; gap: 6px; }
.header-actions .btn { background: transparent; }
.content { width: min(920px, 100%); margin: 0 auto; padding: 16px; }
.status-strip { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; padding: 12px 14px; background: var(--accent-soft); color: var(--accent-dark); border-left: 3px solid var(--accent); border-radius: 4px; font-size: 13px; line-height: 1.4; }
.status-strip.warning { background: var(--amber-soft); color: var(--amber); border-left-color: #c48116; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.page-head h2 { margin: 0; font-size: 23px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 8px; margin-bottom: 12px; }
.search-wrap { position: relative; }
.search-wrap .icon { position: absolute; left: 13px; top: 13px; color: var(--muted); }
.search-wrap .toolbar-input { padding-left: 42px; }
.list { display: grid; gap: 9px; }
.card {
  width: 100%; padding: 14px; text-align: left; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
}
button.card:hover { border-color: #9bb2a9; background: #fbfdfc; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { margin: 0; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.card-text { display: -webkit-box; margin: 9px 0 0; overflow: hidden; color: #52645d; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 11px; }
.badge { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 4px 8px; border-radius: 4px; background: #edf1ef; color: #52625c; font-size: 12px; font-weight: 700; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.new { background: #dff4ec; color: #08705b; border: 1px solid #a4dbc9; }
.count { flex: 0 0 auto; color: var(--accent-dark); background: var(--accent-soft); }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed #bdcbc5; border-radius: 7px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.98); border-top: 1px solid var(--line);
}
.bottom-nav button { min-width: 0; display: grid; justify-items: center; gap: 2px; padding: 7px 3px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-size: 11px; font-weight: 700; }
.bottom-nav button.active { color: var(--accent-dark); background: var(--accent-soft); }
.bottom-nav .icon { width: 21px; height: 21px; }

.detail-header { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.detail-header .btn { flex: 0 0 auto; }
.detail-header h2 { margin: 2px 0 4px; font-size: 21px; line-height: 1.3; }
.detail-header p { margin: 0; color: var(--muted); font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; overflow: hidden; margin-bottom: 14px; background: var(--line); border: 1px solid var(--line); border-radius: 7px; }
.detail-cell { min-width: 0; padding: 12px; background: var(--surface); }
.detail-cell span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.detail-cell strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.section { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.section-head h3 { margin: 0; font-size: 16px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.section-body { padding: 14px; }
.summary { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
details.person { border-bottom: 1px solid var(--line); }
details.person:last-child { border-bottom: 0; }
details.person summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; list-style: none; cursor: pointer; }
details.person summary::-webkit-details-marker { display: none; }
.person-name { font-weight: 750; }
.person-role { margin-top: 3px; color: var(--muted); font-size: 12px; }
.person-data { display: grid; gap: 8px; padding: 0 0 14px; }
.data-line { display: grid; grid-template-columns: 105px minmax(0, 1fr); gap: 8px; font-size: 13px; line-height: 1.4; }
.data-line strong { color: var(--muted); }
.action-card { padding: 13px 0; border-bottom: 1px solid var(--line); }
.action-card:first-child { padding-top: 0; }
.action-card:last-child { padding-bottom: 0; border-bottom: 0; }
.action-card h4 { margin: 0; font-size: 15px; }
.action-card p { margin: 9px 0 0; white-space: pre-wrap; color: #465952; line-height: 1.5; }
.action-link { display: inline-flex; margin-top: 10px; color: var(--accent-dark); font-size: 13px; font-weight: 700; }

.pending-card { border-left: 3px solid #8fa79e; }
.pending-card.overdue, .pending-card.no-date { border-left-color: #c9483e; }
.pending-card.today { border-left-color: #c48116; }
.pending-date { color: var(--muted); font-size: 12px; }
.search-gap { height: 14px; }
.result-group { margin-bottom: 20px; }
.result-group h3 { margin: 0 0 9px; font-size: 14px; color: var(--muted); text-transform: uppercase; }
.result-person { width: 100%; padding: 12px 14px; text-align: left; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }

#map { height: calc(100vh - 205px); min-height: 430px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #dfe7e3; }
.leaflet-popup-content { margin: 12px; line-height: 1.4; }
.leaflet-popup-content strong { display: block; margin-bottom: 4px; }
.leaflet-popup-content button { margin-top: 8px; padding: 7px 10px; color: #fff; background: var(--accent); border: 0; border-radius: 5px; font-weight: 700; }

.settings-list { display: grid; gap: 12px; }
.settings-item { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.settings-item h3 { margin: 0 0 5px; font-size: 15px; }
.settings-item p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.settings-item .btn { margin-top: 12px; }
.toast { position: fixed; z-index: 900; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); width: min(420px, calc(100% - 28px)); padding: 12px 14px; color: #fff; background: #1f302a; border-radius: 6px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading-cover { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(244,246,245,.9); }
.loading-box { width: min(340px, 100%); padding: 24px; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.spinner { width: 34px; height: 34px; margin: 0 auto 14px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) {
  .content { padding: 24px; }
  .list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bottom-nav { left: 50%; right: auto; width: min(620px, calc(100% - 28px)); bottom: 12px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
  .shell { padding-bottom: 96px; }
}

@media (max-width: 520px) {
  .toolbar { grid-template-columns: 1fr; }
  .access-card { padding: 22px 18px; }
  .data-line { grid-template-columns: 1fr; gap: 2px; }
  .header-title h1 { font-size: 19px; }
}
