:root {
  --bg: #f2f5f2;
  --surface: #ffffff;
  --surface-soft: #eef4ed;
  --text: #1a2e1c;
  --muted: #556457;
  --line: #d4ddd4;
  --primary: #2d6a4f;
  --primary-dark: #1f513c;
  --primary-light: #e6f4ed;
  --danger: #c0392b;
  --danger-dark: #a93226;
  --shadow: 0 2px 12px rgba(28, 44, 32, 0.07), 0 1px 3px rgba(28, 44, 32, 0.04);
  --shadow-md: 0 4px 20px rgba(28, 44, 32, 0.1), 0 1px 4px rgba(28, 44, 32, 0.05);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  color: var(--text);
  min-height: 48px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.12);
}

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: default;
}
input[readonly]::-webkit-outer-spin-button,
input[readonly]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[readonly][type="number"] { -moz-appearance: textfield; }

input[type="file"] {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
}

label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

label > span { font-size: 0.875rem; color: var(--muted); }
textarea { resize: vertical; min-height: 100px; }
h1, h2 { margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.stack-xl, .stack-lg { display: grid; }
.stack-lg { gap: 1rem; }
.stack-xl { gap: 1.25rem; }

/* ── Buttons ─────────────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.1rem;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.button:hover { background: var(--surface-soft); border-color: #b5c8b5; }
.button:active { transform: scale(0.98); }
.button-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(45, 106, 79, 0.25);
}
.button-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); box-shadow: 0 3px 12px rgba(45, 106, 79, 0.3); }
.button-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.button-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }
.button-light { background: var(--surface-soft); border-color: var(--line); }
.button-light:hover { background: #deeadd; }
.button-small { padding: 0.5rem 0.8rem; font-size: 0.85rem; }

/* ── Brand ───────────────────────────────────────────── */
.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 0.72rem;
}
.brand-logo {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* ── Header ──────────────────────────────────────────── */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 8px rgba(28, 44, 32, 0.06);
}
.site-header-left { display: flex; align-items: center; gap: 0.85rem; }
.site-header-left h1 {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
}
.header-user {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Layout ──────────────────────────────────────────── */
.page-stack {
  display: grid;
  gap: 1.1rem;
  padding: 1.2rem clamp(1rem, 3vw, 2rem) calc(2rem + env(safe-area-inset-bottom));
  max-width: 1600px;
  margin-inline: auto;
  width: 100%;
}

/* ── Cards ───────────────────────────────────────────── */
.panel, .stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.panel { padding: 1.25rem; }
.panel-full { width: 100%; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.compact-header { margin-bottom: 1.1rem; }
.wrap-gap { flex-wrap: wrap; }

/* ── Stats grid ──────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
}
.stat-card {
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.3rem;
  border-left: 3px solid var(--line);
}
.stat-card:nth-child(1) { border-left-color: var(--primary); }
.stat-card:nth-child(2) { border-left-color: #2980b9; }
.stat-card:nth-child(3) { border-left-color: #8e44ad; }
.stat-card:nth-child(4) { border-left-color: #16a085; }
.stat-card:nth-child(5) { border-left-color: #e67e22; }
.stat-card:nth-child(6) { border-left-color: #c0392b; }
.stat-card strong { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Forms ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.form-actions, .button-row, .action-row, .filters-actions, .import-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: flex-end;
  align-self: flex-end;
}
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  width: 100%;
}
.filters-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 130px;
  flex: 1 1 130px;
}
.import-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  width: 100%;
}

/* ── Table ───────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; min-width: 1080px; }
th, td { padding: 0.85rem 0.8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  z-index: 1;
}
tbody tr:hover { background: #f7fbf7; }
tbody tr:last-child td { border-bottom: none; }
.notes-cell { min-width: 200px; white-space: pre-wrap; font-size: 0.9rem; color: var(--muted); }

/* ── Flash messages ──────────────────────────────────── */
.empty-state { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: 0.95rem; }
.flash { padding: 0.9rem 1rem; border-radius: var(--radius-sm); border: 1px solid; font-size: 0.9rem; font-weight: 500; transition: opacity 0.5s ease, margin 0.5s ease, padding 0.5s ease, max-height 0.5s ease; overflow: hidden; }
.flash.flash-hiding { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin: 0; }
.flash-error { background: #fef3f2; border-color: #fecdca; color: #912018; }
.flash-success { background: #ecfdf3; border-color: #abefc6; color: #067647; }

/* ── Collapsible panels ──────────────────────────────── */
.collapsible-panel { padding: 0; overflow: hidden; }
.details-summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  cursor: pointer;
  user-select: none;
}
.details-summary::-webkit-details-marker { display: none; }
.details-summary:hover { background: var(--surface-soft); }
.summary-indicator {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
details[open] .summary-indicator::after { content: ' ▲'; }
details:not([open]) .summary-indicator::after { content: ' ▼'; }
.details-content {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--line);
}
.mobile-hint { max-width: 55ch; }

/* ── Pagination ──────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.85rem 0 0.25rem;
}
.pagination-info {
  font-size: 0.88rem;
  color: var(--muted);
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.pagination-page {
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0 0.35rem;
}
.button.disabled, .button-small.disabled {
  opacity: 0.38;
  pointer-events: none;
  cursor: default;
}

/* ── Filters ─────────────────────────────────────────── */
.active-filters { display: flex; gap: 0.45rem; flex-wrap: wrap; margin: 0 0 0.85rem; }
.filter-pill {
  background: var(--primary-light);
  border: 1px solid rgba(45, 106, 79, 0.2);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ── Mobile entry cards ──────────────────────────────── */
.mobile-cards { display: none; gap: 0.85rem; }
.mobile-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.8rem;
  display: grid;
  gap: 0.85rem;
  box-shadow: var(--shadow);
}
.mobile-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.mobile-card-date { font-weight: 700; font-size: 1rem; }
.mobile-card-revier {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}
.mobile-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}
.mobile-card-grid div, .mobile-card-notes { display: grid; gap: 0.15rem; }
.mobile-card-grid span, .mobile-card-notes span { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.mobile-card-grid strong { font-size: 1rem; }
.mobile-card-notes p { white-space: pre-wrap; font-size: 0.9rem; margin-top: 0.1rem; }
.mobile-action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.mobile-action-row form, .mobile-action-row button { width: 100%; }

/* ── Sticky submit ───────────────────────────────────── */
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30%);
  padding-top: 0.75rem;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ── Login page ──────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: linear-gradient(150deg, #1a3a28 0%, #2d6648 45%, #1a3a28 100%);
}
.login-shell {
  width: 100%;
  max-width: 400px;
}
.login-card {
  background: var(--surface);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 2.5rem 2.25rem;
  display: grid;
  gap: 1.5rem;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}
.login-logo {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 18px rgba(0,0,0,0.18);
}
.login-app-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary-dark);
}
.login-hint {
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--muted);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1280px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .import-grid { grid-template-columns: 1fr; }
  .filters-row label { flex: 1 1 100%; }
}

@media (max-width: 760px) {
  .site-header { padding: 0.85rem 1rem; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card strong { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .button, .button-small { min-height: 48px; }
  .button-block-mobile { width: 100%; }
  .action-row { flex-direction: column; }
  .details-summary { align-items: flex-start; padding: 1rem; }
  .details-content { padding: 0 1rem 1rem; }
  .desktop-table { display: none; }
  .mobile-cards { display: grid; }
  .panel-header.wrap-gap { flex-direction: column; align-items: stretch; }
  .filters-row { gap: 0.75rem; }
  .import-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .page-stack { padding-inline: 0.75rem; }
  .panel { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { padding: 0.85rem; }
  .login-card { padding: 1.75rem 1.25rem; }
  .mobile-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── User management ─────────────────────────────────── */
.users-table { min-width: 680px; }
.users-table-wrap { margin-bottom: 0.75rem; overflow: auto; }
.user-form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.checkbox-label { align-content: end; }
.checkbox-label input {
  width: auto;
  min-height: auto;
  margin-top: 0.35rem;
  justify-self: start;
  accent-color: var(--primary);
}
.align-end { align-items: end; }
.top-gap { margin-top: 1rem; }
.button-block { width: 100%; }
.muted-text { font-size: 0.85rem; color: var(--text-muted, #888); white-space: nowrap; }
.pref-checks { display: flex; flex-wrap: wrap; gap: 1rem; }
.pref-check-label { flex-direction: row; align-items: center; gap: 0.5rem; cursor: pointer; margin: 0; }

/* Subsection details inside a panel */
.panel-subsection {
  border-top: 1px solid var(--border, #e2e8f0);
  padding-top: 0.75rem;
}
.details-summary-minor {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
  user-select: none;
}
.details-summary-minor::after { content: ' ▼'; font-size: 0.75rem; color: var(--text-muted, #888); }
details[open] > .details-summary-minor::after { content: ' ▲'; }

@media (max-width: 1100px) {
  .user-form-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .user-form-grid { grid-template-columns: 1fr; }
  .users-table { min-width: 100%; }
}
