:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --muted: #6f6a62;
  --line: #e2ddd4;
  --accent: #c8601c;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 6px 0; }

button {
  font: inherit; font-size: 14px; padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer;
}
button:hover { border-color: #c9c2b6; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; font-size: 14px; width: 100%; padding: 7px 9px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.card { background: var(--panel); padding: 28px; border-radius: 12px; width: min(360px, 92vw); border: 1px solid var(--line); }
.card h1 { margin: 0; font-size: 24px; }
.card .primary { width: 100%; margin-top: 6px; }

/* Layout */
.editor {
  display: grid; height: 100vh;
  grid-template-columns: 280px 1fr auto;
  grid-template-rows: 52px 1fr;
  grid-template-areas: "top top top" "side map panel";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; }
.status { flex: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status b { color: var(--accent); }
.actions { display: flex; gap: 6px; }

.sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
.add .label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.add-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0 12px; }
.add-buttons button { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 8px; text-align: left; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.layers details { border-top: 1px solid var(--line); padding: 8px 0; }
.layers summary { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; list-style: none; }
.layers summary::-webkit-details-marker { display: none; }
.layers summary .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.layers summary input { width: auto; margin: 0; }
.layers ul { list-style: none; margin: 6px 0 0; padding: 0; }
.layers li { font-size: 13px; padding: 5px 8px 5px 26px; border-radius: 6px; cursor: pointer; display: flex; gap: 6px; }
.layers li:hover, .layers li.active { background: #f3ede4; }
.layers li .tag { margin-left: auto; font-size: 11px; color: var(--muted); }

.map { grid-area: map; position: relative; }
.panel { grid-area: panel; width: 320px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { font-size: 17px; margin: 0 0 10px; }

.hint {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 5;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px;
}
.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 20; background: var(--ink); color: #fff;
  padding: 10px 14px; border-radius: var(--radius); font-size: 14px; max-width: 360px;
}
.toast.err { background: var(--danger); }

dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 18, 15, .45); }
#dialog-body { padding: 20px; max-height: 80vh; overflow-y: auto; }
#dialog-body h2 { margin: 0 0 12px; font-size: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #f3ede4; font-size: 12px; }
.changes { font-size: 13px; margin: 6px 0 0; padding-left: 18px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
.check input { width: auto; margin: 0; }

/* MapLibre + Draw: mapbox-gl-draw ships mapbox class names */
.maplibregl-ctrl-group button.mapbox-gl-draw_ctrl-draw-btn { background-repeat: no-repeat; background-position: center; }

.downloaders { border: 1px solid var(--line, #ddd); border-radius: 8px; padding: 6px 10px; margin: 0 0 10px; max-height: 180px; overflow-y: auto; }
.downloaders label { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-weight: normal; }
.downloaders input[type=checkbox] { width: auto; margin: 0; }

.pw-box { background: #f6f3ee; border-radius: 10px; padding: 12px 14px; margin-top: 8px; }
.pw { font: 600 22px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; user-select: all; margin-top: 2px; }

.pw-field { display: flex; gap: 6px; align-items: center; }
.pw-field input { flex: 1; }
.pw-toggle { flex: none; }

/* Map / Satellite switch on the map */
.base-switch { display: flex; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 2px rgba(0,0,0,.1); }
.maplibregl-ctrl.base-switch button { border: 0; background: transparent; padding: 6px 12px; font: 600 13px system-ui, sans-serif; color: #333; cursor: pointer; }
.maplibregl-ctrl.base-switch button.on { background: #e8590c; color: #fff; }

/* Satellite imagery cache box in the area panel */
.sat-cache { border: 1px solid #ddd; border-radius: 8px; padding: 8px 12px 12px; margin: 12px 0; }
.sat-cache legend { font-weight: 600; padding: 0 4px; }
.sat-cache progress { width: 100%; height: 8px; }
.sat-cache .check { display: flex; gap: 6px; align-items: center; margin-top: 8px; }

/* Inbox */
.badge { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 10px; background: #e8590c; color: #fff; font-size: 12px; font-weight: 700; margin-left: 4px; }
table.inbox tr.clickable { cursor: pointer; }
table.inbox tr.clickable:hover { background: #fff6ef; }
table.inbox td { padding: 8px 6px; vertical-align: top; border-bottom: 1px solid #eee; }
#sug-view .sug-comment { background: #f5f5f5; border-radius: 8px; padding: 10px; margin: 8px 0; white-space: pre-wrap; }
#sug-view .sug-photo { width: 100%; border-radius: 8px; margin: 6px 0; max-height: 260px; object-fit: cover; background: #eee; min-height: 60px; }
#sug-view textarea { width: 100%; box-sizing: border-box; margin: 10px 0; }
.row.wrap { flex-wrap: wrap; }

/* Add at coordinates */
.coord-box { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.coord-box input { width: 100%; box-sizing: border-box; }
.coord-box .row { display: flex; gap: 6px; }
.coord-box select { flex: 1; min-width: 0; }
.coord-box p { margin: 0; min-height: 16px; }

/* Trips */
.trip-marker { width: 26px; height: 26px; border-radius: 50%; background: #e8590c; color: #fff; font: 700 13px/26px system-ui, sans-serif; text-align: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab; }
#trip-view label { display: block; margin: 8px 0; }
#trip-view input:not([type=time]), #trip-view textarea, #trip-view select { width: 100%; box-sizing: border-box; }
#trip-view .trip-h { font-size: 15px; margin: 16px 0 4px; }
#trip-view .trip-stop { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 8px 0; display: grid; gap: 6px; }
#trip-view .trip-stop-head { display: flex; gap: 4px; align-items: center; }
#trip-view .trip-stop-head input { flex: 1; min-width: 0; }
#trip-view .trip-stop-head button { padding: 2px 6px; }
#trip-view .trip-num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: #e8590c; color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center; cursor: pointer; }
#trip-view .trip-times { display: flex; gap: 6px; }
#trip-view .trip-times label { margin: 0; flex: 1; }
#trip-view .trip-times input { width: 100%; box-sizing: border-box; }
#trip-view a.button { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: inherit; }
.panel:has(#trip-view:not(.hidden)) { width: 420px; }
#trip-view .trip-stop > * { min-width: 0; }
#trip-view .trip-stop-head input { width: auto; }
#trip-view .trip-times input { font-size: 13px; padding: 4px; }
