/* ==========================================================================
   India Geodata — Map Maker
   ========================================================================== */

.page-maps .site-header { position: static; box-shadow: none; }
.maps-page { max-width: 1280px; margin: 0 auto; padding: 24px; }
.maps-page [hidden] { display: none !important; }

.maps-intro { margin-bottom: 16px; }
.maps-intro h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }

.maps-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }

/* --- Sidebar --- */
.maps-side { display: flex; flex-direction: column; gap: 8px; }
.panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
}
.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-user-select: none;
  user-select: none;
  border-radius: var(--radius);
}
.panel > summary:hover { background: var(--color-bg-light); }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after, details.sub > summary::before {
  content: ""; width: 10px; height: 10px; flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 8l5 5 5-5' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--transition);
}
.panel[open] > summary::after { transform: rotate(180deg); }
.panel[open] > summary { border-radius: var(--radius) var(--radius) 0 0; }
.panel[open] > summary { border-bottom: 1px solid var(--color-border); }
.panel-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.hint { font-size: 0.8rem; line-height: 1.45; color: var(--color-muted); margin: -2px 0 0; }
.field > label, .field > .field-label { font-size: 0.74rem; font-weight: 500; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { grid-template-columns: 1fr 1fr 1fr; }
.row .field { min-width: 0; }

.maps-side select, .maps-side input[type="text"], .maps-side input[type="number"], .maps-side textarea {
  width: 100%;
  font: inherit;
  font-size: 0.86rem;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
}
.maps-side select:focus, .maps-side input:focus, .maps-side textarea:focus { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(245,158,11,0.35); }
.maps-side button:focus-visible, .maps-side summary:focus-visible, .stage-frame :focus-visible, .stage-frame svg .drag:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.maps-side textarea { min-height: 88px; resize: vertical; font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.4; }
.maps-side input[type="color"] { width: 100%; height: 34px; padding: 0 2px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-bg); cursor: pointer; }
.maps-side input[type="range"] { width: 100%; accent-color: var(--color-primary); }

.check { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; cursor: pointer; }
.check input { accent-color: var(--color-primary); width: 15px; height: 15px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-plain {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background: var(--color-primary);
  color: #fff;
  transition: opacity var(--transition);
}
.btn-plain:hover { background: var(--color-primary-light); border-color: var(--color-primary-light); }
.btn-plain:active { transform: translateY(1px); }
.btn-plain:disabled, .btn-plain[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn-plain.secondary { background: var(--color-bg); color: var(--color-text); border-color: var(--color-border); }
.btn-plain.secondary:hover { background: var(--color-bg-light); border-color: var(--color-accent); }
.btn-plain { min-height: 34px; }

.file-drop {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--color-muted);
  cursor: pointer;
}
.file-drop:hover, .file-drop.over { border-color: var(--color-accent); color: var(--color-text); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.file-drop:active .file-drop-btn { border-color: var(--color-accent); }
.file-drop-btn {
  display: inline-flex; align-items: center;
  font-size: 0.8rem; font-weight: 600; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--color-border); color: var(--color-text); background: var(--color-bg);
}
.file-drop:hover .file-drop-btn { border-color: var(--color-accent); }
.file-drop:focus-within .file-drop-btn { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(245,158,11,0.12); }
@media (hover: none), (max-width: 900px) { .file-drop-hint { display: none; } .file-drop { border-style: solid; } }

.status { font-size: 0.8rem; color: var(--color-muted); }
.status strong { color: var(--color-text); font-weight: 600; }
.status a { color: var(--color-accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.status.notice { color: #b91c1c; }
.unmatched { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.unmatched:empty { display: none; }
.fix-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.1fr); gap: 6px; align-items: center; font-size: 0.8rem; }
.fix-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #b91c1c; }
.fix-val { color: var(--color-muted); font-size: 0.8rem; white-space: nowrap; }
.maps-side .fix-row select { padding: 4px 6px; font-size: 0.8rem; }
.fix-row.assumed .fix-name { color: #166534; }
.fix-row .fix-undo { padding: 3px 8px; font-size: 0.74rem; justify-self: start; }
.fix-name small { color: var(--color-muted); font-weight: 600; }
.unmatched.flash { outline: 2px solid var(--color-accent); outline-offset: 4px; border-radius: 4px; }
.learned-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.8rem; padding: 2px 0; }
.learned-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unmatched-badge {
  position: absolute; right: 12px; top: 12px; z-index: 4;
  background: #b91c1c; color: #fff; font-size: 0.76rem; font-weight: 600;
  padding: 4px 10px; border-radius: 14px; box-shadow: var(--shadow-sm);
}
.unmatched-badge:hover { background: #991b1b; }

/* --- collapsible values table --- */
details.sub > summary { list-style: none; cursor: pointer; font-size: 0.8rem; color: var(--color-muted); padding: 6px 0; display: flex; align-items: center; gap: 6px; -webkit-user-select: none; user-select: none; }
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > summary::before { transform: rotate(-90deg); }
details.sub[open] > summary::before { transform: none; }
details.sub > input { margin-bottom: 6px; }

.value-table-wrap { max-height: 300px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.value-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.value-table td { padding: 3px 6px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.value-table td:first-child { width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0; }
.value-table td small { color: var(--color-muted); }
.maps-side .value-table input[type="text"] { width: 100%; font: inherit; font-size: 0.8rem; padding: 2px 6px; border: 1px solid transparent; border-radius: 3px; background: transparent; text-align: right; }
.maps-side .value-table input[type="text"]:hover { border-color: var(--color-border); }
.maps-side .value-table input[type="text"]:focus { border-color: var(--color-accent); outline: none; background: var(--color-bg); box-shadow: none; }

/* --- Text assets --- */
#assetList { display: flex; flex-direction: column; gap: 8px; }
.asset { border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.asset-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; font-weight: 600; color: var(--color-text); }
.asset-del { font-size: 0.74rem; color: var(--color-muted); padding: 2px 6px; border-radius: 3px; }
.asset-del:hover { color: #b91c1c; background: #fef2f2; }
.asset .row { gap: 6px; }

/* --- Zoom --- */
.zoom-row { display: flex; align-items: center; gap: 6px; }
.zoom-row input[type="range"] { flex: 1; min-width: 0; }
.zoom-row .btn-plain { padding: 4px 9px; line-height: 1; }
.zoom-value { font-size: 0.8rem; color: var(--color-muted); min-width: 38px; text-align: right; }
.stage-frame svg .map-layer { cursor: grab; }
.stage-frame svg .map-layer:active { cursor: grabbing; }

/* --- Stage --- */
.maps-stage { position: sticky; top: 12px; }
.stage-frame { position: relative; display: flex; justify-content: center; overflow: hidden; }
.stage-frame svg { width: auto; max-width: 100%; height: auto; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: block; border: 1px solid var(--color-border); }
.stage-frame svg .sel-box { fill: none; stroke: var(--color-accent); stroke-width: 1.5; stroke-dasharray: 4 3; pointer-events: none; }
.sel-tools { position: absolute; z-index: 5; display: flex; gap: 4px; }
.sel-tools button {
  width: 26px; height: 26px; border-radius: 50%; padding: 0;
  background: var(--color-text); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.sel-tools button svg, .icon-btn svg { display: block; }
.sel-tools button { border: 1px solid rgba(255,255,255,0.75); }
.stage-loading { position: absolute; left: 0; right: 0; top: 0; height: 3px; overflow: hidden; z-index: 6; background: var(--color-bg-light); }
.stage-loading::after { content: ""; position: absolute; left: -40%; width: 40%; height: 100%; background: var(--color-accent); animation: stage-loading 1.1s ease-in-out infinite; }
@keyframes stage-loading { to { left: 100%; } }
.stage-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 0.86rem; color: var(--color-text); background: rgba(255,255,255,0.92); text-align: center; padding: 24px; }
.icon-btn { padding: 0; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; }
.sel-tools button:hover { background: #b91c1c; }
.asset.flash { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(245,158,11,0.15); }
.stage-frame svg path { transition: opacity 0.1s; }
.stage-frame svg { touch-action: pan-y; }
@media (hover: hover) {
  .stage-frame svg .region:hover { opacity: 0.75; }
  .stage-frame svg .drag:hover { opacity: 0.8; }
}
.stage-frame svg .drag { cursor: move; }


.map-tip {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  background: var(--color-text);
  color: #fff;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 4px;
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
  display: none;
}

.loading { opacity: 0.5; pointer-events: none; }

@media (max-width: 900px) {
  .maps-page { padding: 12px; }
  .maps-intro { margin-bottom: 10px; }
  .maps-intro h1 { font-size: 1.25rem; }
  .maps-layout { grid-template-columns: 1fr; gap: 12px; }
  /* the preview stays pinned under the header while the controls scroll beneath it */
  .maps-stage { position: sticky; top: 0; order: -1; z-index: 20; background: var(--color-bg); padding: 6px 12px; margin: 0 -12px; border-bottom: 1px solid var(--color-border); }
  .stage-frame { justify-content: center; }
  .stage-frame svg { max-height: 42vh; max-height: 42dvh; }
  .maps-side select, .maps-side input[type="text"], .maps-side input[type="number"], .maps-side textarea, .maps-side .fix-row select { font-size: 16px; min-height: 42px; }
  .maps-side textarea { min-height: 96px; }
  .maps-side input[type="color"] { height: 42px; }
  .btn-plain, .file-drop-btn { min-height: 40px; padding: 8px 14px; font-size: 0.9rem; }
  .btn-row { gap: 8px; }
  .check { min-height: 40px; }
  .check input { width: 20px; height: 20px; }
  .panel > summary { padding: 12px 14px; font-size: 0.95rem; }
  .unmatched-badge { top: 8px; right: 8px; font-size: 0.8rem; padding: 6px 12px; min-height: 40px; display: inline-flex; align-items: center; }
    .value-table-wrap { max-height: 240px; }
  .maps-side .value-table input[type="text"] { min-height: 40px; font-size: 16px; border-color: var(--color-border); }
  .zoom-row .btn-plain { min-height: 40px; min-width: 40px; padding: 6px 10px; }
  .icon-btn { width: 40px; height: 40px; }
  .zoom-row input[type="range"] { height: 40px; }
  .sel-tools button { width: 40px; height: 40px; }
  .asset-del { min-height: 40px; padding: 8px 12px; font-size: 0.85rem; }
  details.sub > summary { padding: 10px 0; font-size: 0.9rem; }
  .hint, .status, .fix-val, .zoom-value, .asset-head, .field > label, .field > .field-label { font-size: 0.85rem; }
  /* while a control has focus (keyboard up), the pinned preview shrinks and scroll targets clear it */
  .maps-side:focus-within ~ .maps-stage .stage-frame svg { max-height: 22vh; max-height: 22dvh; }
  .maps-side .asset, .maps-side .unmatched, .maps-side .fix-row, .maps-side input, .maps-side select, .maps-side textarea { scroll-margin-top: calc(42vh + 40px); scroll-margin-top: calc(42dvh + 40px); }
}
/* touch phones in landscape are wider than 900px but still need 16px inputs */
@media (hover: none) and (pointer: coarse) {
  .maps-side select, .maps-side input[type="text"], .maps-side input[type="number"], .maps-side textarea, .maps-side .fix-row select, .maps-side .value-table input[type="text"] { font-size: 16px; }
}
@media (min-width: 600px) and (max-width: 900px) {
  .maps-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .maps-side .panel:nth-child(2) { grid-column: 1 / -1; }
}
.page-maps .header-inner, .page-maps .site-footer .container { max-width: 1280px; }
@media (max-width: 480px) {
  .row-3 { grid-template-columns: 1fr 1fr; }
  .row-3 > .field:last-child { grid-column: 1 / -1; }
  .stage-frame svg { max-height: 38vh; max-height: 38dvh; }
  .maps-side .panel:first-of-type .row { grid-template-columns: 1fr; }
  .fix-row { grid-template-columns: minmax(0, 1fr) auto; }
  .maps-side .fix-row select, .fix-row .fix-undo { grid-column: 1 / -1; }
}
