:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --text: #24221f;
  --muted: #77726a;
  --line: #e4dfd6;
  --accent: #8a4b2a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --green: #2e9e5b;
  --gold: #d4a017;
  --gray: #8a8f98;
  --blue: #5b7fd6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 0.9em; }
.viewer .editor-only { display: none !important; }

button, .file-btn {
  font: inherit; font-size: 0.92rem;
  padding: 0.45rem 0.8rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  cursor: pointer;
}
button:hover, .file-btn:hover { border-color: #c9c1b4; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); border-color: #e8c4c1; }
button.ghost { background: transparent; }
button.link { border: 0; padding: 0; background: none; font-weight: 600; text-align: left; color: var(--text); }
button.link:hover { color: var(--accent); text-decoration: underline; }
button.icon { padding: 0.15rem 0.45rem; font-size: 0.85rem; }

input, select, textarea {
  font: inherit; width: 100%;
  padding: 0.45rem 0.55rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #c98b63; outline-offset: 1px; }

/* Pasek górny */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.brand .logo { width: 34px; height: 34px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.2rem; letter-spacing: -0.01em; }
.brand-text .muted { font-size: 0.78rem; }
.draft-note { margin: 0; font-size: 0.82rem; background: #fff4d6; border: 1px solid #f0d98a; color: #6b4f00; padding: 0.35rem 0.6rem; border-radius: 8px; }
.badge-test { font-size: 0.75rem; background: #fff4d6; color: #7a5a00; border: 1px solid #f0d98a; padding: 0.1rem 0.45rem; border-radius: 99px; }
.city-search { position: relative; flex: 1 1 220px; max-width: 360px; }
.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-left: auto; }

.dropdown {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 0.25rem; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.dropdown li { padding: 0.45rem 0.55rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.dropdown li:hover, .dropdown li.active { background: #f3ede5; }

/* Układ */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
#map { min-height: 300px; }
#sidebar {
  overflow-y: auto; padding: 0.8rem; background: var(--bg); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 0.7rem;
}

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 0.6rem; }
.stat .num { font-size: 1.3rem; font-weight: 700; }
.stat .lbl { font-size: 0.78rem; color: var(--muted); }
.stat .val { font-size: 0.78rem; }

.filters { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chip { border-radius: 99px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

.list-section h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0.6rem 0 0.4rem; }
.list-section .empty { color: var(--muted); font-size: 0.9rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.7rem; margin-bottom: 0.5rem; }
.card.highlight { border-color: var(--accent); box-shadow: 0 0 0 2px #e9cdb9; }
.card-head { display: flex; align-items: center; gap: 0.45rem; }
.card-head .title { flex: 1; min-width: 0; }
.card-sub { font-size: 0.82rem; color: var(--muted); margin: 0.15rem 0 0.35rem 1.15rem; }
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; }

.paintings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.painting { display: flex; align-items: center; gap: 0.5rem; }
.thumb { width: 42px; height: 42px; border-radius: 6px; object-fit: cover; flex: none; background: #eee7dc; border: 0; padding: 0; cursor: zoom-in; }
.thumb.empty { cursor: default; display: inline-flex; align-items: center; justify-content: center; color: #b4aa9b; font-size: 1.1rem; }
.painting .info { flex: 1; min-width: 0; font-size: 0.9rem; }
.painting .info .meta { font-size: 0.78rem; color: var(--muted); }
.status { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 99px; color: #fff; white-space: nowrap; }
.status-select { width: auto; font-size: 0.78rem; padding: 0.15rem 0.3rem; }
.add-here { margin-top: 0.45rem; font-size: 0.82rem; padding: 0.25rem 0.6rem; }

/* Pinezki */
.gm-marker span {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  color: #fff; font-weight: 700; font-size: 13px;
}
.home-marker span {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; transform: rotate(45deg);
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.home-marker span::after { content: "R"; transform: rotate(-45deg); color: #fff; font-weight: 800; }
.legend { background: #fff; padding: 0.45rem 0.6rem; border-radius: 8px; box-shadow: 0 1px 5px rgba(0,0,0,.25); font-size: 0.78rem; line-height: 1.6; }
.legend i { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.35rem; vertical-align: -1px; }

.popup h4 { margin: 0 0 0.2rem; font-size: 1rem; }
.popup .addr { color: var(--muted); font-size: 0.85rem; }
.popup .contact { font-size: 0.82rem; margin: 0.3rem 0; }
.popup .paintings { margin: 0.4rem 0; max-height: 220px; overflow-y: auto; }
.popup .popup-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.popup .popup-actions button { font-size: 0.8rem; padding: 0.25rem 0.55rem; }
.leaflet-popup-content { margin: 0.7rem 0.8rem; min-width: 220px; }

/* Okna dialogowe */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 1.5rem); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(30, 25, 20, .45); }
dialog form { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; }
dialog h2 { margin: 0; font-size: 1.2rem; }
dialog label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
dialog fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 0.7rem 0.7rem; display: flex; flex-direction: column; gap: 0.5rem; margin: 0; }
dialog legend { font-size: 0.85rem; color: var(--muted); padding: 0 0.3rem; }
.hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.mini-map { height: 220px; border-radius: var(--radius); border: 1px solid var(--line); }
.dialog-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.3rem; }
.spacer { flex: 1; }
.photo-field { display: flex; gap: 0.8rem; align-items: center; }
.photo-field > div { display: flex; gap: 0.5rem; flex-wrap: wrap; }
#p-photo-preview { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; }
.file-btn { display: inline-block; color: var(--text) !important; }
.file-btn input { display: none; }
.photo-dialog { width: auto; max-width: calc(100vw - 1.5rem); padding: 0.6rem; }
.photo-dialog img { display: block; max-width: 100%; max-height: calc(100vh - 7rem); border-radius: 8px; margin: 0 auto; }

#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 3000;
  background: #2b2724; color: #fff; padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 2rem);
}
#toast.error { background: var(--danger); }

/* Telefon */
@media (max-width: 800px) {
  body { height: auto; min-height: 100%; }
  .layout { grid-template-columns: 1fr; }
  #map { height: 55vh; }
  #sidebar { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .city-search { max-width: none; order: 3; flex-basis: 100%; }
  .actions { margin-left: 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .legend { display: flex; flex-wrap: wrap; gap: 0 0.6rem; font-size: 0.68rem; line-height: 1.4; padding: 0.25rem 0.45rem; max-width: 220px; opacity: 0.9; }
}
