/* Sheet Layout, Zebra Neatline Border, Title Block & Submaps v2.0 */

/* Sheet Container */
.sheet-wrapper {
  transition: transform 0.15s ease-out;
  transform-origin: center center;
}

.map-sheet {
  background: #ffffff;
  color: #111827;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  box-sizing: border-box;
  overflow: hidden;
  user-select: none;
}

/* Sheet Dimensions */
.map-sheet.a4-landscape {
  width: 1123px;  /* 297mm @ 96 DPI */
  height: 794px;  /* 210mm */
}

.map-sheet.a4-portrait {
  width: 794px;   /* 210mm */
  height: 1123px; /* 297mm */
}

.map-sheet.a3-landscape {
  width: 1587px;  /* 420mm */
  height: 1123px; /* 297mm */
}

.map-sheet.a3-portrait {
  width: 1123px;  /* 297mm */
  height: 1587px; /* 420mm */
}

/* Margin and Outer Frame */
.sheet-inner {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  bottom: 18px;
  border: 1.5px solid #111827;
  display: flex;
  flex-direction: column;
}

/* Default Layout Structure (Standard Avanzik: Map left, sidebar right) */
.layout-body {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Main Map Framing */
.main-map-container {
  flex: 1;
  position: relative;
  border-right: 1.5px solid #111827;
  overflow: hidden;
}

/* Zebra Neatline Frame */
.zebra-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 400;
}

/* The actual leaflet map under the zebra border */
.main-leaflet-map {
  position: absolute;
  top: 21px;
  left: 77px;
  right: 21px;
  bottom: 37px;
  background: #f8fafc;
  z-index: 10;
}

/* Zebra Border Elements */
.zebra-border-top,
.zebra-border-bottom {
  position: absolute;
  left: 48px;
  right: 26px;
  height: 10px;
  display: flex;
  border: 1px solid #111827;
}

.zebra-border-top {
  top: 16px;
}

.zebra-border-bottom {
  bottom: 38px;
}

.zebra-border-left,
.zebra-border-right {
  position: absolute;
  top: 26px;
  bottom: 48px;
  width: 10px;
  display: flex;
  flex-direction: column;
  border: 1px solid #111827;
}

.zebra-border-left {
  left: 38px;
}

.zebra-border-right {
  right: 16px;
}

.zebra-segment {
  flex: 1;
  border-right: 0.5px solid #111827;
}
.zebra-segment.black { background-color: #111827; }
.zebra-segment.white { background-color: #ffffff; }

.zebra-segment-v {
  flex: 1;
  border-bottom: 0.5px solid #111827;
}
.zebra-segment-v.black { background-color: #111827; }
.zebra-segment-v.white { background-color: #ffffff; }

/* Decimal Coordinate Labels on South & West */
.coord-label-sur {
  position: absolute;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 8.5px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  transform: translateX(-50%);
  bottom: 22px;
}

.coord-label-oeste {
  position: absolute;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 8.5px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  left: -2px;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: center center;
}

.coord-label-norte {
  position: absolute;
  font-family: 'Consolas', monospace;
  font-size: 8.5px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  top: 3px;
  transform: translateX(-50%);
}

.coord-label-este {
  position: absolute;
  font-family: 'Consolas', monospace;
  font-size: 8.5px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  right: -2px;
  transform: translateY(-50%) rotate(90deg);
  transform-origin: center center;
}

/* Right Side Column (Submaps & Title Block) */
.layout-sidebar {
  width: 320px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Submaps Container */
.submaps-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1.5px solid #111827;
}

.submap-box {
  position: relative;
  height: 155px;
  border-bottom: 1px solid #111827;
  overflow: hidden;
}
.submap-box:last-child {
  border-bottom: none;
}

.submap-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.9);
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  padding: 3px 6px;
  letter-spacing: 0.5px;
  z-index: 500;
  cursor: text;
  outline: none;
  transition: background 0.15s;
}
.submap-header:hover, .submap-header:focus {
  background: #2563eb;
}

.submap-map {
  width: 100%;
  height: 100%;
  background: #e2e8f0;
}

/* Technical Data Table on Sheet */
.cuadro-datos-container {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  border-bottom: 1.5px solid #111827;
}

.cuadro-datos-title {
  font-size: 10px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.cuadro-datos-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 8px;
}

.cuadro-datos-table th,
.cuadro-datos-table td {
  border: 1px solid #111827;
  padding: 3px 4px;
  text-align: center;
}

.cuadro-datos-table th {
  background: #f1f5f9;
  font-weight: 700;
}

/* Membrete Técnico (Title Block) */
.membrete-block {
  padding: 0;
  background: #ffffff;
  font-size: 9px;
}

.membrete-table {
  width: 100%;
  border-collapse: collapse;
}

.membrete-table td {
  border: 1px solid #111827;
  padding: 3px 6px;
  vertical-align: middle;
}

.m-label {
  font-size: 7.5px;
  font-weight: 700;
  color: #4b5563;
  text-transform: uppercase;
  margin-bottom: 1px;
}

.m-val {
  font-weight: 700;
  font-size: 9.5px;
  color: #111827;
}

.membrete-logo-box {
  width: 70px;
  text-align: center;
  background: #f8fafc;
}

.membrete-logo-img {
  max-width: 60px;
  max-height: 40px;
  object-fit: contain;
}

/* North Arrow */
.map-north-arrow {
  position: absolute;
  top: 36px;
  right: 36px;
  width: 68px;
  height: 68px;
  z-index: 450;
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.35));
}

/* Graphic Scale Styles */
.map-scale-bar {
  position: absolute;
  bottom: 58px;
  left: 60px;
  background: rgba(255, 255, 255, 0.95);
  border: 1.2px solid #111827;
  padding: 4px 10px;
  border-radius: 4px;
  font-family: 'Segoe UI', Arial, sans-serif;
  z-index: 450;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.map-scale-text {
  font-size: 9.5px;
  font-weight: 700;
  color: #111827;
  text-align: center;
  margin-bottom: 2px;
}

.map-scale-units {
  display: flex;
  justify-content: space-between;
  font-size: 7.5px;
  font-weight: 700;
  font-family: monospace;
  margin-top: 1px;
}

/* 1. Checkered / Zebra scale */
.scale-checkered {
  width: 140px;
  height: 6px;
  display: flex;
  border: 1px solid #111827;
  margin: 0 auto;
}
.map-scale-seg { flex: 1; border-right: 1px solid #111827; }
.map-scale-seg:last-child { border-right: none; }
.map-scale-seg.black { background: #111827; }
.map-scale-seg.white { background: #ffffff; }

/* 2. Line scale with ticks */
.scale-line {
  width: 140px;
  height: 8px;
  position: relative;
  border-bottom: 2px solid #111827;
  margin: 0 auto;
}
.scale-tick {
  position: absolute;
  bottom: 0;
  width: 1.5px;
  height: 6px;
  background: #111827;
  transform: translateX(-50%);
}

/* 3. Subdivided scale */
.scale-subdivided {
  width: 140px;
  height: 6px;
  display: flex;
  border: 1px solid #111827;
  margin: 0 auto;
}
.sub-block-fine {
  width: 50%;
  display: flex;
  border-right: 1px solid #111827;
}
.fine-seg { flex: 1; border-right: 0.5px solid #111827; }
.fine-seg:last-child { border-right: none; }
.fine-seg.black { background: #111827; }
.fine-seg.white { background: #ffffff; }
.sub-block-main {
  width: 25%;
  border-right: 1px solid #111827;
}
.sub-block-main:last-child { border-right: none; }
.sub-block-main.black { background: #111827; }
.sub-block-main.white { background: #ffffff; }

/* 4. Stepped scale */
.scale-stepped {
  width: 140px;
  height: 7px;
  display: flex;
  margin: 0 auto;
  border: 1px solid #111827;
}
.step-seg { flex: 1; }
.step-seg.dark { background: #1e293b; }
.step-seg.light { background: #cbd5e1; }

/* Dynamic Legend */
.map-legend-box {
  position: absolute;
  bottom: 58px;
  right: 36px;
  background: rgba(255, 255, 255, 0.95);
  border: 1.2px solid #111827;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 8.5px;
  z-index: 450;
  max-width: 180px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.legend-title {
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 4px;
  font-size: 9px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 2px;
  cursor: text;
  outline: none;
}
.legend-title:focus { color: #2563eb; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-weight: 600;
}

.legend-swatch {
  width: 14px;
  height: 10px;
  border: 1px solid #334155;
}

.legend-swatch.point {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
}

/* =========================================================
   TEMPLATE LAYOUT MODIFIERS (20 CARTOGRAPHIC TEMPLATES)
========================================================= */

/* Template 2: A4 Horizontal Bottom Strip */
.map-sheet.tpl-02-a4h-bottom .layout-body {
  flex-direction: column;
}
.map-sheet.tpl-02-a4h-bottom .main-map-container {
  border-right: none;
  border-bottom: 1.5px solid #111827;
  flex: 2;
}
.map-sheet.tpl-02-a4h-bottom .layout-sidebar {
  width: 100%;
  height: 160px;
  flex-direction: row;
}
.map-sheet.tpl-02-a4h-bottom .submaps-panel {
  flex-direction: row;
  width: 320px;
  border-bottom: none;
  border-right: 1.5px solid #111827;
}
.map-sheet.tpl-02-a4h-bottom .submap-box {
  flex: 1;
  height: 100%;
  border-bottom: none;
  border-right: 1px solid #111827;
}
.map-sheet.tpl-02-a4h-bottom .cuadro-datos-container {
  flex: 1;
  border-bottom: none;
  border-right: 1.5px solid #111827;
}
.map-sheet.tpl-02-a4h-bottom .membrete-block {
  width: 320px;
}

/* Template 3: A4 Horizontal Left Sidebar */
.map-sheet.tpl-03-a4h-left .layout-body {
  flex-direction: row-reverse;
}
.map-sheet.tpl-03-a4h-left .main-map-container {
  border-right: none;
  border-left: 1.5px solid #111827;
}

/* Template 6: A4 Vertical Standard */
.map-sheet.tpl-06-a4v-std .layout-body {
  flex-direction: column;
}
.map-sheet.tpl-06-a4v-std .main-map-container {
  border-right: none;
  border-bottom: 1.5px solid #111827;
  flex: 2.2;
}
.map-sheet.tpl-06-a4v-std .layout-sidebar {
  width: 100%;
  height: 280px;
  flex-direction: row;
}
.map-sheet.tpl-06-a4v-std .submaps-panel {
  flex-direction: row;
  width: 260px;
  border-bottom: none;
  border-right: 1.5px solid #111827;
}
.map-sheet.tpl-06-a4v-std .submap-box {
  flex: 1;
  height: 100%;
  border-bottom: none;
  border-right: 1px solid #111827;
}
.map-sheet.tpl-06-a4v-std .cuadro-datos-container {
  flex: 1;
  border-bottom: none;
  border-right: 1.5px solid #111827;
}
.map-sheet.tpl-06-a4v-std .membrete-block {
  width: 250px;
}

/* Template 11: A3 Horizontal Cadastral */
.map-sheet.tpl-11-a3h-cadastral .layout-sidebar {
  width: 380px;
}
.map-sheet.tpl-11-a3h-cadastral .submap-box {
  height: 180px;
}

/* Template 17: Classic Cadastral Blueprint */
.map-sheet.tpl-17-perim-classic .main-leaflet-map {
  background: #ffffff;
}

/* Template 18: Full-bleed Satellite HD */
.map-sheet.tpl-18-satellite-hd .layout-sidebar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
}

/* QGIS Grid Coordinates Control Styles */
.qgis-side-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.qgis-side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.qgis-side-title {
  font-size: 11.5px;
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qgis-side-badge {
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.qgis-side-badge.active {
  background: #dbeafe;
  color: #1d4ed8;
}
.qgis-side-badge.inactive {
  background: #f1f5f9;
  color: #64748b;
}
.qgis-side-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
.qgis-side-grid .form-group {
  margin-bottom: 0;
}
.qgis-side-grid .form-label {
  font-size: 10px;
  margin-bottom: 3px;
  color: #64748b;
}
.qgis-side-grid select {
  font-size: 10.5px;
  padding: 4px 6px;
  height: 28px;
}
