/* ==========================================
   Design System Tokens (New)
   ========================================== */
:root {
    --color-bg: #ffffff;
    --color-panel-bg: rgba(255, 255, 255, 0.95);
    --color-panel-blur: 10px;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-divider: #f1f5f9;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-accent-subtle: #eff6ff;
    --color-danger: #dc2626;
    --color-warn: #d97706;
    --color-ok: #15803d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .07), 0 0 0 1px rgba(0, 0, 0, .04);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, .10), 0 0 0 1px rgba(0, 0, 0, .04);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, .12), 0 2px 4px rgba(0, 0, 0, .08);
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --transition-fast: .12s cubic-bezier(.4, 0, .2, 1);
    --transition-base: .2s cubic-bezier(.4, 0, .2, 1);
    --panel-width: 340px;
    --toolpanel-width: 360px;
    --panel-top: 12px;
    --focus-ring: 0 0 0 3px var(--color-accent-subtle), 0 0 0 1.5px var(--color-accent);
}

html,
body,
#map {
    height: 100%;
    margin: 0;
}

#map {
    position: fixed;
    inset: 0;
}


.layer-row {
    display: grid;
    grid-template-columns: auto 1fr 80px auto;
    gap: 6px 8px;
    align-items: center;
    padding: 6px 8px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    background: #fff;
    margin-bottom: 6px;
}

.layer-row.dragging {
    opacity: .4;
}

.layer-row .handle {
    cursor: grab;
    user-select: none;
    font-size: 14px;
    line-height: 1;
    padding: 2px 4px;
}

.layer-row .handle:active {
    cursor: grabbing;
}

.layer-row label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.layer-row input[type=range] {
    width: 100%;
}

.btns button {
    margin-left: 4px;
}


.coord {
    position: fixed;
    left: 12px;
    bottom: 12px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(8px);
    font: 12px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
    z-index: 9;
}

/* ==========================================
   Panel + Row Layout (clean, unused removed)
   ========================================== */

/* 趣旨説明パネル (左上・ドックの上に重なる) */
.app-purpose-inner {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-purpose-title {
    font-weight: 600;
    font-size: 13px;
    color: #003f7e;
    /* 適度な強調 */
}

.app-purpose-body {
    font-size: 12px;
    line-height: 1.3;
    color: #1d242b;
}

.app-purpose-links {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.app-purpose-links .small {
    background: #f1f5f9;
    border: 1px solid #dbe4ef;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

/* ==== Dock & Floating Panels ==== */
.toolbar-dock {
    position: fixed;
    top: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 30;
}

.dock-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--color-border);
    background: var(--color-panel-bg);
    backdrop-filter: blur(var(--color-panel-blur));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    color: var(--color-text-muted);
    box-shadow: var(--shadow-md);
    transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.dock-btn img {
    width: 24px;
    height: 24px;
    display: block;
    pointer-events: none;
    filter: invert(40%) sepia(6%) saturate(500%) hue-rotate(180deg) brightness(90%) contrast(85%);
    transition: filter var(--transition-fast);
}

.dock-btn:hover {
    background: #ffffff;
    color: var(--color-text);
}

.dock-btn:hover img {
    filter: invert(15%) sepia(8%) saturate(900%) hue-rotate(180deg) brightness(95%) contrast(95%);
}

.dock-btn[aria-expanded="true"] {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent-subtle), var(--shadow-md);
}

.dock-btn[aria-expanded="true"] img {
    filter: invert(100%) brightness(110%);
}

.dock-btn:active {
    transform: translateY(1px);
}

.dock-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* カスタム浮動パネルが maplibregl の margin に影響されないようにする */
.floating-panel.maplibregl-ctrl,
#layerPanel.maplibregl-ctrl,
#weightPanel.maplibregl-ctrl,
.app-purpose-panel.maplibregl-ctrl {
    margin: 0 !important;
}

.floating-panel {
    position: fixed;
    top: var(--panel-top);
    left: 64px;
    width: 340px;
    max-width: calc(100% - 76px);
    max-height: calc(100% - 24px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--color-panel-bg);
    backdrop-filter: blur(var(--color-panel-blur));
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 12px 14px 14px;
    box-shadow: var(--shadow-lg);
    font: 13px/1.45 var(--font-sans);
    color: var(--color-text);
    z-index: 50;
    animation: fadeIn .25s ease;
}

.floating-panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.floating-panel h2,
.floating-panel h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .5px;
}

.floating-panel .panel-body {
    overflow: auto;
    scrollbar-width: thin;
    max-height: calc(100vh - 120px);
    padding-right: 2px;
}

.floating-panel[hidden] {
    display: none !important;
}

/* Mobile (narrow) adjustments */
@media (max-width: 720px) {
    .toolbar-dock {
        top: 12px;
        left: 12px;
        bottom: auto;
        flex-direction: row;
    }

    .dock-btn {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    #layerPanel,
    #weightPanel,
    .app-purpose-panel {
        box-sizing: border-box;
    }

    .floating-panel {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 72px;
        width: auto;
        max-width: none;
        max-height: 60vh;
    }

    /* Mobile: place the purpose panel at the bottom and make it full-width like other panels */
    .app-purpose-panel {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 72px;
        width: calc(100% - 24px);
        max-width: none;
        z-index: 40;
    }

    /* Mobile: make layer and weight panels align at the same bottom and share width */
    #layerPanel,
    #weightPanel {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 72px;
        width: calc(100% - 24px);
        max-width: none;
        z-index: 50;
    }

    .floating-panel .panel-body {
        max-height: calc(60vh - 72px);
    }
}

/* Generic row layout */
/* weight panel legacy selector (kept for compatibility) */
#weightPanel h3 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .5px;
}

#weightPanel h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-divider);
    padding-bottom: 4px;
}

.legend-cats,
.legend-grad {
    font-size: 12px;
}

.legend-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    margin: 2px 0 4px;
}

.legend-cats span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-accent-subtle);
    color: var(--color-text);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.legend-cats span i {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    display: inline-block;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .15) inset;
}

.legend-grad {
    position: relative;
    height: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.legend-grad::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #33a02c, #b2df8a, #ffffbf, #fdae61, #d73027);
}

/* Hint / helper text */
.hint,
.small {
    font-size: 11.5px;
    color: var(--color-text-muted);
}

/* Buttons */
button,
.small-btn {
    font: 12px/1.2 var(--font-sans);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #f8fafc;
    color: var(--color-text);
    cursor: pointer;
    padding: 4px 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

button:hover,
.small-btn:hover {
    background: #eef2f7;
}

button:active,
.small-btn:active {
    background: #e2e8f0;
}

button:focus-visible,
.small-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Inputs */
input[type=text],
input[type=number],
select {
    font: 12px/1.3 var(--font-sans);
    padding: 4px 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type=text]:focus,
input[type=number]:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--focus-ring);
}

/* Scrollbars (WebKit) */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border: 2px solid #f1f5f9;
    border-radius: 20px;
}

*::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Popup Table Styling */
.maplibregl-popup-content {
    font: 11px/1.35 var(--font-sans);
    padding: 6px 6px 8px;
}

.popup-heading {
    font-weight: 400;
    margin: 0 0 4px;
    font-size: 11.2px;
    color: var(--color-text-muted);
}

.popup-table {
    width: 100%;
    border-collapse: collapse;
    font: 11px/1.3 var(--font-sans);
    table-layout: fixed;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.popup-table th,
.popup-table td {
    border: 1px solid var(--color-border);
    padding: 2px 4px;
}

.popup-table th {
    background: #f1f5f9;
    text-align: center;
    width: 70%;
    font-weight: 400;
    color: var(--color-text);
}

.popup-table td {
    background: #aed6ff;
    text-align: center;
    width: 30%;
    font-variant-numeric: tabular-nums;
    font-weight: 400;
}

/* Utility */
.muted {
    color: var(--color-text-muted);
}

.mono {
    font-family: var(--font-mono);
}

/* Collapsed visibility adjustments */

/* Smooth fade-in */
.panel {
    opacity: 0;
    animation: fadeIn .35s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* Coordinate box harmonize */
.coord {
    border: 1px solid var(--color-border);
    backdrop-filter: blur(var(--color-panel-blur));
    font: 12px/1.3 var(--font-sans);
}

/* Style rows scroll area refinement */
.style-rows {
    scrollbar-width: thin;
}

/* Weighted Style Control */
/* Weight Panel Styles */
.weight-panel {
    position: fixed;
    top: var(--panel-top);
    right: 32px;
    z-index: 60;
    width: 340px;
    max-width: calc(100% - 24px);
    background: var(--color-panel-bg);
    backdrop-filter: blur(var(--color-panel-blur));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font: 13px/1.45 var(--font-sans);
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.weight-panel h3 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.weight-panel h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-divider);
    padding-bottom: 4px;
}

/* レイヤーセクション */
.weight-panel .layer-section {
    margin: 8px 0;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: rgba(248, 250, 252, 0.5);
}

/* スライダー行 */
#weightPanel .slider-row {
    display: grid;
    grid-template-columns: 28px 1fr 90px;
    /* toggle | label | slider */
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    font-size: 11px;
}

/* Toggle switch */
.switch {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
    flex: 0 0 28px;
    /* 幅を固定 */
    max-width: 28px;
    /* 最大幅を固定 */
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-toggle {
    position: absolute;
    cursor: pointer;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 28px;
    /* 明示的に幅指定 */
    background: #cbd5e1;
    transition: var(--transition-fast);
    border-radius: 16px;
    box-shadow: inset 0 0 0 1px #94a3b8;
}

.slider-toggle:before {
    content: "";
    position: absolute;
    height: 12px;
    width: 12px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    transition: var(--transition-fast);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

.switch input:checked+.slider-toggle {
    background: var(--color-accent);
    box-shadow: inset 0 0 0 1px var(--color-accent);
}

.switch input:checked+.slider-toggle:before {
    transform: translateX(12px);
}

.switch input:focus-visible+.slider-toggle {
    outline: none;
    box-shadow: var(--focus-ring);
}

.slider-row.disabled {
    opacity: .55;
}

#weightPanel .slider-row label {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#weightPanel .slider-row input[type="range"] {
    width: 100%;
    height: 20px;
    accent-color: var(--color-accent);
    justify-self: end;
}


/* 凡例 */
#weightPanel .legend {
    margin: 8px 0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 10px;
}

#weightPanel .legend span {
    display: flex;
    align-items: center;
    gap: 2px;
}

#weightPanel .legend i {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* 単一行グラデーション凡例 */
.risk-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    user-select: none;
}

.risk-legend .title {
    font-weight: 600;
    color: var(--color-text-muted);
    margin-right: 2px;
}

.risk-legend .min-label,
.risk-legend .max-label {
    font-size: 11px;
    color: var(--color-text-muted);
}

.risk-legend .bar {
    flex: 1 1 auto;
    height: 14px;
    border-radius: 7px;
    position: relative;
    border: 1px solid var(--color-border);
    background: linear-gradient(90deg, #22c55e, #84cc16, #f59e0b, #f97316, #dc2626);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
    min-width: 140px;
}

.risk-legend.top {
    margin-bottom: 4px;
}

/* === Tri-state weight switches === */
.weight-layer-section {
    margin: 8px 0;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: rgba(248, 250, 252, .6);
}

.tri-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    margin: 4px 0;
    font-size: 11px;
}

.tri-row .attr-label {
    line-height: 1.25;
    color: var(--color-text);
}

.tri-switch {
    display: inline-flex;
    border: 1px solid var(--color-border);
    background: #f1f5f9;
    border-radius: 20px;
    overflow: hidden;
}

.tri-switch .state-btn {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 4px 10px 5px;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    font-weight: 500;
    color: #475569;
    transition: background .15s, color .15s;
}

.tri-switch .state-btn+.state-btn {
    border-left: 1px solid var(--color-border);
}

.tri-switch .state-btn.off.active {
    background: #e2e8f0;
    color: #334155;
}

.tri-switch .state-btn.mid.active {
    background: #f59e0b;
    color: #fff;
}

.tri-switch .state-btn.high.active {
    background: #dc2626;
    color: #fff;
}

.tri-switch .state-btn:not(.active):hover {
    background: #e2e8f0;
}

@media (hover:none) {
    .tri-switch .state-btn:not(.active):hover {
        background: transparent;
    }
}

/* Group headers inside weight panel */
.group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 10px 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.group-header:first-of-type {
    margin-top: 4px;
}

.group-header .group-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: grayscale(15%) brightness(0.75);
}

.group-header .group-title {
    line-height: 1.1;
}


/* 旧スタイルとの互換性 */
#weightPanel .row {
    border-top: 1px solid var(--color-divider);
    padding: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#weightPanel .inline {
    display: flex;
    gap: 6px;
    align-items: center;
}

#weightPanel .mini-legend {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
}

#weightPanel .mini-legend span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-accent-subtle);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

/* removed .close-btn (not used after details conversion) */