/* ============================================================
   羽地大川土地改良区 筆境界マップ - スタイルシート
   ============================================================ */

:root {
  --font-sans: "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --color-primary: #0d5c4e;
  --color-primary-dark: #0a4a3e;
  --color-secondary: #0a4a7a;
  --color-bg: #f0f4f8;
  --color-surface: #ffffff;
  --color-surface-2: #f8fafc;
  --color-border: #d8e2ea;
  --color-border-light: #e8eef3;
  --color-text: #1a2530;
  --color-text-muted: #4a5d6e;
  --color-text-faint: #8a9baa;
  --header-height: 54px;
  --side-panel-width: 300px;
  --shadow-sm: 0 1px 4px rgba(10,30,50,0.08);
  --shadow-md: 0 4px 16px rgba(10,30,50,0.10);
  --shadow-lg: 0 8px 32px rgba(10,30,50,0.14);
  --radius: 8px;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
}

/* ============================================================
   アプリシェル
   ============================================================ */
.map-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ============================================================
   ヘッダー
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--header-height);
  padding: 0 16px;
  background: linear-gradient(135deg, #0d5c4e 0%, #0a4a7a 100%);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

.home-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.78);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.25);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.home-link:hover {
  background: rgba(255,255,255,0.15);
  color: white;
}

.title-block {
  flex: 1;
  min-width: 0;
}

.title-block h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-sub {
  font-size: 0.73rem;
  color: rgba(255,255,255,0.65);
  margin: 1px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  flex-shrink: 0;
}

.map-status-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 4px 12px;
  white-space: nowrap;
  transition: background var(--transition);
}

.map-status-badge[data-kind="error"] {
  background: rgba(220,38,38,0.25);
  border-color: rgba(220,38,38,0.4);
  color: #fca5a5;
}

/* ============================================================
   ワークスペース
   ============================================================ */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  --side-panel-width: 300px;
}

.workspace.is-side-panel-collapsed .side-panel {
  width: 0 !important;
  overflow: hidden;
}

.workspace.is-side-panel-collapsed .workspace-resizer {
  display: none;
}

/* ============================================================
   サイドパネル
   ============================================================ */
.side-panel {
  width: var(--side-panel-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
}

.side-panel::-webkit-scrollbar { width: 4px; }
.side-panel::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.tool-section {
  padding: 16px;
}

.tool-section h2 {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 14px;
}

.tool-section h2 svg {
  color: var(--color-primary);
  flex-shrink: 0;
}

.section-divider {
  height: 1px;
  background: var(--color-border-light);
  margin: 0 16px;
}

/* ============================================================
   表示設定コントロール
   ============================================================ */
.style-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.control-row select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.84rem;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234a5d6e' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color var(--transition);
}

.control-row select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13,92,78,0.15);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-row input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--color-surface);
}

.color-value {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-family: monospace;
}

.control-row input[type="range"] {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.opacity-value {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-primary);
  font-family: monospace;
}

/* ============================================================
   凡例
   ============================================================ */
.legend-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--color-text-muted);
}

.legend-swatch {
  width: 28px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 2px solid #000000;
  background-color: rgba(128, 128, 128, 0.25);
  transition: background-color var(--transition), border-color var(--transition);
}

/* ============================================================
   操作ガイド
   ============================================================ */
.guide-list {
  margin: 0;
  padding: 0 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-list li {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ============================================================
   ワークスペースリサイザー
   ============================================================ */
.workspace-resizer {
  width: 5px;
  flex-shrink: 0;
  background: var(--color-border-light);
  cursor: col-resize;
  transition: background var(--transition);
  position: relative;
  z-index: 10;
}

.workspace-resizer:hover,
.workspace-resizer:active {
  background: var(--color-primary);
}

/* ============================================================
   地図パネル
   ============================================================ */
.map-panel {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

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

/* サイドパネル開閉ボタン */
.side-panel-toggle {
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  z-index: 50;
  width: 28px;
  height: 48px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.side-panel-toggle:hover {
  background: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-md);
}

/* ============================================================
   筆情報ポップアップ
   ============================================================ */
.parcel-popup {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 200;
  width: 280px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 18px;
  animation: popup-in 0.2s ease;
}

@keyframes popup-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.parcel-popup.is-hidden {
  display: none;
}

.popup-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background var(--transition);
}

.popup-close:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}

.popup-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 12px;
}

.popup-details {
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
}

.popup-details dt {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-faint);
  white-space: nowrap;
  padding-top: 1px;
}

.popup-details dd {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  word-break: break-all;
}

.popup-actions {
  display: flex;
  gap: 8px;
}

.popup-action-link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-secondary);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface-2);
  transition: background var(--transition), border-color var(--transition);
}

.popup-action-link:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1d4ed8;
}

/* ============================================================
   ズームレベル表示
   ============================================================ */
.zoom-level {
  position: absolute;
  bottom: 40px;
  right: 58px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 50;
}

/* ============================================================
   ESRIウィジェット調整
   ============================================================ */
.esri-ui-bottom-right {
  bottom: 60px !important;
}

.esri-zoom {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md) !important;
  border: 1px solid var(--color-border) !important;
}

.esri-widget--button {
  border-radius: 0 !important;
}

.esri-zoom .esri-widget--button:first-child {
  border-radius: var(--radius) var(--radius) 0 0 !important;
}

.esri-zoom .esri-widget--button:last-child {
  border-radius: 0 0 var(--radius) var(--radius) !important;
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 640px) {
  .side-panel {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }

  .workspace.is-side-panel-collapsed .side-panel {
    transform: translateX(-100%);
    width: var(--side-panel-width) !important;
    overflow: auto;
    transition: transform 0.2s ease;
  }

  .parcel-popup {
    top: auto;
    bottom: 60px;
    right: 8px;
    left: 8px;
    width: auto;
  }
}

/* ============================================================
   フォーカス・アクセシビリティ
   ============================================================ */
:focus-visible {
  outline: 3px solid rgba(13,92,78,0.5);
  outline-offset: 2px;
}

.is-hidden {
  display: none !important;
}

/* ============================================================
   レイヤ一覧 (TOC)
   ============================================================ */
.toc-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toc-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--color-text);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.toc-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--color-primary);
  cursor: pointer;
  margin: 0;
}

/* サブレイヤツリー */
.toc-sub-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-left: 12px;
  border-left: 1px dashed var(--color-border-light);
  padding-left: 12px;
  margin-top: 4px;
}

.toc-sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.toc-sub-item input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--color-primary);
  cursor: pointer;
  margin: 0;
}

/* 凡例スウォッチ */
.toc-swatch {
  width: 20px;
  height: 12px;
  border-radius: 2px;
  border: 1.5px solid var(--color-text-muted);
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* ポイントシンボルの代わり（丸） */
.toc-swatch-point {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--color-text-muted);
  flex-shrink: 0;
  display: inline-block;
  margin: 0 5px;
}

/* ラインシンボル（線） */
.toc-swatch-line {
  width: 20px;
  height: 3px;
  background-color: var(--color-text-muted);
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  margin: 0 2px;
  border-radius: 1px;
}

.toc-swatch-line.dashed {
  background-color: transparent !important;
}

.toc-sub-group {
  display: flex;
  flex-direction: column;
}

