:root {
  /* Silverback brand palette */
  --bg: #0a0a0a;          /* brand black — dark toolbar/surfaces */
  --bg-2: #161616;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #595a5a;       /* brand charcoal */
  --line: #e4e4e4;
  --accent: #d3303a;      /* brand red */
  --accent-dark: #b1252e;
  --blue: #b3cddf;        /* brand alt blue */
  --light: #eeeeee;       /* brand light gray */
  --toolbar-h: 56px;
  --sidebar-w: 246px;
  --props-w: 284px;
  font-family: 'Helvetica Neue', 'Inter', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); }
/* the `hidden` attribute must win over explicit display rules below */
[hidden] { display: none !important; }

/* ===== Toolbar ===== */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--toolbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--bg); color: #f2f2f2; z-index: 1000;
  box-shadow: 0 2px 0 var(--accent), 0 3px 10px rgba(0,0,0,.35);
  overflow-x: auto; scrollbar-width: thin;
}
#toolbar::-webkit-scrollbar { height: 5px; }
#toolbar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-spacer { flex: 1; }
.tb-brand { gap: 10px; padding-right: 12px; border-right: 2px solid var(--accent); }
#brandLogo { height: 38px; width: auto; display: block; }
#projectName {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.16);
  color: #fff; border-radius: 6px; padding: 7px 9px; width: 178px; font-size: 13px; font-weight: 600;
}
#projectName:focus { outline: none; border-color: var(--accent); }
.tools { padding: 0 6px; border-left: 1px solid rgba(255,255,255,.12); border-right: 1px solid rgba(255,255,255,.12); }

.tool {
  background: rgba(255,255,255,.09); color: #ededed; border: 1px solid transparent;
  border-radius: 7px; padding: 8px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  letter-spacing: .01em;
}
.tool:hover { background: rgba(255,255,255,.17); }
.tool.active { background: var(--accent); color: #fff; box-shadow: 0 0 0 1px var(--accent); }
.tool.ghost { background: transparent; border-color: rgba(255,255,255,.16); }
.tool.ghost:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); }
.tool.primary { background: var(--accent); color: #fff; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.tool.primary:hover { background: var(--accent-dark); }

/* Dropdowns */
.dropdown { position: relative; }
.menu {
  /* fixed so the toolbar's overflow-x scroll container can't clip it */
  position: fixed; min-width: 214px; max-height: 70vh; overflow-y: auto;
  background: #fff; color: var(--ink); border-radius: 10px; padding: 6px;
  box-shadow: 0 14px 34px rgba(0,0,0,.30); display: none; z-index: 1200;
  border-top: 3px solid var(--accent);
}
.menu.open { display: block; }
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: transparent; border: none; padding: 8px 10px; border-radius: 7px;
  font-size: 13px; cursor: pointer; color: var(--ink); font-weight: 500;
}
.menu button:hover { background: var(--light); }
.menu .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }

/* ===== Sidebar ===== */
#sidebar {
  position: fixed; top: var(--toolbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--light); border-right: 1px solid #dcdcdc; overflow-y: auto; z-index: 800;
  padding: 12px;
}
.panel { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.panel h3 {
  margin: 0 0 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink); font-weight: 800; border-left: 3px solid var(--accent); padding-left: 8px;
}

.layers { display: flex; flex-direction: column; gap: 4px; }
.layer-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 2px; }
.layer-row input { accent-color: var(--accent); }
.layer-row .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.layer-row .count { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 700; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 8px; }
.mini { display: inline-block; width: 100%; text-align: center; background: var(--light); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px; font-size: 12px; font-weight: 600; cursor: pointer; margin-top: 6px; }
.mini:hover { background: #fdecec; color: var(--accent); border-color: #f3c9cc; }
.mini.danger { background: #fdecec; color: var(--accent); border-color: #f3c9cc; }
.mini.danger:hover { background: #f9d7d9; }
.mini.full { width: 100%; }
.hint { color: var(--muted); font-size: 11px; margin: 8px 0 0; line-height: 1.4; }
.tips { margin: 0; padding-left: 16px; font-size: 12px; color: #4a4a4a; line-height: 1.6; }
.tips b { color: var(--ink); }

/* ===== Properties ===== */
#props {
  position: fixed; top: calc(var(--toolbar-h) + 12px); right: 12px; width: var(--props-w);
  background: #fff; border: 1px solid var(--line); border-radius: 12px; z-index: 900;
  box-shadow: 0 16px 44px rgba(0,0,0,.20); border-top: 3px solid var(--accent);
}
.props-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.props-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; font-weight: 800; }
.x { background: transparent; border: none; font-size: 15px; cursor: pointer; color: var(--muted); }
.props-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.fld input, .fld select, .fld textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 13px; color: var(--ink);
  font-family: inherit; font-weight: 400; text-transform: none; letter-spacing: normal;
}
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--accent); }
.fld input[type=color] { padding: 2px; height: 36px; }
.fld textarea { resize: vertical; }
.edit-hint { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.45;
  background: var(--light); padding: 8px 10px; border-radius: 7px; border-left: 3px solid var(--accent); }
.route-stat { margin: 0; font-size: 13px; color: var(--ink); background: var(--light);
  padding: 9px 10px; border-radius: 7px; border-left: 3px solid var(--accent); }
.route-stat b { color: var(--accent); font-weight: 800; }

/* ===== Map ===== */
#map { position: fixed; top: var(--toolbar-h); left: var(--sidebar-w); right: 0; bottom: 0; background: #d8dee4; }
body.view-mode #sidebar { transform: translateX(-100%); }
body.view-mode #map { left: 0; }
body.view-mode .tools, body.view-mode #saveBtn, body.view-mode #loadBtn,
body.view-mode #imageBtn, body.view-mode #shareBtn, body.view-mode #projectName { display: none; }

/* POI markers */
.poi-icon { background: none; border: none; }
.poi-pin {
  width: 30px; height: 30px; background: var(--pin, #334155); border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,.4); border: 2px solid #fff;
}
.poi-pin span { transform: rotate(45deg); font-size: 15px; line-height: 1; }
.leaflet-tooltip.label-tip {
  background: rgba(10,10,10,.86); color: #fff; border: none; box-shadow: none;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px; letter-spacing: .01em;
}
.leaflet-tooltip.label-tip::before { display: none; }
.text-note {
  background: none; border: none; font-weight: 800; color: var(--pin, #0f172a);
  font-size: 14px; text-shadow: 0 1px 3px rgba(255,255,255,.9), 0 0 3px rgba(255,255,255,.9); white-space: nowrap;
}

/* Corner handles for image repositioning */
.corner-handle {
  width: 18px; height: 18px; background: var(--accent); border: 3px solid #fff;
  border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab;
}

/* ===== Map legend (also captured in exports & view mode) ===== */
.map-legend {
  background: #fff; border-radius: 10px; padding: 0; min-width: 168px; max-width: 250px;
  box-shadow: 0 6px 22px rgba(0,0,0,.28); border: 1px solid #d9d9d9; overflow: hidden;
  font-family: 'Helvetica Neue', 'Inter', Arial, sans-serif;
}
.legend-title {
  background: var(--bg); color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .04em;
  padding: 8px 11px; text-transform: uppercase; border-bottom: 3px solid var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.legend-items { padding: 8px 11px; display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink); font-weight: 500; }
.legend-item .lg-pin {
  width: 18px; height: 18px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--c, #334155); display: flex; align-items: center; justify-content: center;
  border: 1.5px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); flex: none;
}
.legend-item .lg-pin span { transform: rotate(45deg); font-size: 9px; line-height: 1; }
.legend-item .lg-line { width: 20px; height: 4px; border-radius: 2px; background: var(--c); flex: none; }
.legend-item .lg-fill { width: 16px; height: 14px; border-radius: 3px; background: var(--c); opacity: .55; border: 1.5px solid var(--c); flex: none; }
.legend-foot { padding: 6px 11px; border-top: 1px solid var(--line); font-size: 9px; font-weight: 800;
  letter-spacing: .12em; color: var(--muted); text-transform: uppercase; text-align: right; }
.legend-foot b { color: var(--accent); }
.legend-empty { padding: 10px 11px; font-size: 11px; color: var(--muted); }

/* ===== View banner ===== */
#viewBanner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 950;
  background: var(--bg); color: #fff; padding: 9px 15px; border-radius: 22px;
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.12);
}
#viewBanner button { background: var(--accent); color: #fff; border: none; border-radius: 13px; padding: 5px 11px; cursor: pointer; font-size: 12px; font-weight: 700; }
#viewBanner button:hover { background: var(--accent-dark); }

/* ===== Overlay ===== */
#overlay { position: fixed; inset: 0; background: rgba(10,10,10,.60); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.ov-card { background: #fff; border-radius: 14px; padding: 26px 34px; text-align: center; min-width: 280px; border-top: 4px solid var(--accent); }
.ov-card p { margin: 14px 0 12px; font-size: 14px; font-weight: 600; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--light); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ov-bar { height: 7px; background: var(--light); border-radius: 4px; overflow: hidden; }
#ovFill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.book-grid-cell { outline: 2px dashed var(--accent); }
.book-grid-num { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }
