:root {
  --bg: #C8DFDB;
  --panel: #ffffff;
  --text: #191919;
  --muted: #6d6d69;
  --line: #d9d9d5;
  --unvisited: #F2EFE7;
  --lenka: #E76F51;
  --jachym: #111111;
  --together: #249D8F;
  --albert: #E9C46A;
  --shadow: 0 18px 50px rgba(0,0,0,.16);
}

* { box-sizing: border-box; }
html, body, #app, #map { width: 100%; height: 100%; margin: 0; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

#map { background: #C8DFDB; z-index: 1; }
.leaflet-container { background: #C8DFDB; }
.leaflet-control-attribution { font-size: 10px; opacity: .78; }
.leaflet-interactive { transition: fill .18s ease, fill-opacity .18s ease, stroke-width .18s ease; }
.leaflet-interactive:focus { outline: none; }

.app-title {
  position: fixed; z-index: 500; top: 18px; left: 18px;
  background: rgba(255,255,255,.93); backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,.08); border-radius: 14px;
  padding: 10px 13px; box-shadow: 0 8px 26px rgba(0,0,0,.08);
  display: flex; gap: 10px; align-items: baseline;
}
.app-title span { color: var(--muted); font-size: 12px; }

.toolbar {
  position: fixed; z-index: 500; top: 18px; right: 64px;
  display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end;
  max-width: calc(100vw - 360px);
}

.btn {
  border: 0; border-radius: 10px; min-height: 38px; padding: 8px 12px;
  font-weight: 650; font-size: 13px; transition: transform .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-light { background: rgba(255,255,255,.94); border: 1px solid rgba(0,0,0,.09); box-shadow: 0 6px 18px rgba(0,0,0,.06); }
.btn-primary { background: #202020; color: #fff; }
.btn-secondary { background: #efefec; color: #202020; border: 1px solid #dddcd7; }
.btn-ghost { background: transparent; color: var(--muted); }
.file-label { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }

.legend {
  position: fixed; z-index: 500; left: 18px; bottom: 18px;
  background: rgba(255,255,255,.94); backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,.08); border-radius: 12px;
  padding: 10px 12px; box-shadow: 0 8px 26px rgba(0,0,0,.08);
  display: grid; gap: 6px; font-size: 12px;
}
.legend div { display: flex; gap: 8px; align-items: center; }
.swatch { width: 14px; height: 14px; display: inline-block; border: 1px solid #6f6f6b; border-radius: 3px; }
.swatch.unvisited { background: var(--unvisited); }
.swatch.lenka { background: var(--lenka); }
.swatch.jachym { background: var(--jachym); }
.swatch.together { background: var(--together); }
.swatch.albert { background: var(--albert); }

.panel {
  position: fixed; z-index: 800; top: 0; right: 0; bottom: 0; width: min(440px, 94vw);
  background: var(--panel); box-shadow: var(--shadow); transform: translateX(105%);
  transition: transform .24s ease; overflow-y: auto; padding: 22px;
}
.panel.open { transform: translateX(0); }
.panel-header { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.panel h1 { margin: 2px 0 4px; font-size: 27px; line-height: 1.1; }
.panel h2 { margin: 0; font-size: 16px; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .11em; font-weight: 800; color: var(--muted); }
.muted { color: var(--muted); font-size: 12px; }
.icon-btn { width: 36px; height: 36px; border: 0; background: #f1f1ef; border-radius: 50%; font-size: 24px; line-height: 1; }
.panel-actions { display: flex; gap: 10px; align-items: center; margin: 14px 0 4px; }
.status { font-size: 11px; color: var(--muted); }
.section { padding: 19px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.badge { display: inline-flex; min-width: 25px; height: 25px; align-items: center; justify-content: center; border-radius: 999px; background: #efefec; font-size: 12px; font-weight: 700; }
.visits-list { display: grid; gap: 9px; }
.empty-state { padding: 15px; background: #f6f6f3; border-radius: 10px; color: var(--muted); font-size: 13px; }
.visit-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.visit-card-top { display: flex; justify-content: space-between; gap: 12px; }
.visit-date { font-weight: 760; font-size: 13px; }
.visit-visitors { font-size: 12px; color: var(--muted); margin-top: 3px; }
.visit-cities { margin-top: 9px; font-size: 13px; }
.visit-notes { margin-top: 7px; font-size: 12px; line-height: 1.45; color: #454542; white-space: pre-wrap; }
.card-actions { display: flex; gap: 5px; }
.small-btn { border: 0; border-radius: 8px; padding: 5px 7px; font-size: 11px; background: #f1f1ef; }
.small-btn.danger { color: #9e2525; background: #fff0f0; }

.visit-form-section h2 { margin-bottom: 13px; }
form { display: grid; gap: 13px; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 650; }
label span, legend { color: #4d4d49; }
input[type="date"], input[type="text"], textarea {
  width: 100%; border: 1px solid #d7d7d2; background: #fafaf8; border-radius: 9px;
  padding: 10px 11px; color: var(--text); outline: none;
}
input:focus, textarea:focus { border-color: #7e7e78; box-shadow: 0 0 0 3px rgba(0,0,0,.05); }
textarea { resize: vertical; min-height: 90px; }
small { font-weight: 400; color: var(--muted); }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 12px; font-weight: 650; margin-bottom: 7px; }
.checks { display: flex; gap: 7px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 6px; padding: 8px 9px; background: #f5f5f2; border-radius: 9px; font-weight: 600; }
.form-actions { display: flex; gap: 8px; }
.form-error { min-height: 1px; font-size: 12px; color: #b3261e; }

.modal-backdrop { position: fixed; z-index: 1200; inset: 0; background: rgba(0,0,0,.36); padding: 4vh 4vw; }
.modal { width: 100%; height: 100%; max-width: 1250px; margin: 0 auto; background: #fff; border-radius: 18px; box-shadow: var(--shadow); display: grid; grid-template-rows: auto auto 1fr; overflow: hidden; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 19px 20px 12px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 2px 0 0; }
.modal-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px; background: #fafaf8; border-bottom: 1px solid var(--line); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { text-align: left; vertical-align: top; border-bottom: 1px solid #C8DFDB; padding: 10px 12px; font-size: 12px; }
th { position: sticky; top: 0; background: #f5f5f2; z-index: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.table-sort-button { width: 100%; display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; text-align: left; }
.table-sort-button:hover { color: #000; }
.table-sort-button:focus-visible { outline: 2px solid #777; outline-offset: 3px; border-radius: 2px; }
.sort-indicator { display: inline-block; min-width: 1em; font-size: 9px; opacity: .65; }
th[aria-sort="ascending"] .sort-indicator, th[aria-sort="descending"] .sort-indicator { opacity: 1; }
td.notes-cell { max-width: 360px; white-space: pre-wrap; }

.loading-overlay { position: fixed; z-index: 1600; inset: 0; background: #efefec; display: grid; place-items: center; }
.loader-card { display: grid; place-items: center; gap: 9px; color: #3d3d39; }
.loader-card span { color: var(--muted); font-size: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid #d3d3cf; border-top-color: #343431; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 2000; left: 50%; bottom: 28px; transform: translateX(-50%); padding: 10px 14px; background: #202020; color: #fff; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 820px) {
  .toolbar { top: auto; bottom: 18px; left: 18px; right: 18px; max-width: none; justify-content: center; }
  .legend { bottom: 78px; }
  .app-title { max-width: calc(100vw - 90px); }
  .panel { padding: 18px; }
  .two-cols { grid-template-columns: 1fr; }
}

.btn-warning { background: #fff1c7; color: #5f4700; border: 1px solid #e8ce75; }
.server-status {
  min-height: 38px; padding: 8px 11px; display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.94); border: 1px solid rgba(0,0,0,.09); border-radius: 10px;
  font-size: 11px; font-weight: 700; color: var(--muted); box-shadow: 0 6px 18px rgba(0,0,0,.06);
}
.server-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #aaa; }
.server-status[data-state="online"]::before { background: #2f9e44; }
.server-status[data-state="offline"]::before { background: #d9480f; }
.server-status[data-state="reconnecting"]::before,
.server-status[data-state="connecting"]::before { background: #d6a514; }
