/* ── Paper palette ─────────────────────────────────────── */
:root {
  --orange:  #db7100;
  --blue:    #067bc2;
  --green:   #154522;
  --lgreen:  #bfe7ba;
  --cream:   #f3eed6;

  --bg:      #f3eed6;
  --bg-surface: #faf8f2;
  --bg-hover: #f0ead8;
  --text:    #2a2a2a;
  --text-dim: #777766;
  --border:  #bdbdbd;

  --sidebar-w: 300px;
  --radius:  4px;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  gap: 14px;
}

#sidebar h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

#canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--cream);
}

#globe-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#globe-canvas:active { cursor: grabbing; }

/* ── Loading ───────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  z-index: 10;
  gap: 16px;
  transition: opacity 0.4s;
}
#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p { color: var(--text-dim); font-size: 12px; }

/* ── Panels ────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel h2 {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

/* ── Form elements ─────────────────────────────────────── */
label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
label input[type="number"],
label select {
  width: 90px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  font-size: 12px;
}
label input[type="range"] {
  flex: 1;
  accent-color: var(--orange);
}
label input[type="color"] {
  width: 32px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: none;
  cursor: pointer;
}
.checkbox-label {
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  accent-color: var(--orange);
}
.hidden { display: none !important; }

/* ── Selected list ─────────────────────────────────────── */
.selected-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  min-height: 40px;
  max-height: 320px;
  overflow-y: auto;
}
.selected-list:empty::after {
  content: 'No countries added yet';
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}
.selected-list::-webkit-scrollbar { width: 5px; }
.selected-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.selected-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  border-bottom: 1px solid #eee;
  user-select: none;
}
.selected-item:last-child { border-bottom: none; }
.selected-item:hover { background: var(--bg-hover); }
.selected-item .drag-handle {
  font-size: 10px;
  color: var(--text-dim);
  cursor: grab;
  letter-spacing: -2px;
  line-height: 1;
  padding: 0 2px;
  user-select: none;
  flex-shrink: 0;
}
.selected-item .path-node-check,
.selected-item .frame-all-check {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}
.selected-item .path-node-check input,
.selected-item .frame-all-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.selected-item .path-node-check .path-node-icon {
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.3;
  transition: color 0.15s, opacity 0.15s;
  line-height: 1;
}
.selected-item .path-node-check:hover .path-node-icon {
  opacity: 0.6;
}
.selected-item .path-node-check.active .path-node-icon {
  color: #8b0000;
  opacity: 1;
  font-weight: 700;
}
.selected-item .frame-all-check .frame-all-icon {
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.35;
  transition: color 0.15s, opacity 0.15s;
  line-height: 1;
}
.selected-item .frame-all-check:hover .frame-all-icon {
  opacity: 0.65;
}
.selected-item .frame-all-check.active .frame-all-icon {
  color: var(--blue);
  opacity: 1;
  font-weight: 700;
}
.selected-item.dragging { opacity: 0.4; }
.selected-item.drag-over {
  border-top: 2px solid var(--orange);
}
.selected-item .selected-name { flex: 1; }
.selected-item .selected-iso {
  font-size: 10px;
  color: var(--text-dim);
  font-family: monospace;
}
.selected-item .selected-order {
  font-size: 10px;
  color: var(--orange);
  font-weight: 700;
  min-width: 16px;
  text-align: right;
}
.selected-item .selected-hold {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.selected-item .selected-hold input {
  width: 28px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 1px 1px;
  font-size: 11px;
  font-family: inherit;
  text-align: right;
  -moz-appearance: textfield;
  appearance: textfield;
}
.selected-item .selected-hold input::-webkit-inner-spin-button,
.selected-item .selected-hold input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.selected-item .selected-hold input:hover {
  border-color: var(--border);
  background: #fff;
}
.selected-item .selected-hold input:focus {
  border-color: var(--orange);
  background: #fff;
  outline: none;
}
.selected-item .selected-hold input.is-default {
  color: var(--text-dim);
}
.selected-item .selected-hold .hold-steppers {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 0;
  margin-left: -2px;
}
.selected-item .selected-hold .hold-steppers button {
  background: none;
  border: none;
  padding: 2px 3px;
  margin: 0;
  cursor: pointer;
  font-size: 8px;
  line-height: 1;
  color: var(--text-dim);
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.selected-item .selected-hold .hold-steppers button:hover {
  color: var(--orange);
}
.selected-item .selected-hold .hold-unit {
  font-size: 10px;
  color: var(--text-dim);
  pointer-events: none;
  margin-left: 1px;
}
.selected-item .btn-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.selected-item:hover .btn-remove { opacity: 1; }
.selected-item .btn-remove:hover { color: #c0392b; }

/* ── Sequences panel ───────────────────────────────────── */
.sequences-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sequences-controls select {
  width: 100%;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 12px;
  outline: none;
}
.sequences-controls select:focus {
  border-color: var(--orange);
}
.sequences-controls input {
  width: 100%;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 12px;
  outline: none;
}
.sequences-controls input:focus {
  border-color: var(--orange);
}
.sequences-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.sequence-btn {
  flex: 1 1 calc(50% - 4px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sequence-btn:nth-child(n + 3) {
  flex-basis: calc(33.333% - 4px);
}
.sequence-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--orange);
  color: var(--orange);
}
.sequence-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.sequence-icon {
  position: relative;
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  color: currentColor;
}
.seq-save .sequence-icon {
  border: 1px solid currentColor;
  border-radius: 1px;
}
.seq-save .sequence-icon::before {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  top: 2px;
  height: 3px;
  background: currentColor;
}
.seq-save .sequence-icon::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 1px;
  height: 4px;
  border: 1px solid currentColor;
  border-bottom: 0;
}
.seq-load .sequence-icon {
  border: 1px solid currentColor;
  border-top-width: 4px;
  border-radius: 1px;
}
.seq-load .sequence-icon::before {
  content: '';
  position: absolute;
  left: -1px;
  top: -5px;
  width: 6px;
  height: 3px;
  border: 1px solid currentColor;
  border-bottom: 0;
  border-radius: 1px 1px 0 0;
}
.seq-update .sequence-icon {
  border: 1px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}
.seq-update .sequence-icon::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 1px;
  width: 4px;
  height: 4px;
  border-top: 1px solid currentColor;
  border-right: 1px solid currentColor;
  transform: rotate(45deg);
}
.seq-rename .sequence-icon::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 6px;
  width: 9px;
  height: 3px;
  border: 1px solid currentColor;
  border-radius: 1px;
  transform: rotate(-35deg);
  transform-origin: center;
}
.seq-rename .sequence-icon::after {
  content: '';
  position: absolute;
  left: 1px;
  bottom: 1px;
  width: 10px;
  border-bottom: 1px solid currentColor;
}
.seq-delete .sequence-icon {
  border: 1px solid currentColor;
  border-top: 0;
  border-radius: 0 0 1px 1px;
  height: 9px;
  margin-top: 2px;
}
.seq-delete .sequence-icon::before {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  top: -3px;
  border-top: 1px solid currentColor;
}
.seq-delete .sequence-icon::after {
  content: '';
  position: absolute;
  left: 3px;
  right: 3px;
  top: -5px;
  border-top: 1px solid currentColor;
}
.sequence-status {
  min-height: 13px;
  font-size: 10px;
  color: var(--text-dim);
}
.sequence-status:empty {
  display: none;
}

/* ── Add country button ────────────────────────────────── */
.add-country-btn {
  width: 100%;
  padding: 6px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.add-country-btn:hover {
  border-color: var(--orange);
  color: var(--orange);
}

/* ── Country picker modal ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none !important; }

.modal {
  background: var(--bg-surface);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  width: 340px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0;
  text-transform: none;
  border: none;
  padding: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

#modal-search {
  margin: 10px 16px 6px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
}
#modal-search:focus { border-color: var(--orange); }

.custom-coordinate-panel {
  display: grid;
  grid-template-columns: 1fr 64px 64px;
  gap: 6px;
  padding: 0 16px 10px;
  border-bottom: 1px solid var(--border);
}
.custom-coordinate-panel input {
  min-width: 0;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px;
  font-size: 11px;
  outline: none;
}
.custom-coordinate-panel input:focus {
  border-color: var(--orange);
}
.custom-coordinate-panel button {
  grid-column: 1 / -1;
  padding: 5px 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.custom-coordinate-panel button:hover {
  border-color: var(--orange);
  color: var(--orange);
}

.modal-country-list {
  overflow-y: auto;
  padding: 0 8px 10px;
  flex: 1;
}
.modal-country-list::-webkit-scrollbar { width: 5px; }
.modal-country-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.modal-country-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius);
  user-select: none;
}
.modal-country-item:hover { background: var(--bg-hover); }
.modal-country-item .country-name { flex: 1; }
.modal-country-item .country-iso {
  font-size: 10px;
  color: var(--text-dim);
  font-family: monospace;
}
.modal-country-item.disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ── Buttons ───────────────────────────────────────────── */
button {
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-buttons {
  display: flex;
  gap: 6px;
}
.action-buttons button {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-weight: 600;
}
.action-buttons button:hover:not(:disabled) { background: var(--bg-hover); }
.action-buttons button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.action-buttons button.primary:hover:not(:disabled) { background: #0890e0; }
.action-buttons button.accent {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}
.action-buttons button.accent:hover:not(:disabled) { background: #f08520; }

button.danger {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius);
  width: 100%;
}
button.danger:hover { background: #e74c3c; }

/* ── Progress ──────────────────────────────────────────── */
#progress-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#progress-bar {
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--orange);
  border-radius: 4px;
  transition: width 0.15s;
}
#progress-label {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

.info-text {
  font-size: 11px;
  color: var(--text-dim);
  min-height: 16px;
}
