/* FCIS: Imperative Shell / Presentation - visual styling only. */

:root {
  --layer-chiban-beta-color: #c2410c;
  --layer-urban-planning-color: #2563eb;
  --page-bg: #8fa8bd;
  --panel-bg: #d7d2c8;
  --panel-border: #808080;
  --retro-dark: #404040;
  --retro-field-bg: #fffffb;
  --retro-highlight: #0a246a;
  --retro-highlight-2: #3a6ea5;
  --retro-light: #ffffff;
  --retro-surface: #ece9d8;
  --text-main: #111111;
  --text-subtle: #263238;
  --focus-ring: #000080;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.14) 1px, transparent 1px),
    linear-gradient(0deg, rgb(255 255 255 / 0.14) 1px, transparent 1px),
    var(--page-bg);
  background-size: 16px 16px;
  color: var(--text-main);
  font-family: "MS PGothic", "MS UI Gothic", Tahoma, Arial, sans-serif;
  font-size: 13px;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 1px dotted var(--focus-ring);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  width: 100vw;
  height: 100vh;
}

.layer-panel,
.summary-panel {
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  height: 100%;
  overflow: auto;
  background: var(--panel-bg);
  padding: 8px;
  border: 2px solid;
  border-color: var(--retro-light) var(--retro-dark) var(--retro-dark)
    var(--retro-light);
  box-shadow:
    inset 1px 1px 0 var(--retro-surface),
    inset -1px -1px 0 var(--panel-border);
}

.layer-panel {
  border-right-color: var(--retro-dark);
}

.summary-panel {
  border-left-color: var(--retro-light);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  border: 1px solid var(--retro-light);
  background: linear-gradient(
    90deg,
    var(--retro-highlight),
    var(--retro-highlight-2)
  );
  padding: 3px 4px;
  color: #ffffff;
}

.panel-header h1,
.legend-section h2,
.summary-panel h2,
.summary-section h3,
.summary__section h4 {
  margin: 0;
  letter-spacing: 0;
}

.panel-header h1 {
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-button {
  min-width: 74px;
  height: 23px;
  border: 2px solid;
  border-color: var(--retro-light) var(--retro-dark) var(--retro-dark)
    var(--retro-light);
  border-radius: 0;
  background: var(--panel-bg);
  color: #000000;
  box-shadow:
    inset 1px 1px 0 var(--retro-surface),
    inset -1px -1px 0 var(--panel-border);
  font-weight: 700;
  cursor: pointer;
}

.report-button:hover {
  background: #e7e3d7;
}

.report-button:active {
  border-color: var(--retro-dark) var(--retro-light) var(--retro-light)
    var(--retro-dark);
  box-shadow: inset 1px 1px 0 var(--panel-border);
}

.report-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.legend-section,
.summary-section {
  display: grid;
  gap: 7px;
  min-height: 0;
  border: 2px solid;
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  background: var(--retro-surface);
  padding: 7px;
}

.legend-section h2,
.summary-panel h2,
.summary-section h3,
.summary__section h4 {
  color: #000080;
  font-size: 0.78rem;
  font-weight: 800;
}

.summary-panel > h2 {
  border: 1px solid var(--retro-light);
  background: linear-gradient(
    90deg,
    var(--retro-highlight),
    var(--retro-highlight-2)
  );
  padding: 4px 6px;
  color: #ffffff;
  font-size: 0.9rem;
}

.layer-toggle {
  display: grid;
  grid-template-columns: 16px 22px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 27px;
  border: 1px solid transparent;
  padding: 2px 3px;
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 700;
}

.layer-toggle:hover {
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  background: #f3f0e7;
}

.layer-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--retro-highlight);
}

.layer-toggle input:disabled ~ span {
  opacity: 0.46;
}

.legend-layer-toggle {
  min-height: 25px;
}

.layer-swatch {
  width: 19px;
  height: 19px;
  border: 2px solid;
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  border-radius: 0;
}

.layer-swatch--urban-planning {
  background-color: rgb(37 99 235 / 0.12);
  background-image:
    linear-gradient(
      135deg,
      transparent 42%,
      #d40000 42%,
      #d40000 56%,
      transparent 56%
    ),
    linear-gradient(
    0deg,
    transparent 40%,
    #4b5563 40%,
    #4b5563 54%,
    transparent 54%
  ),
    linear-gradient(
    90deg,
    transparent 40%,
    var(--layer-urban-planning-color) 40%,
    var(--layer-urban-planning-color) 54%,
    transparent 54%
  );
  background-size: 8px 8px;
}

.layer-swatch--chiban-beta {
  background-color: color-mix(
    in srgb,
    var(--layer-chiban-beta-color) 18%,
    transparent
  );
  background-image:
    linear-gradient(
      var(--layer-chiban-beta-color),
      var(--layer-chiban-beta-color)
    ),
    linear-gradient(
    90deg,
    var(--layer-chiban-beta-color),
    var(--layer-chiban-beta-color)
  );
  background-position: center, center;
  background-size: 100% 2px, 2px 100%;
  background-repeat: no-repeat;
}

.layer-message,
.legend-message,
.map-status {
  margin: 0;
  color: #800000;
  font-size: 0.78rem;
  line-height: 1.35;
}

.legend-message {
  color: var(--text-subtle);
}

.legend-group {
  display: grid;
  gap: 5px;
}

.legend-group + .legend-group {
  border-top: 1px solid var(--panel-border);
  padding-top: 7px;
}

.use-district-legend {
  display: grid;
  gap: 5px;
  margin-left: 22px;
  padding-left: 6px;
  border-left: 1px solid var(--panel-border);
}

.use-district-legend h3 {
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.76rem;
  font-weight: 800;
}

.use-district-legend__list {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.use-district-legend__item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-height: 20px;
  color: var(--text-main);
  font-size: 0.76rem;
  line-height: 1.25;
}

.use-district-legend__swatch {
  width: 15px;
  height: 15px;
  border: 1px solid var(--panel-border);
  box-shadow: inset 1px 1px 0 rgb(255 255 255 / 0.55);
}

.coordinate-list {
  display: grid;
  gap: 6px;
  margin: 0;
  border: 2px solid;
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  background: var(--retro-surface);
  padding: 7px;
}

.coordinate-list div {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.coordinate-list dt {
  color: var(--text-subtle);
  font-size: 0.76rem;
  font-weight: 800;
}

.coordinate-list dd {
  min-width: 0;
  margin: 0;
  border: 2px solid;
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  border-radius: 0;
  background: var(--retro-field-bg);
  padding: 4px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.summary-status {
  min-height: 1.35em;
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.78rem;
  line-height: 1.35;
}

.summary-result {
  min-width: 0;
  color: #111111;
  font-size: 0.8rem;
  line-height: 1.4;
}

.summary {
  display: grid;
  gap: 8px;
}

.summary__section {
  display: grid;
  gap: 6px;
}

.summary__table {
  width: 100%;
  border: 2px solid;
  border-color: var(--panel-border) var(--retro-light) var(--retro-light)
    var(--panel-border);
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--retro-field-bg);
  font-size: 0.78rem;
}

.summary__table th,
.summary__table td {
  border-top: 1px solid #a0a0a0;
  padding: 5px 6px;
  text-align: left;
  vertical-align: top;
}

.summary__table tr:first-child th,
.summary__table tr:first-child td {
  border-top: 0;
}

.summary__table th {
  width: 42%;
  background: var(--panel-bg);
  color: var(--text-subtle);
  font-weight: 800;
}

.summary__table td {
  overflow-wrap: anywhere;
}

.summary__table .summary__row--height-control-name {
  height: 3.4em;
}

.summary__scroll-value {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}

.summary__scroll-value::-webkit-scrollbar {
  height: 6px;
}

.summary-status--error {
  color: #800000;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 3px solid;
  border-color: var(--retro-dark) var(--retro-light) var(--retro-light)
    var(--retro-dark);
  background: #b7c4d2;
}

.map-canvas {
  position: absolute;
  inset: 0;
}

.map-canvas {
  background: #d5dde5;
}

.map-stage--report-exporting .map-canvas {
  pointer-events: none;
}

.map-status {
  position: absolute;
  left: 50%;
  top: 8px;
  z-index: 3;
  max-width: min(520px, calc(100% - 32px));
  transform: translateX(-50%);
  border: 2px solid;
  border-color: var(--retro-light) var(--retro-dark) var(--retro-dark)
    var(--retro-light);
  border-radius: 0;
  background: #ffffe1;
  padding: 6px 8px;
  box-shadow: 2px 2px 0 rgb(0 0 0 / 0.24);
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr) auto;
    min-height: 100vh;
    height: auto;
  }

  .layer-panel {
    height: 34vh;
    max-height: none;
    border-right-color: var(--retro-dark);
    border-bottom-color: var(--retro-dark);
  }

  .map-stage {
    min-height: 58vh;
  }

  .summary-panel {
    height: auto;
    min-height: 260px;
    border-top-color: var(--retro-light);
    border-left-color: var(--retro-light);
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html,
  body {
    width: auto;
    height: auto;
    overflow: visible;
    background: #ffffff;
    color: #111827;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 5mm;
    width: auto;
    height: auto;
  }

  .map-stage {
    order: 1;
  }

  .layer-panel,
  .summary-panel {
    display: block;
    height: auto;
    overflow: visible;
    border: 0;
    background: transparent;
    padding: 0;
    box-shadow: none;
  }

  .layer-panel {
    order: 2;
  }

  .summary-panel {
    order: 3;
  }

  .panel-header,
  .summary-panel > h2,
  .coordinate-list,
  .map-status {
    display: none !important;
  }

  .map-stage {
    /* A4 portrait height minus the 10mm top and bottom page margins. */
    width: min(
      100%,
      calc(277mm * var(--report-map-aspect-ratio, 16 / 9))
    );
    max-width: 100%;
    height: auto;
    max-height: 277mm;
    aspect-ratio: var(--report-map-aspect-ratio, 16 / 9);
    margin-inline: auto;
    min-height: 0;
    border: 1px solid #9ca3af;
    break-inside: avoid;
    overflow: hidden;
    clip-path: inset(0);
    contain: layout paint size;
    isolation: isolate;
  }

  .map-canvas {
    position: absolute;
    inset: 0;
    visibility: visible;
  }

  .legend-section,
  .summary-section {
    position: relative;
    z-index: 2;
    display: grid;
    gap: 3mm;
    border: 0;
    background: #ffffff;
    padding: 0;
    box-shadow: none;
    break-inside: avoid;
  }

  .summary-section {
    border-top: 0;
    padding-top: 0;
  }

  .legend-section h2,
  .summary-section h3 {
    color: #111827;
    font-size: 11pt;
    line-height: 1.35;
  }

  .legend-group {
    gap: 2mm;
    break-inside: avoid;
  }

  .legend-group + .legend-group {
    padding-top: 3mm;
  }

  .legend-layer-toggle {
    grid-template-columns: 5mm minmax(0, 1fr);
    gap: 2mm;
    min-height: auto;
    font-size: 9pt;
    line-height: 1.3;
  }

  .legend-layer-toggle input,
  .layer-message {
    display: none !important;
  }

  .legend-layer-toggle .layer-swatch {
    grid-column: 1;
    width: 4mm;
    height: 4mm;
  }

  .legend-layer-toggle span:last-child {
    grid-column: 2;
  }

  .use-district-legend {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .use-district-legend__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1mm 4mm;
  }

  .use-district-legend__item {
    grid-template-columns: 4mm minmax(0, 1fr);
    gap: 2mm;
    min-height: auto;
    font-size: 8pt;
  }

  .use-district-legend__swatch {
    width: 4mm;
    height: 4mm;
  }

  .summary-result {
    font-size: 8.5pt;
    line-height: 1.45;
  }

  .summary {
    gap: 4mm;
  }

  .summary__section {
    gap: 2mm;
    break-inside: avoid;
  }

  .summary__section h4 {
    font-size: 9.5pt;
  }

  .summary__table {
    font-size: 8pt;
  }

  .summary__table th,
  .summary__table td {
    padding: 2mm;
  }

  .summary__scroll-value {
    overflow: visible;
    white-space: normal;
  }
}
