:root {
  color-scheme: dark;
  /* Modern Dark Theme Palette (Default) */
  --bg-app: #1e1e1e;
  --bg-panel: #252526;
  --bg-input: #3c3c3c;
  --bg-hover: #2a2d2e;
  
  --text-main: #cccccc;
  --text-muted: #858585;
  --text-bright: #ffffff;
  
  --border: #3e3e42;
  --border-focus: #007fd4;
  
  --primary: #007fd4;
  --primary-hover: #0069b4;
  --primary-text: #ffffff;
  
  --text-primary: #ffffff; /* Added for compatibility */

  --danger: #f48771;
  --success: #89d185;
  
  --gap: 12px;
  --radius: 6px;
  
  --font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
}

/* Light Theme Palette */
body.light-theme {
  color-scheme: light;
  --bg-app: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #e5e7eb;
  
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --text-bright: #111827;
  
  --border: #d1d5db;
  --border-focus: #2563eb;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;
  
  --text-primary: #111827; /* Added for compatibility */

  --danger: #dc2626;
  --success: #16a34a;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-family);
  margin: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  box-sizing: border-box;
  overflow: hidden;
}

footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* Theme Toggle Button */
.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background-color 0.2s;
  z-index: 100;
}
.theme-toggle:hover {
  background-color: var(--bg-hover);
  color: var(--text-bright);
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Additional Columns Grid */
.cols-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.col-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-panel);
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.col-row input {
  flex: 1;
  min-width: 0; /* Prevent overflow */
}

.col-row .remove {
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

h1, h2, h3 {
  color: var(--text-bright);
  font-weight: 600;
  margin-top: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Inputs & Controls */
input[type="text"], 
input[type="search"], 
input[type="datetime-local"], 
textarea, 
select {
  background-color: var(--bg-input);
  color: var(--text-bright);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, 
textarea:focus, 
select:focus {
  border-color: var(--border-focus);
}

select option {
  background-color: var(--bg-input);
  color: var(--text-bright);
}

label {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 4px;
  display: block;
}

/* Buttons */
button {
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.2s;
}

button:hover {
  background-color: var(--bg-hover);
}

button.primary {
  background-color: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

button.primary:hover {
  background-color: var(--primary-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: #424242;
  border-radius: 5px;
  border: 2px solid var(--bg-app);
}
::-webkit-scrollbar-thumb:hover {
  background: #4f4f4f;
}

/* Common Layout Utilities */
.row {
  display: flex;
  gap: var(--gap);
}
.col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Dropdowns (Custom) */
.dropdown-content {
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  color: var(--text-main);
}
.dropdown-content ul li:hover {
  background-color: var(--bg-hover);
}

/* Tabulator Dark Theme Overrides */
.tabulator {
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
}
.tabulator .tabulator-header {
  background-color: var(--bg-app);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.tabulator .tabulator-header .tabulator-col {
  background-color: var(--bg-app);
  border-right: 1px solid var(--border);
}
.tabulator .tabulator-row {
  background-color: var(--bg-panel);
  color: var(--text-main);
  border-bottom: 1px solid var(--border);
}
.tabulator .tabulator-row.tabulator-row-even {
  background-color: var(--bg-panel);
}
.tabulator .tabulator-row:hover {
  background-color: var(--bg-hover);
}
.tabulator .tabulator-cell {
  border-right: 1px solid var(--border);
}
.tabulator-row .tabulator-cell.cell-selected {
    outline: 2px solid var(--border-focus) !important;
    background-color: rgba(0, 127, 212, 0.1) !important;
    outline-offset: -2px;
}

/* Modal */
.modal-overlay {
  background: rgba(0,0,0,0.6);
}
.modal-content {
  background: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

/* Tabulator List Editor (Dropdown) Dark Theme */
.tabulator-edit-select-list {
  background-color: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

.tabulator-edit-select-list .tabulator-edit-select-list-item {
  color: var(--text-main) !important;
  background-color: var(--bg-panel) !important;
}

.tabulator-edit-select-list .tabulator-edit-select-list-item.active,
.tabulator-edit-select-list .tabulator-edit-select-list-item:hover {
  background-color: var(--bg-hover) !important;
  color: var(--text-bright) !important;
}

.tabulator-edit-select-list .tabulator-edit-select-list-notice {
  color: var(--text-muted) !important;
  background-color: var(--bg-panel) !important;
}

.tabulator-edit-select-list .tabulator-edit-select-list-group {
  color: var(--text-bright) !important;
  background-color: var(--bg-app) !important;
  border-bottom: 1px solid var(--border) !important;
}

.tabulator-edit-select-list::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.tabulator-edit-select-list::-webkit-scrollbar-track {
  background: var(--bg-panel);
}
.tabulator-edit-select-list::-webkit-scrollbar-thumb {
  background: #424242;
  border-radius: 5px;
  border: 2px solid var(--bg-panel);
}
.tabulator-edit-select-list::-webkit-scrollbar-thumb:hover {
  background: #4f4f4f;
}

/* Tabulator v6 List Editor Dark Theme */
.tabulator-edit-list {
    background-color: var(--bg-panel) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

.tabulator-edit-list .tabulator-edit-list-item {
    color: var(--text-main) !important;
    background-color: var(--bg-panel) !important;
}

.tabulator-edit-list .tabulator-edit-list-item.active,
.tabulator-edit-list .tabulator-edit-list-item:hover {
    background-color: var(--bg-hover) !important;
    color: var(--text-bright) !important;
}

.tabulator-edit-list .tabulator-edit-list-group {
    color: var(--text-bright) !important;
    background-color: var(--bg-app) !important;
    border-bottom: 1px solid var(--border) !important;
}

.tabulator-edit-list .tabulator-edit-list-placeholder {
    color: var(--text-muted) !important;
}

.tabulator-edit-list input {
    background-color: var(--bg-input) !important;
    color: var(--text-bright) !important;
    border: 1px solid var(--border) !important;
}

/* Tabulator Menu (Context Menu) Dark Theme */
.tabulator-menu {
  background-color: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

.tabulator-menu .tabulator-menu-item {
  background-color: var(--bg-panel) !important;
  color: var(--text-main) !important;
}

.tabulator-menu .tabulator-menu-item:not(.tabulator-menu-item-disabled):hover {
  background-color: var(--bg-hover) !important;
  color: var(--text-bright) !important;
}

.tabulator-menu .tabulator-menu-separator {
  border-bottom: 1px solid var(--border) !important;
}

/* Custom Dropdown Styles */
.sidc-dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  z-index: 2500; /* Higher than modal (2000) */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  border-radius: var(--radius);
  margin-top: 4px;
  display: none; /* Hidden by default */
}

.sidc-dropdown-list.visible {
  display: block;
}

.sidc-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background-color 0.2s;
}

.sidc-dropdown-item:hover, .sidc-dropdown-item.selected {
  background-color: var(--bg-hover);
  color: var(--text-bright);
}

/* Scrollbar for dropdown */
.sidc-dropdown-list::-webkit-scrollbar {
  width: 8px;
}

.sidc-dropdown-list::-webkit-scrollbar-track {
  background: var(--bg-panel);
}

.sidc-dropdown-list::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 4px;
}

.sidc-dropdown-list::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}

/* Clear Button Styles */
.input-with-clear {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-with-clear input {
  padding-right: 32px !important;
}

.clear-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  width: 24px;
  height: 24px;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: color 0.2s;
}

.clear-btn.visible {
  display: flex;
}

.clear-btn:hover {
  color: var(--text-bright);
}


#coord-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

/* Admin Button Custom Styles */
#open-admin-btn {
    color: var(--primary);
    background-color: rgba(0, 127, 212, 0.1);
    transition: all 0.3s ease;
    border: 1px solid rgba(0, 127, 212, 0.3);
}

#open-admin-btn:hover {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 0 15px rgba(0, 127, 212, 0.5);
    transform: scale(1.1);
    border-color: var(--primary);
}

#open-admin-btn svg {
    width: 26px;
    height: 26px;
}

