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

:root {
  /* ── LIGHT THEME ── */
  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --surface2:  #e8edf3;
  --border:    #c8d5e0;
  --accent:    #1a6eb5;     /* primary blue */
  --accent-h:  #1557a0;     /* hover */
  --accent2:   #d9541e;     /* orange / danger */
  --text:      #1a2733;
  --text-soft: #3d5166;
  --muted:     #7a95a8;
  --panel-w:   340px;
  --header-h:  52px;
  --radius:    6px;
  --mono:      'Space Mono', monospace;
  --display:   'Syne', sans-serif;
  --shadow:    0 2px 8px rgba(0,0,0,.10);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.14);
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--mono); }

/* ── HEADER ── */
header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-bar {
  height: var(--header-h);
  display: flex; align-items: center; padding: 0 16px;
}
.header-bar-right {
  display: flex; align-items: center; gap: 8px; margin-left: auto;
}

.accordion-chevron {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: var(--radius);
  width: 30px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; cursor: pointer; transition: all .2s;
  flex-shrink: 0; padding: 0; line-height: 1;
  transform: rotate(90deg);
}
.accordion-chevron.open  { transform: rotate(270deg); border-color: var(--accent); color: var(--accent); }
.accordion-chevron:hover { border-color: var(--accent); color: var(--accent); }

.header-expanded {
  display: none; flex-direction: column; gap: 8px;
  padding: 8px 16px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.header-expanded.open { display: flex; }

.header-controls-row {
  display: flex; align-items: center; gap: 8px; width: 100%; flex-wrap: nowrap;
}
.header-controls-row select       { flex-shrink: 0; width: auto; min-width: 130px; }
.header-controls-row .search-wrap { flex: 1; min-width: 0; }

/* small header buttons (Save/Load inside accordion) */
.btn-hdr {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-soft); border-radius: var(--radius);
  padding: 5px 10px; font-family: var(--mono); font-size: 0.65rem;
  cursor: pointer; transition: all .2s; white-space: nowrap; flex-shrink: 0;
}
.btn-hdr:hover { border-color: var(--accent); color: var(--accent); background: rgba(26,110,181,.06); }

.search-wrap { position: relative; display: flex; align-items: center; }
.attr-search-input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 32px 6px 10px; font-family: var(--mono); font-size: 0.72rem;
  outline: none; transition: border-color .2s;
}
.attr-search-input:focus       { border-color: var(--accent); }
.attr-search-input::placeholder { color: var(--muted); }

.search-clear-btn {
  position: absolute; right: 8px;
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 0.7rem; padding: 2px; line-height: 1; display: none;
}
.search-clear-btn.visible { display: block; }
.search-clear-btn:hover   { color: var(--accent2); }

.search-results {
  display: none; flex-direction: column; gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.search-results.has-results { display: flex; }
.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.search-result-item {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 7px 10px; background: var(--surface2); border-radius: var(--radius);
  border: 1px solid var(--border); cursor: pointer; font-size: 0.68rem;
  transition: border-color .15s;
}
.search-result-item:hover { border-color: var(--accent); }
.search-result-layer { font-size: 0.6rem; white-space: nowrap; flex-shrink: 0; padding-top: 1px; }
.search-result-text  { color: var(--text); word-break: break-word; }
.search-result-text mark { background: transparent; color: var(--accent); font-weight: 700; }
.search-no-results   { font-size: 0.68rem; color: var(--muted); padding: 6px 10px; text-align: center; }

/* ── LOGO ── */
.logo {
  font-family: var(--display); font-weight: 800; font-size: 1.2rem;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), #0e9fd8);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  white-space: nowrap; flex-shrink: 0;
}
.logo span { color: var(--accent2); -webkit-text-fill-color: var(--accent2); }

/* ── FORM ELEMENTS ── */
select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 10px; font-family: var(--mono); font-size: 0.7rem;
  cursor: pointer; outline: none; width: 100%;
}
select:focus { border-color: var(--accent); }

.btn {
  background: var(--accent); border: 1px solid var(--accent);
  color: #fff; border-radius: var(--radius);
  padding: 5px 12px; font-family: var(--mono); font-size: 0.7rem;
  cursor: pointer; transition: all .2s; white-space: nowrap;
  position: relative; flex-shrink: 0;
}
.btn:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* ── LAYOUT ── */
.app {
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
  display: flex;
  /* top overridden by JS setAppTop() on load and accordion toggle */
}

#map {
  flex: 1;
  min-width: 0;
  height: 100%; /* required: parent is position:fixed, children won't auto-fill */
}

.leaflet-container { background: #dde8f0; }
.leaflet-control-zoom a {
  background: var(--surface) !important; color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface2) !important; }

/* ── PANEL WRAPPER — holds the actual panel, expand handled separately ── */
#panel-wrapper {
  position: relative;
  display: flex;
  height: 100%;
  width: var(--panel-w);
  flex-shrink: 0;
  transition: width .3s cubic-bezier(.4,0,.2,1);
}
#panel-wrapper.expanded  { width: calc(100vw - 32px); }
#panel-wrapper.collapsed { width: 0; }
#panel-wrapper.collapsed #panel { pointer-events: none; }

/* expand button: fixed to viewport right edge, always visible, never clipped */
.panel-expand-btn {
  position: fixed;
  right: var(--panel-w);        /* sits at left edge of panel */
  bottom: 50%;
  transform: translateY(50%);
  z-index: 500;
  width: 22px; height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s, right .3s cubic-bezier(.4,0,.2,1);
  box-shadow: -2px 0 6px rgba(0,0,0,.12);
  padding: 0; line-height: 1;
  writing-mode: vertical-rl;
}
.panel-expand-btn:hover { color: var(--accent); background: var(--bg); }
/* When panel is expanded, shift the button left too */
.panel-expand-btn[data-expanded="true"] {
  right: calc(100vw - 32px);
}

/* ── SIDE PANEL ── */
#panel {
  flex: 1; min-width: 0; height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: -2px 0 8px rgba(0,0,0,.07);
}

/* ── TABS ── */
.panel-tabs {
  display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: var(--bg);
}
.tab-btn {
  flex: 1; padding: 11px 6px; background: transparent; border: none;
  color: var(--muted); font-family: var(--mono); font-size: 0.62rem;
  cursor: pointer; transition: all .2s; letter-spacing: 0.04em;
  text-transform: uppercase; border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--surface); }
.tab-badge {
  display: inline-block; background: var(--accent); color: #fff;
  border-radius: 20px; padding: 1px 6px; font-size: 0.55rem;
  font-weight: 700; margin-left: 4px; vertical-align: middle;
}

.tab-pane { display: none; flex: 1; overflow-y: auto; flex-direction: column; }
.tab-pane.active { display: flex; flex-direction: column; }
.tab-pane::-webkit-scrollbar { width: 4px; }
.tab-pane::-webkit-scrollbar-track { background: transparent; }
.tab-pane::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── FEATURE INFO ── */
.panel-body { flex: 1; overflow-y: auto; padding: 20px 16px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 14px; color: var(--muted); text-align: center; padding: 40px 20px;
}
.empty-icon { font-size: 2.5rem; opacity: .35; }
.empty-state p { font-size: 0.72rem; line-height: 1.6; max-width: 220px; }

.feature-content { animation: fadeSlide .3s ease; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.desc-html { font-size: 0.82rem; line-height: 1.7; }
.desc-html h1,.desc-html h2,.desc-html h3 { font-family: var(--display); margin: 1em 0 .4em; color: var(--accent); }
.desc-html a { color: var(--accent); text-decoration: underline; }
.desc-html table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 0.75rem; }
.desc-html th,.desc-html td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.desc-html th { background: var(--surface2); color: var(--accent); }
.desc-html img { max-width: 100%; border-radius: var(--radius); margin: .5em 0; }
.desc-html code { background: var(--surface2); padding: 2px 6px; border-radius: 3px; font-family: var(--mono); font-size: 0.8em; color: var(--accent2); }
.desc-html pre  { background: var(--surface2); padding: 12px; border-radius: var(--radius); overflow-x: auto; margin: .8em 0; }

.props-grid { display: grid; gap: 6px; }
.prop-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 10px;
  background: var(--surface2); border-radius: var(--radius); border: 1px solid var(--border); font-size: 0.7rem;
}
.prop-key { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prop-val { color: var(--text); word-break: break-all; }

.no-desc {
  font-size: 0.72rem; color: var(--text-soft); margin-bottom: 12px;
  padding: 8px 12px; background: var(--surface2); border-radius: var(--radius); border: 1px solid var(--border);
}
.link-accent { color: var(--accent); }

/* ── LAYER LIST ── */
.layer-list-pane { padding: 0; overflow-y: auto; }
.layer-list-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 200px; gap: 12px; color: var(--muted); text-align: center; padding: 30px 20px; font-size: 0.72rem;
}
.layer-list-empty .empty-icon { font-size: 2rem; opacity: .35; }

.layer-item { border-bottom: 1px solid var(--border); transition: background .1s; }
.layer-item-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
}
.layer-item-header:hover { background: rgba(26,110,181,.04); }

.layer-color-swatch {
  width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0;
  cursor: pointer; border: 2px solid rgba(0,0,0,.15); transition: transform .15s;
}
.layer-color-swatch:hover { transform: scale(1.2); }

.layer-name { flex: 1; font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.icon-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); padding: 3px; border-radius: 3px;
  font-size: 0.85rem; line-height: 1; transition: all .15s;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover         { color: var(--text); background: var(--surface2); }
.icon-btn.danger:hover  { color: var(--accent2); background: rgba(217,84,30,.1); }

.vis-btn { font-size: 0.9rem; }
.vis-btn.hidden-layer   { color: var(--border); }
.expand-btn             { transition: transform .2s; }
.expand-btn.open        { transform: rotate(90deg); }
.order-btns             { display: flex; gap: 4px; }

/* ── STYLE EDITOR ── */
.style-editor {
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 14px; display: none; gap: 12px; flex-direction: column;
}
.style-editor.open { display: flex; }

.style-row        { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; align-items: center; }
.style-row-color  { display: grid; grid-template-columns: 90px 1fr; gap: 8px; align-items: center; }
.style-label      { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.style-val        { font-size: 0.65rem; color: var(--accent); min-width: 28px; text-align: right; font-family: var(--mono); }

.style-section-title {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

input[type=range] {
  -webkit-appearance: none; width: 100%; height: 4px;
  background: var(--border); border-radius: 2px; outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px;
  border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid #fff;
}

input[type=color] {
  -webkit-appearance: none; width: 32px; height: 26px;
  border: 1px solid var(--border); border-radius: 4px;
  background: transparent; cursor: pointer; padding: 2px;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch         { border: none; border-radius: 2px; }

.apply-style-btn {
  margin-top: 2px; width: 100%;
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 7px; font-family: var(--mono); font-size: 0.68rem; font-weight: 700;
  cursor: pointer; transition: all .2s; letter-spacing: 0.04em;
}
.apply-style-btn:hover { background: var(--accent-h); }

/* ── POINT ICON PICKER ── */
.icon-picker { display: flex; flex-wrap: wrap; gap: 5px; }
.icon-opt {
  width: 30px; height: 30px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface2);
  cursor: pointer; transition: all .15s; color: var(--text-soft);
}
.icon-opt:hover    { border-color: var(--accent); }
.icon-opt.selected { border-color: var(--accent); background: rgba(26,110,181,.1); box-shadow: 0 0 0 1px var(--accent); }
.icon-opt svg      { width: 16px; height: 16px; }

.label-attr-select {
  width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 8px; font-family: var(--mono); font-size: 0.68rem;
  cursor: pointer; outline: none;
}
.label-attr-select:focus { border-color: var(--accent); }

/* ── LABELS ── */
.geo-label { background: transparent; border: none; box-shadow: none; }
.geo-label-inner { font-family: 'Space Mono', monospace; white-space: nowrap; pointer-events: none; }

/* ── DROP OVERLAY ── */
#drop-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(240,244,248,.88); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; flex-direction: column; gap: 12px;
  font-family: var(--display); font-size: 1.2rem; color: var(--accent);
}
#drop-overlay.active { display: flex; }
#drop-overlay .drop-icon { font-size: 3rem; }

/* ═══════════════════════════════════════
   ATTRIBUTE TABLE
═══════════════════════════════════════ */
.attr-table-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  background: var(--bg); flex-shrink: 0; flex-wrap: wrap;
}
.attr-table-toolbar select { flex: 1; min-width: 0; font-size: 0.68rem; }

#attr-table-wrap {
  flex: 1; overflow: hidden; display: flex; flex-direction: column;
}
/* ↓ KEY: horizontal + vertical scroll */
.attr-table-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
}
.attr-table-scroll::-webkit-scrollbar        { width: 6px; height: 6px; }
.attr-table-scroll::-webkit-scrollbar-track  { background: var(--surface2); }
.attr-table-scroll::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 4px; }
.attr-table-scroll::-webkit-scrollbar-corner { background: var(--surface2); }

.attr-table {
  border-collapse: collapse; font-size: 0.65rem;
  /* don't stretch—let h-scroll take over */
  width: max-content; min-width: 100%;
}
/* column header label */
.attr-th-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-right: 4px;
}

/* delete-column button inside header */
.attr-col-del-btn {
  display: none;
  background: transparent; border: none; cursor: pointer;
  color: var(--accent2); font-size: 0.6rem; padding: 0 2px;
  line-height: 1; flex-shrink: 0;
}
.attr-th:hover .attr-col-del-btn { display: inline-block; }

/* column resize handle */
.attr-col-resizer {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 5px;
  cursor: col-resize;
  background: transparent;
  z-index: 2;
}
.attr-col-resizer:hover,
.attr-col-resizer:active {
  background: var(--accent);
  opacity: 0.5;
}

/* make th use flex so label + del btn + resizer sit side-by-side */
.attr-th {
  position: sticky; top: 0; background: var(--surface2);
  border: 1px solid var(--border); padding: 6px 18px 6px 10px;
  color: var(--accent); text-align: left; white-space: nowrap;
  font-family: var(--mono); font-weight: 700; z-index: 1;
  user-select: none;
  overflow: hidden;
}
.attr-th-idx, .attr-th-del {
  position: sticky; top: 0; background: var(--surface2);
  border: 1px solid var(--border); padding: 6px 4px;
  color: var(--muted); text-align: center; z-index: 1;
}
.attr-th-del { min-width: 28px; }

.attr-row            { transition: background .1s; cursor: pointer; }
.attr-row:hover      { background: rgba(26,110,181,.05); }
.attr-row:nth-child(even) { background: rgba(26,110,181,.02); }
.attr-row:nth-child(even):hover { background: rgba(26,110,181,.06); }

.attr-td     { border: 1px solid var(--border); padding: 0; }
.attr-td-idx { border: 1px solid var(--border); padding: 4px 8px; color: var(--muted); text-align: center; font-size: 0.6rem; white-space: nowrap; }
.attr-td-del { border: 1px solid var(--border); padding: 2px; text-align: center; }

.attr-cell-input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 0.65rem;
  padding: 5px 8px; width: 100%; min-width: 80px; transition: background .15s;
}
.attr-cell-input:focus { background: rgba(26,110,181,.07); border-radius: 2px; }

/* ── SHARED SMALL BUTTON ── */
.btn-sm {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-soft); border-radius: var(--radius);
  padding: 4px 9px; font-family: var(--mono); font-size: 0.62rem;
  cursor: pointer; transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.btn-sm:hover           { border-color: var(--accent); color: var(--accent); }
.btn-sm.btn-accent      { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm.btn-accent:hover{ background: var(--accent-h); border-color: var(--accent-h); }
.btn-sm.btn-danger      { color: var(--accent2); border-color: transparent; background: transparent; }
.btn-sm.btn-danger:hover{ border-color: var(--accent2); background: rgba(217,84,30,.08); }
.btn-sm.btn-save-file   { border-color: var(--accent); color: var(--accent); }
.btn-sm.btn-save-file:disabled { border-color: var(--border); color: var(--muted); cursor: not-allowed; }

/* ── TOAST ── */
#geo-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 18px; font-size: 0.72rem; color: var(--text); font-family: var(--mono);
  z-index: 99999; box-shadow: var(--shadow-lg);
  transition: opacity .4s; pointer-events: none;
}
#geo-toast.success { border-color: var(--accent); color: var(--accent); }
#geo-toast.error   { border-color: var(--accent2); color: var(--accent2); }
#geo-toast.warn    { border-color: #c07b00; color: #c07b00; }

/* ── MOBILE ── */
@media (max-width: 700px) {
  .app  { flex-direction: column; }
  #map  { flex: 1; min-height: 0; }
  #panel-wrapper { width: 100% !important; height: 50%; flex-shrink: 0; }
  #panel-wrapper.collapsed { height: 0 !important; }
  #panel-wrapper.expanded  { height: 80% !important; }
  #panel { border-left: none; border-top: 1px solid var(--border); height: 100%; }
  .header-bar { gap: 8px; }
  .panel-expand-btn { display: none; }
}
