/* create font from ttf file */
@font-face {
    font-family: 'Afacad Flux';
    src: url('fonts/AfacadFlux-VariableFont_slnt,wght.ttf') format('truetype');
    font-weight: 100 1000;
    font-style: normal oblique;
}

/* clear all defauls */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* set variables */
:root {
    --bg: #0d0f14;
    --panel: #13161e;
    --panel-border: #1f2433;
    --accent: #90C715;
    --accent-dim: rgba(74, 240, 176, 0.12);
    --accent-glow: rgba(74, 240, 176, 0.35);
    --text: #e2e8f0;
    --text-muted: #d4dae4;
    --danger: #f87171;
    --warning: #fbbf24;
    --panel-w: 320px;
}

/* style page... */
html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
}

#map {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: var(--panel-w);
    z-index: 0;
}

.home-btn {
    display: block;
    width: 30px;
    height: 30px;
    background: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 30px;
    text-align: center;
    color: #333;
}
.home-btn:hover { background: #f4f4f4; }

/* ── PANEL ── */
#panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--panel-w);
    z-index: 1000;
    background: var(--panel);
    border-left: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: -8px 0 40px rgba(0,0,0,0.6);
}

#panel-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

#fold-logo {
    display: block;
    width: 100%;
    max-height: 80px;
    object-fit: contain;
    margin-bottom: 14px;
}

#panel-header h1 {
    font-family: 'Afacad Flux', 'DM Sans', sans-serif;
    font-size: 24px;
    font-weight: 600;
    /* letter-spacing: 0.05em; */
    text-transform: none;
    /* color: var(--text); */
    color: white;
    margin-bottom: 12px;
    text-align: center;
}

#wms-url-wrap {
    display: flex;
    gap: 6px;
}

#wms-url {
    flex: 1;
    background: #0d0f14;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.2s;
}
#wms-url:focus { border-color: var(--accent); }

#load-btn {
    background: var(--accent);
    color: #0d0f14;
    border: none;
    border-radius: 6px;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.05em;
}
#load-btn:hover { opacity: 0.85; }
#load-btn:active { transform: scale(0.97); }
#load-btn:disabled { opacity: 0.4; cursor: default; }

/* ── STATUS BAR ── */
#status-bar {
    font-size: 12px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--panel-border);
    color: var(--text-muted);
    font-family: 'Space Mono', monospace;
    min-height: 34px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
#status-bar.error { color: var(--danger); }
#status-bar.ok { color: var(--accent); }

.spinner {
    width: 10px; height: 10px;
    border: 1.5px solid var(--accent-dim);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOOLBAR ── */
#layer-toolbar {
    display: flex;
    gap: 6px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.tool-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 5px;
    color: var(--text-muted);
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    /* letter-spacing: 0.08em; */
    text-transform: uppercase;
    padding: 5px 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

#search-wrap {
    padding: 10px 20px 0;
    flex-shrink: 0;
}
#layer-search {
    width: 100%;
    background: #0d0f14;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.2s;
}
#layer-search:focus { border-color: var(--accent); }
#layer-search::placeholder { color: var(--text-muted); }

/* ── LAYER LIST ── */
#layer-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 20px;
}

#layer-list::-webkit-scrollbar { width: 4px; }
#layer-list::-webkit-scrollbar-track { background: transparent; }
#layer-list::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 2px; }

.group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Afacad Flux', 'DM Sans', sans-serif;
    font-size: 14px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    padding: 10px 8px 4px;
    border-bottom: 1px solid var(--panel-border);
    margin-bottom: 2px;
    cursor: pointer;
    user-select: none;
}
.group-header:hover { color: var(--accent); }
.group-chevron { font-size: 14px; flex-shrink: 0; }
.group-count {
    margin-left: auto;
    background: var(--panel-border);
    border-radius: 99px;
    padding: 1px 6px;
    font-size: 12px;
}
.group-body.collapsed { display: none; }

.layer-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s;
    position: relative;
}
.layer-item:hover { background: var(--accent-dim); }
.layer-item.active { background: var(--accent-dim); }

/* Custom toggle */
.toggle-track {
    width: 32px;
    height: 17px;
    background: var(--panel-border);
    border-radius: 99px;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s;
    margin-top: 2px;
}
.layer-item.active .toggle-track {
    background: var(--accent);
}
.toggle-thumb {
    position: absolute;
    top: 2px; left: 2px;
    width: 13px; height: 13px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.layer-item.active .toggle-thumb {
    transform: translateX(15px);
}

.layer-info { flex: 1; min-width: 0; }
.layer-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.layer-id {
    font-family: 'Space Mono', monospace;
    font-size: 9px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.zoom-link {
    font-size: 11px;
    color: var(--accent);
    text-decoration: none;
    opacity: 0.7;
}
.zoom-link:hover { opacity: 1; text-decoration: underline; }

/* Active indicator dot */
.layer-item.active .layer-name { color: var(--accent); }

/* ── EMPTY / PLACEHOLDER ── */
#placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}
#placeholder svg { opacity: 0.25; }
#placeholder p {
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.08em;
    line-height: 1.8;
}

/* ── ACTIVE COUNT BADGE ── */
#active-count {
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    background: var(--accent);
    color: #0d0f14;
    border-radius: 99px;
    padding: 1px 7px;
    letter-spacing: 0.05em;
    display: none;
}

#count-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 20px 0;
    flex-shrink: 0;
}
#count-label {
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ── OPACITY SLIDER ── */
.opacity-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 8px 4px 38px;
}
.opacity-row label {
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    letter-spacing: 0.06em;
}
.opacity-row input[type=range] {
    flex: 1;
    -webkit-appearance: none;
    height: 3px;
    background: var(--panel-border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.opacity-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px; height: 10px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}
.opacity-val {
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    color: var(--accent);
    min-width: 24px;
    text-align: right;
}