/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #21253a;
  --border:     #2e3250;
  --accent:     #4f80ff;
  --accent2:    #7c5cfc;
  --danger:     #e63946;
  --success:    #2a9d8f;
  --warn:       #e9c46a;
  --text:       #e8eaf2;
  --text2:      #8b93b5;
  --text3:      #555e82;
  --sidebar-w:  340px;
  --header-h:   56px;
  --radius:     10px;
  --shadow:     0 8px 32px rgba(0,0,0,.45);
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 800;
  flex-shrink: 0;
}

.header-logo {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.header-sep { flex: 1; }

.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.header-btn:hover { border-color: var(--accent); color: var(--accent); }
.header-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.header-btn .icon { font-size: 0.9rem; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
}
.toggle-label input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }

/* ── Layout ──────────────────────────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Sidebar ─────────────────────────────────────────── */
.left-sidebar {
  width: 230px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 6px 4px 8px;
}

#searchInput {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
}
#searchInput:focus { border-color: var(--accent); }

#locationList { overflow-y: auto; flex: 1; padding: 6px; }

.loc-list-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.loc-list-item:hover { background: var(--surface2); }
.loc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.loc-list-info { min-width: 0; }
.loc-list-info strong { font-size: 0.82rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-list-info small { font-size: 0.72rem; color: var(--text2); }

/* ── Map ─────────────────────────────────────────────────── */
#map {
  flex: 1;
  z-index: 1;
}

/* ── Right Side Panel ─────────────────────────────────────── */
#sidePanel {
  width: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .25s ease;
  flex-shrink: 0;
}
#sidePanel.open { width: var(--sidebar-w); }

.panel-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
}
.panel-title-group h2 { font-size: 1rem; font-weight: 600; }
.panel-title-group p  { font-size: 0.75rem; color: var(--text2); margin-top: 2px; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .12s;
}
.btn-ghost:hover { color: var(--text); }

.panel-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-sm {
  flex: 1;
  padding: 7px 8px;
  font-size: 0.78rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: all .12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.btn-sm:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-sm:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm.primary:hover { opacity: .9; }

.panel-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

/* ── Folder Tree ──────────────────────────────────────────── */
.folder-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 0;
}
.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 8px 14px 4px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  cursor: pointer;
  border-radius: 6px;
  margin: 0 6px;
  transition: background .1s;
  font-size: 0.82rem;
}
.folder-item:hover { background: var(--surface2); }
.folder-item.active { background: rgba(79,128,255,.15); }
.folder-icon { font-size: 0.95rem; }
.folder-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-count { font-size: 0.7rem; color: var(--text3); background: var(--surface2); padding: 1px 5px; border-radius: 10px; }
.folder-menu-btn { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 1rem; padding: 0 4px; border-radius: 4px; }
.folder-menu-btn:hover { color: var(--text); background: var(--border); }

/* ── File List ────────────────────────────────────────────── */
.file-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.file-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#filePanelTitle { font-size: 0.82rem; font-weight: 600; color: var(--text2); }

#fileList { overflow-y: auto; padding: 4px 0; flex: 1; }

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(46,50,80,.5);
  transition: background .1s;
}
.file-item:hover { background: var(--surface2); }
.file-icon { font-size: 1.3rem; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 0.7rem; color: var(--text2); margin-top: 2px; }
.file-actions { display: flex; gap: 4px; flex-shrink: 0; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 1rem;
  padding: 3px 5px;
  border-radius: 5px;
  text-decoration: none;
  transition: color .1s, background .1s;
}
.btn-icon:hover { color: var(--text); background: var(--border); }
.btn-icon.danger:hover { color: var(--danger); }

/* ── Distance Table (bottom of left sidebar) ──────────────── */
.dist-section {
  border-top: 1px solid var(--border);
  max-height: 160px;
  overflow-y: auto;
  flex-shrink: 0;
}
.dist-table { width: 100%; font-size: 0.72rem; border-collapse: collapse; }
.dist-table th { color: var(--text3); font-weight: 600; padding: 5px 8px; text-align: left; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.dist-table td { padding: 5px 8px; border-bottom: 1px solid rgba(46,50,80,.4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80px; }
.dist-table tr:hover td { background: var(--surface2); }

/* ── Context Menu ─────────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  overflow: hidden;
  animation: ctxIn .1s ease;
}
@keyframes ctxIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

.ctx-header {
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  font-size: 0.83rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-item.danger { color: var(--danger); }
.ctx-item .icon { font-size: 0.9rem; }
.ctx-divider { height: 1px; background: var(--border); margin: 3px 0; }
.ctx-menu-small { min-width: 170px; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.78rem; font-weight: 600; color: var(--text2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row3 { display: grid; grid-template-columns: 1fr 1fr 80px; gap: 10px; }

input[type=text], input[type=number], textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
input[type=text]:focus, input[type=number]:focus, textarea:focus {
  border-color: var(--accent);
}
input[type=color] {
  padding: 2px 4px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface2);
  border: 1px solid var(--border);
}
textarea { resize: vertical; min-height: 70px; }

.btn-primary {
  padding: 8px 20px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }

.btn-cancel {
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-cancel:hover { border-color: var(--text2); }

/* Upload specific */
.upload-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-drop-zone:hover { border-color: var(--accent); background: rgba(79,128,255,.05); }
.upload-drop-zone input { display: none; }
.upload-drop-zone p { font-size: 0.85rem; color: var(--text2); margin-top: 6px; }

#uploadFileList { list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 120px; overflow-y: auto; }
#uploadFileList li { font-size: 0.8rem; color: var(--text2); display: flex; gap: 6px; align-items: center; }

.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 100px;
  height: 6px;
  overflow: hidden;
}
#uploadBar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width .3s;
  border-radius: 100px;
}

/* Distances modal table */
.dist-modal-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.dist-modal-table th { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text2); }
.dist-modal-table td { padding: 8px 10px; border-bottom: 1px solid rgba(46,50,80,.4); }
.dist-modal-table tr:hover td { background: var(--surface2); }

/* Empty hint */
.empty-hint {
  padding: 18px 14px;
  font-size: 0.8rem;
  color: var(--text3);
  text-align: center;
  line-height: 1.5;
}

/* ── Leaflet overrides ────────────────────────────────────── */
.leaflet-container { background: #0f1117; }
.leaflet-tile { filter: brightness(0.75) saturate(0.6); }

.leaflet-tooltip {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
  font-size: 0.78rem !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-tooltip-top::before { border-top-color: var(--border) !important; }

.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; }

/* ── Scrollbars ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
