:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #657287;
  --line: #d6dee8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(23, 31, 45, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #eef2f5, #dbe7e5);
  z-index: 20;
}

.login-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 380px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 8px;
}

.app-shell.locked {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  overflow: hidden;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 2;
  overflow-y: auto;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

.counter {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary);
  font-weight: 700;
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.role-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.admin-menu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.admin-menu button.active {
  background: var(--primary);
  color: #ffffff;
}

.admin-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tab-button.active {
  background: var(--primary);
  color: #ffffff;
}

.hidden {
  display: none !important;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.check-row {
  flex-direction: row;
  align-items: center;
  color: var(--text);
  font-weight: 500;
}

.check-row input {
  width: auto;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fbfcfd;
  outline: none;
}

textarea:focus,
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  align-items: stretch;
}

.modal-panel .search-row {
  grid-template-columns: 1fr 96px;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 12px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.icon-button {
  min-height: 42px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

button.secondary {
  border: 1px solid var(--line);
  color: var(--text);
  background: #f7f9fb;
}

button.secondary:hover {
  border-color: #b8c4d2;
  background: #edf2f6;
}

.small-button {
  min-height: 34px;
  padding: 7px 10px;
}

.add-list-button {
  align-self: stretch;
  min-height: 38px;
}

.error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.input-section .error:empty {
  min-height: 0;
}

.results-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  cursor: pointer;
}

.result-name {
  font-weight: 700;
}

.account-section,
.account-form,
.account-list,
.school-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.account-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.account-row span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.account-actions {
  display: flex;
  gap: 8px;
}

.school-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.school-list-row {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.school-list-row strong {
  display: block;
  overflow-wrap: anywhere;
}

.delete-school {
  min-height: 34px;
  padding: 0;
  color: var(--danger) !important;
  font-size: 20px;
  line-height: 1;
}

.map-popup {
  display: grid;
  gap: 6px;
  min-width: 180px;
  color: var(--text);
}

.map-popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.map-popup-actions button {
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.report-row {
  grid-template-columns: 1fr;
}

.report-row .account-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 33, 47, 0.42);
  z-index: 9999;
}

.modal-panel {
  position: relative;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 560px);
  max-height: min(680px, 90vh);
  padding: 18px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.search-result {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: auto;
  padding: 10px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #fbfcfd;
  text-align: left;
}

.search-result:hover {
  border-color: #b8c4d2;
  background: #edf2f6;
}

.search-result span,
.search-result small {
  color: var(--muted);
  font-size: 12px;
}

.report-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.report-view p {
  margin: 0;
}

.report-map-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-schools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.print-layout-controls {
  display: grid;
  grid-template-columns: 1fr 82px;
  gap: 8px 10px;
  align-items: center;
}

.print-layout-controls label {
  grid-column: 1 / -1;
}

.print-preview {
  width: 100%;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ffffff center top / 100% 100% no-repeat;
  box-shadow: 0 10px 28px rgba(23, 31, 45, 0.12);
}

.print-preview-content {
  width: 100%;
  min-height: 100%;
  transform-origin: top left;
  color: var(--text);
  font-family: Arial, sans-serif;
}

.print-preview h1 {
  margin: 0 0 4px;
  font-size: 14px;
}

.print-preview-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 8px;
}

.print-preview-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.print-preview-fields div {
  min-height: 26px;
  padding: 4px;
  border: 1px solid #cfd8e3;
  font-size: 7px;
  background: rgba(255, 255, 255, 0.76);
}

.print-preview-fields strong {
  display: block;
  color: var(--muted);
  font-size: 6px;
}

.print-preview-summary,
.print-preview-home,
.print-preview-declaration {
  margin: 0 0 8px;
  font-size: 8px;
  font-weight: 700;
}

.print-preview-home {
  font-weight: 400;
}

.print-preview-home strong {
  color: var(--muted);
}

.print-preview-map {
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border: 1px solid #cfd8e3;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.1) 1px, transparent 1px),
    linear-gradient(rgba(15, 118, 110, 0.1) 1px, transparent 1px),
    #e7f4f2;
  background-size: 12px 12px;
  color: var(--muted);
  font-size: 9px;
}

.print-preview table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.76);
}

.print-preview th,
.print-preview td {
  padding: 4px;
  border: 1px solid #cfd8e3;
  font-size: 7px;
  text-align: left;
}

.print-preview th {
  background: #eef2f5;
}

.print-preview-declaration {
  line-height: 1.45;
  font-weight: 400;
}

.print-preview-signature {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

.print-preview-signature div {
  padding-top: 4px;
  border-top: 1px solid var(--text);
  font-size: 7px;
  text-align: center;
}

.result-meta,
.empty,
.summary {
  color: var(--muted);
  font-size: 12px;
}

.empty,
.summary {
  margin: 0;
}

.map-area {
  min-width: 0;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.leaflet-popup-content {
  margin: 10px 12px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 45%) 1fr;
  }

  .side-panel {
    order: 2;
    box-shadow: none;
  }

  .map-area {
    order: 1;
  }
}
