:root {
  --green-900: #1b5e20;
  --green-700: #2e7d32;
  --green-500: #43a047;
  --green-100: #e8f5e9;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-2: #6b7280;
  --border: #e5e7eb;
  --danger: #c62828;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --appbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- Login ---------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--green-500) 0%, var(--green-900) 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: linear-gradient(160deg, var(--green-500), var(--green-900));
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-title { margin: 0; text-align: center; font-size: 24px; font-weight: 700; }
.login-subtitle { margin: 4px 0 20px; text-align: center; color: var(--text-2); font-size: 14px; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.field input {
  width: 100%;
  padding: 12px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
}
.field input:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-100); }

.login-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #fdecea;
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
}

.login-hint { margin-top: 16px; font-size: 12px; color: var(--text-2); text-align: center; }
.login-hint code { background: var(--green-100); padding: 1px 5px; border-radius: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--green-700); color: #fff; }
.btn-primary:active { background: var(--green-900); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: default; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  color: #fff;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }

/* ---------- App bar ---------- */
.appbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--appbar-h);
  background: var(--green-700);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  z-index: 30;
  box-shadow: var(--shadow);
}
.appbar-title { flex: 1; display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.appbar-name { font-weight: 700; font-size: 16px; }
.appbar-module { font-size: 12px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; align-items: center; gap: 4px; }

.year-select {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
}
.year-select option { color: #000; }

/* ---------- Drawer ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--surface);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
  padding-top: var(--appbar-h);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.2);
}
.drawer.open { transform: translateX(0); }

.drawer-list { padding: 8px 0 24px; }
.drawer-group { padding: 12px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); font-weight: 600; }
.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.drawer-item:active { background: var(--green-100); }
.drawer-item.active { background: var(--green-100); color: var(--green-900); font-weight: 600; }
.drawer-item .dot { width: 26px; height: 26px; border-radius: 7px; background: var(--green-100); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }

/* ---------- Content ---------- */
.content {
  padding: calc(var(--appbar-h) + 12px) 12px 40px;
  max-width: 760px;
  margin: 0 auto;
}

.list-header { padding: 4px 4px 10px; }
.list-header h2 { margin: 0; font-size: 20px; }
.list-header .count { color: var(--text-2); font-size: 13px; }

.card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  cursor: pointer;
  border: none;
  background: var(--surface);
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: #f0f4f0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: 15px; }
.list-item .li-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-chev { color: #c0c4c8; font-size: 18px; }

/* ---------- Detail ---------- */
.detail-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
}
.detail-title { font-size: 20px; font-weight: 700; margin: 0; flex: 1; }
.detail-headline { color: var(--text-2); font-size: 13px; margin-bottom: 12px; }

.kv { padding: 0 14px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: none; }
.kv-key { color: var(--text-2); font-size: 13px; flex-shrink: 0; max-width: 45%; }
.kv-val { font-size: 14px; font-weight: 500; text-align: right; word-break: break-word; }

.section-title { padding: 14px 14px 4px; font-size: 13px; font-weight: 700; color: var(--green-900); text-transform: uppercase; letter-spacing: 0.02em; }

/* ---------- States ---------- */
.state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-2);
}
.state .big { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid var(--green-100);
  border-top-color: var(--green-700);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  margin: 12px;
  padding: 12px 14px;
  background: #fdecea;
  color: var(--danger);
  border-radius: 10px;
  font-size: 14px;
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .drawer {
    transform: none;
    position: fixed;
    top: var(--appbar-h);
    left: 0;
    bottom: 0;
    width: 260px;
    padding-top: 8px;
    box-shadow: none;
    border-right: 1px solid var(--border);
    z-index: 20;
  }
  .drawer-overlay { display: none; }
  #drawer-toggle { display: none; }
  .content { margin-left: 260px; max-width: 900px; }
  .appbar-title { margin-left: 4px; }
}


/* ---------- Карта полей ---------- */
/* Карта — обычный блок с высотой (не position:fixed): fixed внутри #content
   даёт нулевой getBoundingClientRect у map-pane, из-за чего Leaflet рисует
   полигоны как d="M0 0". */
.content-map { max-width: none; margin: 0; padding: 0; }
.map-full {
  width: 100%;
  height: calc(100vh - var(--appbar-h));
  height: calc(100dvh - var(--appbar-h));
  background: #dfe6df;
}
@media (min-width: 900px) {
  .content-map { margin-left: 260px; }
}


/* ---------- Офлайн-баннер ---------- */
.offline-banner {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: #37474f;
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 999;
  max-width: 90vw;
  text-align: center;
}
