/* Terrain map. Loads after bico-theme.css. */

/* Legacy token names kept alive so terrain-admin.css keeps working untouched. */
body.bico-nocturne {
  --parchment:      #f3e9d2;
  --parchment-deep: #e8d9b8;
  --ink:            #2b2116;
  --ink-soft:       #55452f;
  --gold-soft:      #d4af6a;
  --panel:          var(--surface-1);
  --panel-line:     var(--border);
}

/* ---- layout inside the shared shell ---- */
body.bico-nocturne .bico-main.is-wide {
  position: relative;
  flex: 1;
  min-height: 0;
}

.terrain-shell { position: absolute; inset: 0; }

.terrain-main { position: absolute; inset: 0 0 0 300px; }

#map {
  width: 100%;
  height: 100%;
  background: var(--surface-0);
}

/* ---- sidebar ---- */
.terrain-sidebar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 300px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1100;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: var(--pad-md) var(--pad-md) var(--pad-sm);
  padding: 8px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.sidebar-search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.category-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.cat-section { margin-bottom: 4px; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  padding: 9px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}
.cat-head:hover { background: var(--surface-2); }
.cat-head > span:first-of-type { flex: 1; min-width: 0; }
.cat-head .bx { font-size: 18px; }

.cat-count {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 1px 9px;
  font-variant-numeric: tabular-nums;
}

.cat-eye { color: var(--text-muted); }
.cat-head:hover .cat-eye { color: var(--gold); }
.cat-off > .cat-head { opacity: 0.45; }

.cat-items { list-style: none; margin: 0; padding: 0 0 4px 36px; }
.cat-items a {
  display: block;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
}
.cat-items a:hover { color: var(--gold); background: var(--surface-2); text-decoration: none; }
.cat-off > .cat-items { display: none; }

.cat-empty { color: var(--text-muted); font-style: italic; padding: 18px; font-family: var(--font-prose); }

.cat-sub { margin-left: 14px; border-left: 1px solid var(--border); }
.cat-sub-head { font-size: 13px; padding: 7px 9px; }
.cat-sub-off .cat-items { display: none; }
.cat-sub-off .cat-sub-head { opacity: 0.45; }

.sidebar-foot {
  padding: var(--pad-sm) var(--pad-md) var(--pad-md);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
}
.artist-credit {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.45;
  margin-bottom: 6px;
}
.artist-credit .bx { font-size: 15px; margin-top: 1px; flex-shrink: 0; color: var(--gold); }

/* ---- suggest ---- */
.suggest-box { padding: var(--pad-sm) var(--pad-md) 0; }
.btn-suggest {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  color: #1c150f;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}
.btn-suggest:hover { background: var(--gold-soft); }
.suggest-login {
  display: block;
  text-align: center;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.suggest-login:hover { border-color: var(--gold-soft); color: var(--gold); text-decoration: none; }

.suggest-cursor { cursor: crosshair; }
.pin-suggest { border-style: dashed; }

.suggest-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  background: var(--parchment);
  border: 1px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  z-index: 1150;
  overflow: hidden;
}
.suggest-panel[hidden] { display: none; }

.suggest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 15px;
  background: #241c15;
  color: var(--bar-gold);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
}
.suggest-head button {
  background: transparent;
  border: none;
  color: var(--bar-gold);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.suggest-body { padding: var(--pad-md) 15px 15px; overflow-y: auto; }
.s-field { display: block; margin-bottom: var(--gap-sm); }
.s-field > span {
  display: block;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.s-field input, .s-field select, .s-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid rgba(138, 106, 38, 0.4);
  border-radius: var(--radius);
  background: #fffdf7;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
}
.s-field input:focus, .s-field select:focus, .s-field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 169, 76, 0.25);
}
.s-field textarea { resize: vertical; }

.suggest-msg, .editor-msg {
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-ui);
  font-size: 13.5px;
  margin-bottom: var(--gap-sm);
  border: 1px solid;
  border-left-width: 3px;
}
.suggest-msg.ok { background: #e9efdf; border-color: #6b7d5a; color: #3d4a31; }
.suggest-msg.err { background: #f6e2dd; border-color: #b2503d; color: #7c2f20; }

.btn-suggest-send {
  width: 100%;
  padding: 10px;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  color: #1c150f;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}
.btn-suggest-send:hover { background: var(--gold-soft); }

/* ---- markers ---- */
.terrain-pin-wrap { background: transparent; border: none; }

.terrain-pin {
  --pin: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--parchment);
  border: 2px solid var(--pin);
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.45);
}
.terrain-pin .bx {
  transform: rotate(45deg);
  font-size: 17px;
  color: var(--pin);
}

.terrain-pin-free {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}
.terrain-pin-free .pin-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter:
    drop-shadow(1px 0 0 var(--pin))
    drop-shadow(-1px 0 0 var(--pin))
    drop-shadow(0 1px 0 var(--pin))
    drop-shadow(0 -1px 0 var(--pin))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

/* ---- popups ---- */
.leaflet-popup-content-wrapper {
  background: var(--parchment);
  color: var(--ink);
  border: 1px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.leaflet-popup-tip { background: var(--gold); }
.leaflet-popup-content {
  margin: 16px 18px;
  max-height: 68vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) transparent;
}
.leaflet-popup-close-button { color: var(--ink-soft) !important; }

.terrain-popup .tp-img-link { display: block; margin: -6px -6px 12px; }
.terrain-popup .tp-img {
  display: block;
  width: 100%;
  max-height: 42vh;
  height: auto;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid rgba(138, 106, 38, 0.4);
}
.terrain-popup .tp-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 21px;
  color: var(--ink);
  margin-bottom: 6px;
}
.terrain-popup .tp-desc {
  font-family: var(--font-prose);
  font-size: 16px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.terrain-popup .tp-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  color: #8a6a26;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 15px;
}
.terrain-popup .tp-link:hover { text-decoration: underline; }
.terrain-popup .tp-web { margin-left: 14px; }
.terrain-popup .tp-web .bx { vertical-align: middle; }

.tp-guild {
  margin-top: 12px;
  padding: 11px 13px;
  background: rgba(184, 134, 11, 0.09);
  border: 1px solid rgba(138, 106, 38, 0.35);
  border-radius: var(--radius);
}
.tp-guild-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  color: #8a6a26;
  margin-bottom: 7px;
}
.tp-guild-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-ui);
  font-size: 15px;
  padding: 3px 0;
}
.tp-guild-label {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-top: 3px;
}
.tp-guild-value { color: var(--ink); font-weight: 500; text-align: right; }

.tp-events {
  margin-top: 12px;
  padding: 11px 13px;
  background: rgba(43, 33, 22, 0.05);
  border: 1px solid rgba(138, 106, 38, 0.35);
  border-radius: var(--radius);
}
.tp-events-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  color: var(--ink);
  margin-bottom: 7px;
}
.tp-event {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0;
  font-family: var(--font-ui);
  font-size: 15px;
  border-bottom: 1px solid rgba(85, 69, 47, 0.2);
}
.tp-event:last-child { border-bottom: none; }
.tp-event-title { color: var(--ink); font-weight: 500; }
.tp-event-when { color: var(--ink-soft); white-space: nowrap; text-align: right; }

/* ---- map chrome ---- */
.coord-badge {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--gold);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 15px;
  font-family: var(--font-ui);
  font-size: 13px;
  z-index: 1200;
  white-space: pre;
}

.map-credit {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(20, 17, 13, 0.85);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 5px 11px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  pointer-events: none;
}

.leaflet-control-attribution {
  background: rgba(20, 17, 13, 0.78) !important;
  color: var(--text-muted) !important;
  font-family: var(--font-ui);
  font-size: 11px;
}
.leaflet-control-attribution a { color: var(--gold-soft) !important; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-bottom-color: var(--border);
}
.leaflet-bar a:hover { color: var(--gold); }

/* ---- mobile drawer ---- */
.drawer-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1300;
  width: 44px;
  height: 44px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--gold);
  font-size: 22px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 820px) {
  .terrain-main { inset: 0; }
  .drawer-toggle { display: flex; }
  .terrain-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: min(300px, 85vw);
    box-shadow: 6px 0 22px rgba(0, 0, 0, 0.5);
  }
  .terrain-sidebar.open { transform: translateX(0); }
  .map-credit { font-size: 10.5px; bottom: 8px; right: 8px; }
  .suggest-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 62vh;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .terrain-sidebar { transition: none; }
}
