/* --------------------------------------------------------------------------
   Layout
   #sheet is the printable area and the only thing that survives @media print.
   #scaler exists so print rendering can happen at 2x tile density and then be
   scaled back down, see js/tools/print.js.
   -------------------------------------------------------------------------- */

:root {
  --panel-bg: #fff;
  --panel-border: #ddd;
  --accent: #d40000;
  --shadow: 0 1px 6px rgba(0, 0, 0, .4);
}

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #4a4a4a;
}

#sheet {
  position: absolute;
  inset: 0;
  background: #fff;
  overflow: hidden;
}

#scaler {
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #eee;
}

#sheet-title {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  padding: 3mm 4mm;
  font-size: 14pt;
  font-weight: 600;
  color: #111;
  background: linear-gradient(rgba(255, 255, 255, .92), rgba(255, 255, 255, 0));
  pointer-events: none;
}

#sheet-title[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Sector labels
   -------------------------------------------------------------------------- */

.sector-label {
  background: none;
  border: none;
  box-shadow: none;
  font-weight: 700;
  color: var(--accent);
  font-size: 11px;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
  /* divIcon is positioned by its top-left; nudge so the text centres on the
     polygon's anchor point. */
  transform: translate(-50%, -50%);
  width: max-content;
}

/* --------------------------------------------------------------------------
   Control panel
   -------------------------------------------------------------------------- */

#panel {
  position: absolute;
  /* Clear of #panel-toggle, which sits in the top-right corner. */
  top: 52px;
  right: 10px;
  z-index: 1000;
  width: 230px;
  max-height: calc(100vh - 62px);
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  font-size: 12px;
}

#panel[hidden] { display: none; }

.panel-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--panel-border);
  background: #f6f6f6;
}

.panel-tabs button {
  flex: 1;
  padding: 6px 4px;
  font: inherit;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: none;
  cursor: pointer;
  color: #555;
}

.panel-tabs button:hover { background: #ececec; }

.panel-tabs button[aria-selected="true"] {
  background: var(--panel-bg);
  border-color: var(--panel-border);
  color: #111;
  font-weight: 600;
  margin-bottom: -1px;
}

#panel-body {
  padding: 10px;
  overflow: auto;
}

#panel-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1001;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

/* Shared widgets for tool panels */

.field {
  display: block;
  margin: 0 0 10px;
}

.field > span {
  display: block;
  margin-bottom: 3px;
  color: #555;
}

.field select,
.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
  font: inherit;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: #fff;
}

.field input[type="range"] { width: 100%; }

.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
}

.segmented {
  display: flex;
  gap: 0;
}

.segmented button {
  flex: 1;
  padding: 5px 4px;
  font: inherit;
  border: 1px solid var(--panel-border);
  background: #fafafa;
  cursor: pointer;
  color: #333;
}

.segmented button:first-child { border-radius: 5px 0 0 5px; }
.segmented button:last-child  { border-radius: 0 5px 5px 0; }
.segmented button + button    { border-left: none; }

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 8px;
  font: inherit;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: #fafafa;
  cursor: pointer;
  text-align: center;
}

.btn:hover { background: #f0f0f0; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: #b00000; }

.btn-list {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  margin: 2px 0;
  padding: 4px 6px;
  font: inherit;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: #fafafa;
  cursor: pointer;
}

.btn-list:hover { background: #fee; }

.hint {
  margin: 8px 0 0;
  color: #777;
  line-height: 1.4;
}

.divider {
  margin: 12px 0;
  border: none;
  border-top: 1px solid #eee;
}

/* --------------------------------------------------------------------------
   Print layout mode (on screen)
   The map stays full-window and interactive; a paper-shaped frame shows the
   extent that will be printed and everything outside it is dimmed.
   -------------------------------------------------------------------------- */

#extent-frame {
  position: absolute;
  inset: 0;
  z-index: 900;
  pointer-events: none;
}

#extent-frame[hidden] { display: none; }

.extent-mask {
  position: absolute;
  background: rgba(30, 30, 30, .45);
}

.extent-box {
  position: absolute;
  outline: 1px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
}

.extent-label {
  position: absolute;
  top: -24px;
  left: 0;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(30, 30, 30, .75);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
}

/* While the sheet is sized to paper for the actual print, keep it visible and
   centred so the transition is not jarring if the print dialog is slow. */
body.printing #sheet {
  position: absolute;
  inset: auto;
  top: 0;
  left: 0;
  box-shadow: 0 0 30px rgba(0, 0, 0, .5);
}

body.printing #panel,
body.printing #panel-toggle,
body.printing #extent-frame { display: none; }

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
  html, body {
    background: #fff;
    width: auto;
    height: auto;
    overflow: visible;
  }

  /* Only the sheet prints. */
  body > *:not(#sheet) { display: none !important; }

  body.printing #sheet {
    position: static;
    box-shadow: none;
    /* width/height are set inline in mm by the print tool */
  }

  /* Leaflet's zoom/attribution controls are UI, not map content. The
     attribution itself is kept — it is a licence requirement. */
  .leaflet-control-zoom,
  .leaflet-control-layers { display: none !important; }

  .leaflet-control-attribution {
    background: rgba(255, 255, 255, .8) !important;
    font-size: 7pt;
  }

  .leaflet-container { background: #fff; }
}
